new mafft v 6.857 with extensions
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Tue, 21 Jun 2011 10:02:51 +0000 (10:02 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Tue, 21 Jun 2011 10:02:51 +0000 (10:02 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4286 e3abac25-378b-4346-85de-24260fe3988d

158 files changed:
binaries/src/mafft/core/DNA.h [new file with mode: 0644]
binaries/src/mafft/core/Falign.c [new file with mode: 0644]
binaries/src/mafft/core/Falign_localhom.c [new file with mode: 0644]
binaries/src/mafft/core/Galign11.c [new file with mode: 0644]
binaries/src/mafft/core/Halignmm.c [new file with mode: 0644]
binaries/src/mafft/core/JTT.c [new file with mode: 0644]
binaries/src/mafft/core/Lalign11.c [new file with mode: 0644]
binaries/src/mafft/core/Lalign11.c.fast [new file with mode: 0644]
binaries/src/mafft/core/Lalign11.c_nostatic [new file with mode: 0644]
binaries/src/mafft/core/Lalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/MSalign11.c [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.algAa [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.algLargeA [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.alga [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.algsmalla [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.back [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.bkbk [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.bug [new file with mode: 0644]
binaries/src/mafft/core/MSalignmm.c.work [new file with mode: 0644]
binaries/src/mafft/core/Makefile [new file with mode: 0644]
binaries/src/mafft/core/Qalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/Ralignmm.c [new file with mode: 0644]
binaries/src/mafft/core/SAalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/Salignmm.c [new file with mode: 0644]
binaries/src/mafft/core/addfunctions.c [new file with mode: 0644]
binaries/src/mafft/core/blosum.c [new file with mode: 0644]
binaries/src/mafft/core/blosum.h [new file with mode: 0644]
binaries/src/mafft/core/constants.c [new file with mode: 0644]
binaries/src/mafft/core/contrafoldwrap.c [new file with mode: 0644]
binaries/src/mafft/core/countlen.c [new file with mode: 0644]
binaries/src/mafft/core/defs.c [new file with mode: 0644]
binaries/src/mafft/core/disttbfast.c [new file with mode: 0644]
binaries/src/mafft/core/dndblast.c [new file with mode: 0644]
binaries/src/mafft/core/dndfast4.c [new file with mode: 0644]
binaries/src/mafft/core/dndfast7.c [new file with mode: 0644]
binaries/src/mafft/core/dndpre.c [new file with mode: 0644]
binaries/src/mafft/core/dndpre2.c [new file with mode: 0644]
binaries/src/mafft/core/dndpre_score.c [new file with mode: 0644]
binaries/src/mafft/core/dp.h [new file with mode: 0644]
binaries/src/mafft/core/dvtditr.c [new file with mode: 0644]
binaries/src/mafft/core/f2cl.c [new file with mode: 0644]
binaries/src/mafft/core/fft.c [new file with mode: 0644]
binaries/src/mafft/core/fft.h [new file with mode: 0644]
binaries/src/mafft/core/fftFunctions.c [new file with mode: 0644]
binaries/src/mafft/core/functions.h [new file with mode: 0644]
binaries/src/mafft/core/genGalign11.c [new file with mode: 0644]
binaries/src/mafft/core/genalign11.c [new file with mode: 0644]
binaries/src/mafft/core/getlag.c [new file with mode: 0644]
binaries/src/mafft/core/io.c [new file with mode: 0644]
binaries/src/mafft/core/iteration.c [new file with mode: 0644]
binaries/src/mafft/core/mafft-distance.c [new file with mode: 0644]
binaries/src/mafft/core/mafft-homologs.1 [new file with mode: 0644]
binaries/src/mafft/core/mafft-homologs.tmpl [new file with mode: 0644]
binaries/src/mafft/core/mafft-profile.c [new file with mode: 0644]
binaries/src/mafft/core/mafft.1 [new file with mode: 0644]
binaries/src/mafft/core/mafft.bat [new file with mode: 0644]
binaries/src/mafft/core/mafft.tmpl [new file with mode: 0644]
binaries/src/mafft/core/mafft.tmpl.subopt [new file with mode: 0644]
binaries/src/mafft/core/mccaskillwrap.c [new file with mode: 0644]
binaries/src/mafft/core/mingw64mingw32 [new file with mode: 0644]
binaries/src/mafft/core/miyata.h [new file with mode: 0644]
binaries/src/mafft/core/miyata5.h [new file with mode: 0644]
binaries/src/mafft/core/mltaln.h [new file with mode: 0644]
binaries/src/mafft/core/mltaln9.c [new file with mode: 0644]
binaries/src/mafft/core/mtxutl.c [new file with mode: 0644]
binaries/src/mafft/core/mtxutl.h [new file with mode: 0644]
binaries/src/mafft/core/multi2hat3s.c [new file with mode: 0644]
binaries/src/mafft/core/newick2mafft.rb [new file with mode: 0644]
binaries/src/mafft/core/nj.c [new file with mode: 0644]
binaries/src/mafft/core/pair2hat3s.c [new file with mode: 0644]
binaries/src/mafft/core/pairash.c [new file with mode: 0644]
binaries/src/mafft/core/pairlara.c [new file with mode: 0644]
binaries/src/mafft/core/pairlocalalign.c [new file with mode: 0644]
binaries/src/mafft/core/partQalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/partSalignmm.c [new file with mode: 0644]
binaries/src/mafft/core/regtable2seq.c [new file with mode: 0644]
binaries/src/mafft/core/replaceu.c [new file with mode: 0644]
binaries/src/mafft/core/restoreu.c [new file with mode: 0644]
binaries/src/mafft/core/rna.c [new file with mode: 0644]
binaries/src/mafft/core/rnatest.c [new file with mode: 0644]
binaries/src/mafft/core/score.c [new file with mode: 0644]
binaries/src/mafft/core/seq2regtable.c [new file with mode: 0644]
binaries/src/mafft/core/setcore.c [new file with mode: 0644]
binaries/src/mafft/core/sextet5.c [new file with mode: 0644]
binaries/src/mafft/core/share.h [new file with mode: 0644]
binaries/src/mafft/core/splittbfast.c [new file with mode: 0644]
binaries/src/mafft/core/suboptalign11.c [new file with mode: 0644]
binaries/src/mafft/core/tbfast.c [new file with mode: 0644]
binaries/src/mafft/core/tddis.c [new file with mode: 0644]
binaries/src/mafft/core/tditeration.c [new file with mode: 0644]
binaries/src/mafft/core/test.c [new file with mode: 0644]
binaries/src/mafft/core/treeOperation.c [new file with mode: 0644]
binaries/src/mafft/core/univscript.tmpl [new file with mode: 0644]
binaries/src/mafft/extensions/Makefile [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/BPPMatrix.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Beta.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/GlobalParameters.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Globaldp.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Globaldp.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Main.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Makefile [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/McCaskill.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/McCaskill.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/README [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/ScoreType.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/StemCandidate.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/Util.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/config.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/nrutil.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/params-weird [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/postProcessings.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/CompareToRef.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h_backup [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EMtrainingALL.txt [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EvolutionaryTree.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FileBuffer.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FixRef.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Main.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MakeGnuPlot.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Makefile [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MultiSequence.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProbabilisticModel.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProjectPairwise.cc [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/README [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SafeVector.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ScoreType.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Sequence.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SparseMatrix.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/mlparams0 [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/probconsRNA/train-script [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/scarna.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/seq2scs.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/COPYING [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/energy_const.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/energy_par.h [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.cpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.hpp [new file with mode: 0644]
binaries/src/mafft/extensions/mxscarna_src/vienna/params.h [new file with mode: 0644]
binaries/src/mafft/extensions/univscript.tmpl [new file with mode: 0644]
binaries/src/mafft/license [new file with mode: 0644]
binaries/src/mafft/license.extensions [new file with mode: 0644]
binaries/src/mafft/readme [new file with mode: 0644]
binaries/src/mafft/test/sample [new file with mode: 0644]
binaries/src/mafft/test/sample.dpparttree [new file with mode: 0644]
binaries/src/mafft/test/sample.fftns2 [new file with mode: 0644]
binaries/src/mafft/test/sample.fftnsi [new file with mode: 0644]
binaries/src/mafft/test/sample.gins1 [new file with mode: 0644]
binaries/src/mafft/test/sample.ginsi [new file with mode: 0644]
binaries/src/mafft/test/sample.lins1 [new file with mode: 0644]
binaries/src/mafft/test/sample.linsi [new file with mode: 0644]
binaries/src/mafft/test/sample.parttree [new file with mode: 0644]
binaries/src/mafft/test/samplerna [new file with mode: 0644]
binaries/src/mafft/test/samplerna.qinsi [new file with mode: 0644]
binaries/src/mafft/test/samplerna.xinsi [new file with mode: 0644]

diff --git a/binaries/src/mafft/core/DNA.h b/binaries/src/mafft/core/DNA.h
new file mode 100644 (file)
index 0000000..5f05fa1
--- /dev/null
@@ -0,0 +1,210 @@
+#define DEFAULTGOP_N -1530
+#define DEFAULTGEP_N  0
+#define DEFAULTOFS_N -123 
+#define DEFAULTPAMN  200
+
+#define DEFAULTRNAGOP_N -1530
+#define DEFAULTRNAGEP_N 0
+#define DEFAULTRNATHR_N 0
+
+//  -h 0.11150 -> all positive
+
+double ribosum4[4][4] = 
+{
+//   a       g       c       t     
+{    2.22,  -1.46,  -1.86,  -1.39, }, // a
+{   -1.46,   1.03,  -2.48,  -1.74, }, // g
+{   -1.86,  -2.48,   1.16,  -1.05, }, // c
+{   -1.39,  -1.74,  -1.05,   1.65, }, // t
+};
+
+double ribosum16[16][16] = 
+{
+//   aa      ag      ac      at      ga      gg      gc      gt      ca      cg      cc      ct      ta      tg      tc      tt    
+{   -2.49,  -8.24,  -7.04,  -4.32,  -6.86,  -8.39,  -5.03,  -5.84,  -8.84,  -4.68, -14.37, -12.64,  -4.01,  -6.16, -11.32,  -9.05, }, // aa
+{   -8.24,  -0.80,  -8.89,  -5.13,  -8.61,  -5.38,  -5.77,  -6.60, -10.41,  -4.57, -14.53, -10.14,  -5.43,  -5.94,  -8.87, -11.07, }, // ag
+{   -7.04,  -8.89,  -2.11,  -2.04,  -9.73, -11.05,  -3.81,  -4.72,  -9.37,  -5.86,  -9.08, -10.45,  -5.33,  -6.93,  -8.67,  -7.83, }, // ac
+{   -4.32,  -5.13,  -2.04,   4.49,  -5.33,  -5.61,   2.70,   0.59,  -5.56,   1.67,  -6.71,  -5.17,   1.61,  -0.51,  -4.81,  -2.98, }, // at
+{   -6.86,  -8.61,  -9.73,  -5.33,  -1.05,  -8.67,  -4.88,  -6.10,  -7.98,  -6.00, -12.43,  -7.71,  -5.85,  -7.55,  -6.63, -11.54, }, // ga
+{   -8.39,  -5.38, -11.05,  -5.61,  -8.67,  -1.98,  -4.13,  -5.77, -11.36,  -4.66, -12.58, -13.69,  -5.75,  -4.27, -12.01, -10.79, }, // gg
+{   -5.03,  -5.77,  -3.81,   2.70,  -4.88,  -4.13,   5.62,   1.21,  -5.95,   2.11,  -3.70,  -5.84,   1.60,  -0.08,  -4.49,  -3.90, }, // gc
+{   -5.84,  -6.60,  -4.72,   0.59,  -6.10,  -5.77,   1.21,   3.47,  -7.93,  -0.27,  -7.88,  -5.61,  -0.57,  -2.09,  -5.30,  -4.45, }, // gt
+{   -8.84, -10.41,  -9.37,  -5.56,  -7.98, -11.36,  -5.95,  -7.93,  -5.13,  -3.57, -10.45,  -8.49,  -2.42,  -5.63,  -7.08,  -8.39, }, // ca
+{   -4.68,  -4.57,  -5.86,   1.67,  -6.00,  -4.66,   2.11,  -0.27,  -3.57,   5.36,  -5.71,  -4.96,   2.75,   1.32,  -4.91,  -3.67, }, // cg
+{  -14.37, -14.53,  -9.08,  -6.71, -12.43, -12.58,  -3.70,  -7.88, -10.45,  -5.71,  -3.59,  -5.77,  -6.88,  -8.41,  -7.40,  -5.41, }, // cc
+{  -12.64, -10.14, -10.45,  -5.17,  -7.71, -13.69,  -5.84,  -5.61,  -8.49,  -4.96,  -5.77,  -2.28,  -4.72,  -7.36,  -3.83,  -5.21, }, // ct
+{   -4.01,  -5.43,  -5.33,   1.61,  -5.85,  -5.75,   1.60,  -0.57,  -2.42,   2.75,  -6.88,  -4.72,   4.97,   1.14,  -2.98,  -3.39, }, // ta
+{   -6.16,  -5.94,  -6.93,  -0.51,  -7.55,  -4.27,  -0.08,  -2.09,  -5.63,   1.32,  -8.41,  -7.36,   1.14,   3.36,  -4.76,  -4.28, }, // tg
+{  -11.32,  -8.87,  -8.67,  -4.81,  -6.63, -12.01,  -4.49,  -5.30,  -7.08,  -4.91,  -7.40,  -3.83,  -2.98,  -4.76,  -3.21,  -5.97, }, // tc
+{   -9.05, -11.07,  -7.83,  -2.98, -11.54, -10.79,  -3.90,  -4.45,  -8.39,  -3.67,  -5.41,  -5.21,  -3.39,  -4.28,  -5.97,  -0.02, }, // tt
+};
+
+int locpenaltyn = -1750;
+char locaminon[] = "agctuAGCTUnNbdhkmnrsvwyx-O";
+char locgrpn[] = 
+{
+       0, 1, 2, 3, 3, 0, 1, 2, 3, 3,
+       4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 
+       5, 5, 5, 5, 5, 5 
+};
+int exgpn = +00;
+int locn_disn[26][26] = 
+/* u ha constants.c no nakade shori */
+/* 0 - 4 dake yomareru.             */
+        {
+               {
+  1000,   600,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+   600,  1000,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,  1000,   600,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,   600,  1000,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,   500,   500,     0,     0,     0,   500,   500,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
+     0,     0,     0,     0,     0,  -500,
+               },
+
+               {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0, -500,
+               },
+
+               {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0, -500,
+               },
+
+               {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0, -500,
+               },
+
+               {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0, -500,
+               },
+
+               {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,
+               },
+
+               {
+ -500, -500, -500, -500, -500, -500, -500, -500, -500, -500,
+ -500, -500, -500, -500, -500, -500, -500, -500, -500, -500,
+ -500, -500, -500, -500,    0,  500,
+               },
+     };
diff --git a/binaries/src/mafft/core/Falign.c b/binaries/src/mafft/core/Falign.c
new file mode 100644 (file)
index 0000000..250a0fa
--- /dev/null
@@ -0,0 +1,2375 @@
+#include "mltaln.h"
+
+#if 0
+static FILE *fftfp;
+#endif
+static TLS int n20or4or2;
+
+#define KEIKA 0
+#define RND   0
+#define DEBUG 0
+
+#if RND // by D.Mathog
+static void generateRndSeq( char *seq, int len )
+{
+       while( len-- )
+#if 1
+               *seq++ = (int)( rnd() * n20or4or2 );
+#else
+               *seq++ = (int)1;
+#endif
+}
+#endif
+
+static void vec_init( Fukusosuu *result, int nlen )
+{
+       while( nlen-- )
+       {
+               result->R = result->I = 0.0;
+               result++;
+       }
+}
+
+#if 0 // by D.Mathog
+static void vec_init2( Fukusosuu **result, char *seq, double eff, int st, int ed )
+{
+       int i;
+       for( i=st; i<ed; i++ )
+               result[(int)*seq++][i].R += eff;
+}
+#endif
+
+static void seq_vec_2( Fukusosuu *result, double *score, double incr, char *seq )
+{
+       static TLS int n;
+       for( ; *seq; result++ )
+       {
+               n = amino_n[(int)*seq++];
+               if( n < 20 && n >= 0 ) result->R += incr * score[n];
+#if 0
+               fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n,  score[n], incr * score[n], result->R );
+#endif
+       }
+}
+
+static void seq_vec_3( Fukusosuu **result, double incr, char *seq )
+{
+       int i;
+       int n;
+       for( i=0; *seq; i++ )
+       {
+               n = amino_n[(int)*seq++];
+               if( n < n20or4or2 && n >= 0 ) result[n][i].R += incr;
+       }
+}
+
+static void seq_vec_5( Fukusosuu *result, double *score1, double *score2, double incr, char *seq )
+{
+       int n;
+       for( ; *seq; result++ )
+       {
+               n = amino_n[(int)*seq++];
+               if( n > 20 ) continue;
+               result->R += incr * score1[n];
+               result->I += incr * score2[n];
+#if 0
+               fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n,  score[n], incr * score[n], result->R );
+#endif
+       }
+}
+
+
+static void seq_vec_4( Fukusosuu *result, double incr, char *seq )
+{
+       char s;
+       for( ; *seq; result++ )
+       {
+               s = *seq++;
+               if( s == 'a' )
+                       result->R += incr;
+               else if( s == 't' )
+                       result->R -= incr;
+               else if( s == 'g' )
+                       result->I += incr;
+               else if( s == 'c' )
+                       result->I -= incr;
+       }
+}
+
+#if 0 // by D.Mathog
+static void seq_vec( Fukusosuu *result, char query, double incr, char *seq )
+{
+#if 0
+       int bk = nlen;
+#endif
+       while( *seq )
+       {
+               if( *seq++ == query ) result->R += incr;
+               result++;
+#if 0
+fprintf( stderr, "i = %d result->R = %f\n", bk-nlen, (result-1)->R );
+#endif
+       }
+}
+
+static int checkRepeat( int num, int *cutpos )
+{
+       int tmp, buf;
+
+       buf = *cutpos;
+       while( num-- )
+       {
+               if( ( tmp = *cutpos++ ) < buf ) return( 1 );
+               buf = tmp;
+       }
+       return( 0 );
+}
+
+static int segcmp( void *ptr1, void *ptr2 )
+{
+       int diff;
+       Segment **seg1 = (Segment **)ptr1;
+       Segment **seg2 = (Segment **)ptr2;
+#if 0
+       return( (*seg1)->center - (*seg2)->center );
+#else
+       diff = (*seg1)->center - (*seg2)->center;
+       if( diff ) return( diff );
+
+       diff = (*seg1)->start - (*seg2)->start;
+       if( diff ) return( diff );
+
+       diff = (*seg1)->end - (*seg2)->end;
+       if( diff ) return( diff );
+
+       fprintf( stderr, "USE STABLE SORT !!\n" );
+       exit( 1 );
+       return( 0 );
+#endif
+}
+#endif
+
+
+static void mymergesort( int first, int last, Segment **seg )
+{
+       int middle;
+       static TLS int i, j, k, p;
+       static TLS int allo = 0;
+       static TLS Segment **work = NULL;
+
+       if( seg == NULL )
+       {
+               free( work ); work = NULL;
+               return;
+       }
+
+       if( last > allo )
+       {
+               allo = last;
+               if( work ) free( work );
+               work = (Segment **)calloc( allo / 2 + 1, sizeof( Segment *) );
+       }
+
+       if( first < last )
+       {
+               middle = ( first + last ) / 2;
+               mymergesort( first, middle, seg );
+               mymergesort( middle+1, last, seg );
+               p = 0;
+               for( i=first; i<=middle; i++ ) work[p++] = seg[i];
+               i = middle + 1; j = 0; k = first;
+               while( i <= last && j < p )
+               {
+                       if( work[j]->center <= seg[i]->center ) 
+                               seg[k++] = work[j++];
+                       else
+                               seg[k++] = seg[i++];
+               }
+               while( j < p ) seg[k++] = work[j++];
+       }
+}
+
+
+double Fgetlag( char  **seq1, char  **seq2, 
+                           double *eff1, double *eff2, 
+                           int    clus1, int    clus2,
+                           int alloclen )
+{
+       int i, j, k, l, m;
+       int nlen, nlen2, nlen4;
+       static TLS int crossscoresize = 0;
+       static TLS char **tmpseq1 = NULL;
+       static TLS char **tmpseq2 = NULL;
+       static TLS char **tmpptr1 = NULL;
+       static TLS char **tmpptr2 = NULL;
+       static TLS char **tmpres1 = NULL;
+       static TLS char **tmpres2 = NULL;
+       static TLS char **result1 = NULL;
+       static TLS char **result2 = NULL;
+#if RND
+       static TLS char **rndseq1 = NULL;
+       static TLS char **rndseq2 = NULL;
+#endif
+       static TLS Fukusosuu **seqVector1 = NULL;
+       static TLS Fukusosuu **seqVector2 = NULL;
+       static TLS Fukusosuu **naiseki = NULL;   
+       static TLS Fukusosuu *naisekiNoWa = NULL; 
+       static TLS double *soukan = NULL;
+       static TLS double **crossscore = NULL;
+       int nlentmp;
+       static TLS int *kouho = NULL;
+       static TLS Segment *segment = NULL;
+       static TLS Segment *segment1 = NULL;
+       static TLS Segment *segment2 = NULL;
+       static TLS Segment **sortedseg1 = NULL;
+       static TLS Segment **sortedseg2 = NULL;
+       static TLS int *cut1 = NULL;
+       static TLS int *cut2 = NULL;
+       static TLS int localalloclen = 0;
+       int lag;
+       int tmpint;
+       int count, count0;
+       int len1, len2;
+       int totallen;
+       float dumfl = 0.0;
+       int headgp, tailgp;
+
+       len1 = strlen( seq1[0] );
+       len2 = strlen( seq2[0] );
+       nlentmp = MAX( len1, len2 );
+
+       nlen = 1;
+       while( nlentmp >= nlen ) nlen <<= 1;
+#if 0
+       fprintf( stderr, "###   nlen    = %d\n", nlen );
+#endif
+
+       nlen2 = nlen/2; nlen4 = nlen2 / 2;
+
+#if DEBUG
+       fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 );
+       fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen );
+#endif
+
+       if( !localalloclen )
+       {
+               kouho = AllocateIntVec( NKOUHO );
+               cut1 = AllocateIntVec( MAXSEG );
+               cut2 = AllocateIntVec( MAXSEG );
+               tmpptr1 = AllocateCharMtx( njob, 0 );
+               tmpptr2 = AllocateCharMtx( njob, 0 );
+               result1 = AllocateCharMtx( njob, alloclen );
+               result2 = AllocateCharMtx( njob, alloclen );
+               tmpres1 = AllocateCharMtx( njob, alloclen );
+               tmpres2 = AllocateCharMtx( njob, alloclen );
+//             crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG );
+               segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) )
+                       ErrorExit( "Allocation error\n" );
+
+               if     ( scoremtx == -1 ) n20or4or2 = 4;
+               else if( fftscore == 1  ) n20or4or2 = 2;
+               else                      n20or4or2 = 20;
+       }
+       if( localalloclen < nlen )
+       {
+               if( localalloclen )
+               {
+#if 1
+                       FreeFukusosuuMtx ( seqVector1 );
+                       FreeFukusosuuMtx ( seqVector2 );
+                       FreeFukusosuuVec( naisekiNoWa );
+                       FreeFukusosuuMtx( naiseki );
+                       FreeDoubleVec( soukan );
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+#endif
+#if RND
+                       FreeCharMtx( rndseq1 );
+                       FreeCharMtx( rndseq2 );
+#endif
+               }
+
+
+               tmpseq1 = AllocateCharMtx( njob, nlen );
+               tmpseq2 = AllocateCharMtx( njob, nlen );
+               naisekiNoWa = AllocateFukusosuuVec( nlen );
+               naiseki = AllocateFukusosuuMtx( n20or4or2, nlen );
+               seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+               seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+               soukan = AllocateDoubleVec( nlen+1 );
+
+#if RND
+               rndseq1 = AllocateCharMtx( njob, nlen );
+               rndseq2 = AllocateCharMtx( njob, nlen );
+               for( i=0; i<njob; i++ )
+               {
+                       generateRndSeq( rndseq1[i], nlen );
+                       generateRndSeq( rndseq2[i], nlen );
+               }
+#endif
+               localalloclen = nlen;
+       }
+       
+       for( j=0; j<clus1; j++ ) strcpy( tmpseq1[j], seq1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( tmpseq2[j], seq2[j] );
+
+#if 0
+fftfp = fopen( "input_of_Falign", "w" );
+fprintf( fftfp, "nlen = %d\n", nlen );
+fprintf( fftfp, "seq1: ( %d sequences ) \n", clus1 );
+for( i=0; i<clus1; i++ )
+       fprintf( fftfp, "%s\n", seq1[i] );
+fprintf( fftfp, "seq2: ( %d sequences ) \n", clus2 );
+for( i=0; i<clus2; i++ )
+       fprintf( fftfp, "%s\n", seq2[i] );
+fclose( fftfp );
+system( "less input_of_Falign < /dev/tty > /dev/tty" );
+#endif
+
+       if( fftkeika ) fprintf( stderr,  " FFT ... " );
+
+       for( j=0; j<n20or4or2; j++ ) vec_init( seqVector1[j], nlen );
+       if( fftscore && scoremtx != -1 )
+       {
+               for( i=0; i<clus1; i++ )
+               {
+                       seq_vec_2( seqVector1[0], polarity, eff1[i], tmpseq1[i] );
+                       seq_vec_2( seqVector1[1], volume,   eff1[i], tmpseq1[i] );
+               }
+       }
+       else
+       {
+#if 0
+               for( i=0; i<clus1; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                       seq_vec( seqVector1[j], amino[j], eff1[i], tmpseq1[i] );
+#else
+               for( i=0; i<clus1; i++ )
+                       seq_vec_3( seqVector1, eff1[i], tmpseq1[i] );
+#endif
+       }
+#if RND
+       for( i=0; i<clus1; i++ )
+       {
+               vec_init2( seqVector1, rndseq1[i], eff1[i], len1, nlen );
+       }
+#endif
+#if 0
+fftfp = fopen( "seqVec", "w" );
+fprintf( fftfp, "before transform\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "nlen=%d\n", nlen );
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector1[k][l].R, seqVector1[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec < /dev/tty > /dev/tty" );
+#endif
+
+       for( j=0; j<n20or4or2; j++ ) vec_init( seqVector2[j], nlen );
+       if( fftscore && scoremtx != -1 )
+       {
+               for( i=0; i<clus2; i++ )
+               {
+                       seq_vec_2( seqVector2[0], polarity, eff2[i], tmpseq2[i] );
+                       seq_vec_2( seqVector2[1], volume,   eff2[i], tmpseq2[i] );
+               }
+       }
+       else
+       {
+#if 0
+               for( i=0; i<clus2; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                       seq_vec( seqVector2[j], amino[j], eff2[i], tmpseq2[i] );
+#else
+               for( i=0; i<clus2; i++ )
+                       seq_vec_3( seqVector2, eff2[i], tmpseq2[i] );
+#endif
+       }
+#if RND
+       for( i=0; i<clus2; i++ )
+       {
+               vec_init2( seqVector2, rndseq2[i], eff2[i], len2, nlen );
+       }
+#endif
+
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "before fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+       for( j=0; j<n20or4or2; j++ )
+       {
+               fft( nlen, seqVector2[j], 0 );
+               fft( nlen, seqVector1[j], 0 );
+       }
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "#after fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "#%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+       for( k=0; k<n20or4or2; k++ ) 
+       {
+               for( l=0; l<nlen; l++ ) 
+                       calcNaiseki( naiseki[k]+l, seqVector1[k]+l, seqVector2[k]+l );
+       }
+       for( l=0; l<nlen; l++ ) 
+       {
+               naisekiNoWa[l].R = 0.0;
+               naisekiNoWa[l].I = 0.0;
+               for( k=0; k<n20or4or2; k++ ) 
+               {
+                       naisekiNoWa[l].R += naiseki[k][l].R;
+                       naisekiNoWa[l].I += naiseki[k][l].I;
+               }
+       }
+
+#if 0
+fftfp = fopen( "naisekiNoWa", "w" );
+fprintf( fftfp, "#Before fft\n" );
+for( l=0; l<nlen; l++ )
+       fprintf( fftfp, "%d  %f %f\n", l, naisekiNoWa[l].R, naisekiNoWa[l].I ); 
+fclose( fftfp );
+system( "less naisekiNoWa < /dev/tty > /dev/tty " );
+#endif
+
+       fft( -nlen, naisekiNoWa, 0 );
+
+       for( m=0; m<=nlen2; m++ ) 
+               soukan[m] = naisekiNoWa[nlen2-m].R;
+       for( m=nlen2+1; m<nlen; m++ ) 
+               soukan[m] = naisekiNoWa[nlen+nlen2-m].R;
+
+#if 0
+fftfp = fopen( "naisekiNoWa", "w" );
+fprintf( fftfp, "#After fft\n" );
+for( l=0; l<nlen; l++ )
+       fprintf( fftfp, "%d  %f\n", l, naisekiNoWa[l].R ); 
+fclose( fftfp );
+fftfp = fopen( "list.plot", "w"  );
+fprintf( fftfp, "plot 'naisekiNoWa'\npause -1" );
+fclose( fftfp );
+system( "/usr/bin/gnuplot list.plot &" );
+#endif
+#if 0
+fprintf( stderr, "frt write start\n" );
+fftfp = fopen( "frt", "w" );
+for( l=0; l<nlen; l++ )
+       fprintf( fftfp, "%d  %f\n", l-nlen2, soukan[l] ); 
+fclose( fftfp );
+system( "less frt < /dev/tty > /dev/tty" );
+#if 0
+fftfp = fopen( "list.plot", "w"  );
+fprintf( fftfp, "plot 'frt'\n pause +1" );
+fclose( fftfp );
+system( "/usr/bin/gnuplot list.plot" );
+#endif
+#endif
+
+
+       getKouho( kouho, NKOUHO, soukan, nlen );
+
+#if 0
+       for( i=0; i<NKOUHO; i++ )
+       {
+               fprintf( stdout, "kouho[%d] = %d\n", i, kouho[i] );
+       }
+#endif
+
+#if KEIKA
+       fprintf( stderr, "Searching anchors ... " );
+#endif
+       count = 0;
+
+
+
+#define CAND 0
+#if CAND
+       fftfp = fopen( "cand", "w" );
+       fclose( fftfp );
+#endif
+
+       for( k=0; k<NKOUHO; k++ ) 
+       {
+
+               lag = kouho[k];
+               zurasu2( lag, clus1, clus2, seq1, seq2, tmpptr1, tmpptr2 );
+#if CAND
+               fftfp = fopen( "cand", "a" );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr1[0] );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr2[0] );
+               fprintf( fftfp, ">\n", k+1, lag );
+               fclose( fftfp );
+#endif
+               tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count );
+               
+               if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" );
+
+
+               if( tmpint == 0 ) break; // 060430 iinoka ?
+               while( tmpint-- > 0 )
+               {
+                       if( lag > 0 )
+                       {
+                               segment1[count].start  = segment[count].start ;
+                               segment1[count].end    = segment[count].end   ;
+                               segment1[count].center = segment[count].center;
+                               segment1[count].score  = segment[count].score;
+
+                               segment2[count].start  = segment[count].start  + lag;
+                               segment2[count].end    = segment[count].end    + lag;
+                               segment2[count].center = segment[count].center + lag;
+                               segment2[count].score  = segment[count].score       ;
+                       }
+                       else
+                       {
+                               segment1[count].start  = segment[count].start  - lag;
+                               segment1[count].end    = segment[count].end    - lag;
+                               segment1[count].center = segment[count].center - lag;
+                               segment1[count].score  = segment[count].score       ;
+
+                               segment2[count].start  = segment[count].start ;
+                               segment2[count].end    = segment[count].end   ;
+                               segment2[count].center = segment[count].center;
+                               segment2[count].score  = segment[count].score ;
+                       }
+#if 0
+                       fprintf( stderr, "Goukaku=%dko\n", tmpint ); 
+                       fprintf( stderr, "in 1 %d\n", segment1[count].center );
+                       fprintf( stderr, "in 2 %d\n", segment2[count].center );
+#endif
+                       segment1[count].pair = &segment2[count];
+                       segment2[count].pair = &segment1[count];
+                       count++;
+#if 0
+                       fprintf( stderr, "count=%d\n", count );
+#endif
+               }
+       }
+
+#if 1
+       fprintf( stderr, "done. (%d anchors)\r", count );
+#endif
+       if( !count && fftNoAnchStop )
+               ErrorExit( "Cannot detect anchor!" );
+#if 0
+       fprintf( stdout, "RESULT before sort:\n" );
+       for( l=0; l<count+1; l++ )
+       {
+               fprintf( stdout, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( stdout, "%d score = %f\n", segment2[l].center, segment1[l].score );
+       }
+       exit( 1 );
+#endif
+
+#if KEIKA
+       fprintf( stderr, "Aligning anchors ... " );
+#endif
+       for( i=0; i<count; i++ )
+       {
+               sortedseg1[i] = &segment1[i];
+               sortedseg2[i] = &segment2[i];
+       }
+
+       {
+               mymergesort( 0, count-1, sortedseg1 ); 
+               mymergesort( 0, count-1, sortedseg2 ); 
+               for( i=0; i<count; i++ ) sortedseg1[i]->number = i;
+               for( i=0; i<count; i++ ) sortedseg2[i]->number = i;
+
+               if( crossscoresize < count+2 )
+               {
+                       crossscoresize = count+2;
+                       fprintf( stderr, "####################################################################################################################################allocating crossscore, size = %d\n", crossscoresize );
+                       if( crossscore ) FreeDoubleMtx( crossscore );
+                       crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+               }
+
+               for( i=0; i<count+2; i++ ) for( j=0; j<count+2; j++ )
+                       crossscore[i][j] = 0.0;
+               for( i=0; i<count; i++ )
+               {
+                       crossscore[segment1[i].number+1][segment1[i].pair->number+1] = segment1[i].score;
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+
+#if DEBUG
+               fprintf( stderr, "AFTER SORT\n" );
+               for( i=0; i<count; i++ ) fprintf( stderr, "%d, %d\n", segment1[i].start, segment2[i].start );
+#endif
+
+               crossscore[0][0] = 10000000.0;
+               cut1[0] = 0; 
+               cut2[0] = 0;
+               crossscore[count+1][count+1] = 10000000.0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+               count0 = count;
+
+               blockAlign2( cut1, cut2, sortedseg1, sortedseg2, crossscore, &count );
+       }
+       if( fftkeika )
+       {
+               if( count0 > count )
+               {
+                       fprintf( stderr, "REPEAT!? \n" ); 
+                       if( fftRepeatStop ) exit( 1 );
+               }
+#if KEIKA
+               else 
+                       fprintf( stderr, "done\n" );
+                       fprintf( stderr, "done. (%d anchors)\n", count );
+#endif
+       }
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( fftfp, "%d\n", segment2[l].center );
+       }
+       fclose( fftfp );
+#endif
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut : %d %d\n", cut1[l], cut2[l] );
+       }
+       fclose( fftfp );
+#endif
+
+#if KEIKA
+       fprintf( trap_g, "Devided to %d segments\n", count-1 );
+       fprintf( trap_g, "%d  %d forg\n", MIN( clus1, clus2 ), count-1 );
+#endif
+
+       totallen = 0;
+       for( j=0; j<clus1; j++ ) result1[j][0] = 0;
+       for( j=0; j<clus2; j++ ) result2[j][0] = 0;
+       for( i=0; i<count-1; i++ )
+       {
+               if( i == 0 ) headgp = outgap; else headgp = 1;
+               if( i == count-2 ) tailgp = outgap; else tailgp = 1;
+               
+#if DEBUG
+               fprintf( stderr, "DP %03d / %03d %4d to ", i+1, count-1, totallen );
+#else
+#if KEIKA
+               fprintf( stderr, "DP %03d / %03d\r", i+1, count-1 );
+#endif
+#endif
+               for( j=0; j<clus1; j++ )
+               {
+                       strncpy( tmpres1[j], seq1[j]+cut1[i], cut1[i+1]-cut1[i] );
+                       tmpres1[j][cut1[i+1]-cut1[i]] = 0;
+               }
+               for( j=0; j<clus2; j++ )
+               {
+                       strncpy( tmpres2[j], seq2[j]+cut2[i], cut2[i+1]-cut2[i] );
+                       tmpres2[j][cut2[i+1]-cut2[i]] = 0;
+               }
+               switch( alg )
+               {
+                       case( 'a' ):
+                               Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen );
+                               break;
+                       case( 'M' ):
+                                       MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp );
+                               break;
+                       case( 'A' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                                       G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               else
+                                       A__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, headgp, tailgp );
+                               break;
+                       case( 'H' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                                       G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               else
+                                       H__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                               break;
+                       case( 'Q' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                                       G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               else
+                                       Q__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                               break;
+                       default:
+                               fprintf( stderr, "alg = %c\n", alg );
+                               ErrorExit( "ERROR IN SOURCE FILE Falign.c" );
+                               break;
+               }
+
+               nlen = strlen( tmpres1[0] );
+               if( totallen + nlen > alloclen ) ErrorExit( "LENGTH OVER in Falign\n " );
+               for( j=0; j<clus1; j++ ) strcat( result1[j], tmpres1[j] );
+               for( j=0; j<clus2; j++ ) strcat( result2[j], tmpres2[j] );
+               totallen += nlen;
+#if 0
+               fprintf( stderr, "%4d\r", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+       }
+#if KEIKA
+       fprintf( stderr, "DP ... done   \n" );
+#endif
+
+       for( j=0; j<clus1; j++ ) strcpy( seq1[j], result1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( seq2[j], result2[j] );
+#if 0
+       for( j=0; j<clus1; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result1[j] );
+       }
+       fprintf( stderr, "- - - - - - - - - - -\n" );
+       for( j=0; j<clus2; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result2[j] );
+       }
+#endif
+       return( 0.0 );
+}
+
+
+
+float Falign( char  **seq1, char  **seq2, 
+                         double *eff1, double *eff2, 
+                         int    clus1, int    clus2,
+                         int alloclen, int *fftlog,
+                         int *chudanpt, int chudanref, int *chudanres )
+{
+       int i, j, k, l, m, maxk;
+       int nlen, nlen2, nlen4;
+       static TLS int prevalloclen = 0;
+       static TLS int crossscoresize = 0;
+       static TLS char **tmpseq1 = NULL;
+       static TLS char **tmpseq2 = NULL;
+       static TLS char **tmpptr1 = NULL;
+       static TLS char **tmpptr2 = NULL;
+       static TLS char **tmpres1 = NULL;
+       static TLS char **tmpres2 = NULL;
+       static TLS char **result1 = NULL;
+       static TLS char **result2 = NULL;
+#if RND
+       static TLS char **rndseq1 = NULL;
+       static TLS char **rndseq2 = NULL;
+#endif
+       static TLS Fukusosuu **seqVector1 = NULL;
+       static TLS Fukusosuu **seqVector2 = NULL;
+       static TLS Fukusosuu **naiseki = NULL;   
+       static TLS Fukusosuu *naisekiNoWa = NULL; 
+       static TLS double *soukan = NULL;
+       static TLS double **crossscore = NULL;
+       int nlentmp;
+       static TLS int *kouho = NULL;
+       static TLS Segment *segment = NULL;
+       static TLS Segment *segment1 = NULL;
+       static TLS Segment *segment2 = NULL;
+       static TLS Segment **sortedseg1 = NULL;
+       static TLS Segment **sortedseg2 = NULL;
+       static TLS int *cut1 = NULL;
+       static TLS int *cut2 = NULL;
+       static TLS char *sgap1, *egap1, *sgap2, *egap2;
+       static TLS int localalloclen = 0;
+       int lag;
+       int tmpint;
+       int count, count0;
+       int len1, len2;
+       int totallen;
+       float totalscore;
+       float dumfl = 0.0;
+       int headgp, tailgp;
+
+
+       if( seq1 == NULL )
+       {
+               if( result1 ) 
+               {
+//                     fprintf( stderr, "Freeing localarrays in Falign\n" );
+                       localalloclen = 0;
+                       mymergesort( 0, 0, NULL );
+                       alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL );
+                       fft( 0, NULL, 1 );
+                       A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 );
+                       G__align11( NULL, NULL, 0, 0, 0 );
+                       blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL );
+                       if( crossscore ) FreeDoubleMtx( crossscore );
+                       FreeCharMtx( result1 );
+                       FreeCharMtx( result2 );
+                       FreeCharMtx( tmpres1 );
+                       FreeCharMtx( tmpres2 );
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+                       free( sgap1 );
+                       free( egap1 );
+                       free( sgap2 );
+                       free( egap2 );
+                       free( kouho );
+                       free( cut1 );
+                       free( cut2 );
+                       free( tmpptr1 );
+                       free( tmpptr2 );
+                       free( segment );
+                       free( segment1 );
+                       free( segment2 );
+                       free( sortedseg1 );
+                       free( sortedseg2 );
+                       if( !kobetsubunkatsu )
+                       {
+                               FreeFukusosuuMtx ( seqVector1 );
+                               FreeFukusosuuMtx ( seqVector2 );
+                               FreeFukusosuuVec( naisekiNoWa );
+                               FreeFukusosuuMtx( naiseki );
+                               FreeDoubleVec( soukan );
+                       }
+               }
+               else
+               {
+//                     fprintf( stderr, "Did not allocate localarrays in Falign\n" );
+               }
+
+               return( 0.0 );
+       }
+
+       len1 = strlen( seq1[0] );
+       len2 = strlen( seq2[0] );
+       nlentmp = MAX( len1, len2 );
+
+       nlen = 1;
+       while( nlentmp >= nlen ) nlen <<= 1;
+#if 0
+       fprintf( stderr, "###   nlen    = %d\n", nlen );
+#endif
+
+       nlen2 = nlen/2; nlen4 = nlen2 / 2;
+
+#if DEBUG
+       fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 );
+       fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen );
+#endif
+
+       if( prevalloclen != alloclen ) // Falign_noudp mo kaeru
+       {
+               if( prevalloclen )
+               {
+                       FreeCharMtx( result1 );
+                       FreeCharMtx( result2 );
+                       FreeCharMtx( tmpres1 );
+                       FreeCharMtx( tmpres2 );
+               }
+//             fprintf( stderr, "\n\n\nreallocating ...\n" ); 
+               result1 = AllocateCharMtx( njob, alloclen );
+               result2 = AllocateCharMtx( njob, alloclen );
+               tmpres1 = AllocateCharMtx( njob, alloclen );
+               tmpres2 = AllocateCharMtx( njob, alloclen );
+               prevalloclen = alloclen;
+       }
+       if( !localalloclen )
+       {
+               sgap1 = AllocateCharVec( njob );
+               egap1 = AllocateCharVec( njob );
+               sgap2 = AllocateCharVec( njob );
+               egap2 = AllocateCharVec( njob );
+               kouho = AllocateIntVec( NKOUHO );
+               cut1 = AllocateIntVec( MAXSEG );
+               cut2 = AllocateIntVec( MAXSEG );
+               tmpptr1 = AllocateCharMtx( njob, 0 );
+               tmpptr2 = AllocateCharMtx( njob, 0 );
+//             crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG );
+               segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) )
+                       ErrorExit( "Allocation error\n" );
+
+               if     ( scoremtx == -1 ) n20or4or2 = 1;
+               else if( fftscore )       n20or4or2 = 1;
+               else                      n20or4or2 = 20;
+       }
+       if( localalloclen < nlen )
+       {
+               if( localalloclen )
+               {
+#if 1
+                       if( !kobetsubunkatsu )
+                       {
+                               FreeFukusosuuMtx ( seqVector1 );
+                               FreeFukusosuuMtx ( seqVector2 );
+                               FreeFukusosuuVec( naisekiNoWa );
+                               FreeFukusosuuMtx( naiseki );
+                               FreeDoubleVec( soukan );
+                       }
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+#endif
+#if RND
+                       FreeCharMtx( rndseq1 );
+                       FreeCharMtx( rndseq2 );
+#endif
+               }
+
+               tmpseq1 = AllocateCharMtx( njob, nlen );
+               tmpseq2 = AllocateCharMtx( njob, nlen );
+               if( !kobetsubunkatsu )
+               {
+                       naisekiNoWa = AllocateFukusosuuVec( nlen );
+                       naiseki = AllocateFukusosuuMtx( n20or4or2, nlen );
+                       seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+                       seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+                       soukan = AllocateDoubleVec( nlen+1 );
+               }
+#if RND
+               rndseq1 = AllocateCharMtx( njob, nlen );
+               rndseq2 = AllocateCharMtx( njob, nlen );
+               for( i=0; i<njob; i++ )
+               {
+                       generateRndSeq( rndseq1[i], nlen );
+                       generateRndSeq( rndseq2[i], nlen );
+               }
+#endif
+               localalloclen = nlen;
+       }
+       
+       for( j=0; j<clus1; j++ ) strcpy( tmpseq1[j], seq1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( tmpseq2[j], seq2[j] );
+
+#if 0
+fftfp = fopen( "input_of_Falign", "w" );
+fprintf( fftfp, "nlen = %d\n", nlen );
+fprintf( fftfp, "seq1: ( %d sequences ) \n", clus1 );
+for( i=0; i<clus1; i++ )
+       fprintf( fftfp, "%s\n", seq1[i] );
+fprintf( fftfp, "seq2: ( %d sequences ) \n", clus2 );
+for( i=0; i<clus2; i++ )
+       fprintf( fftfp, "%s\n", seq2[i] );
+fclose( fftfp );
+system( "less input_of_Falign < /dev/tty > /dev/tty" );
+#endif
+       if( !kobetsubunkatsu )
+       {
+               if( fftkeika ) fprintf( stderr,  " FFT ... " );
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector1[j], nlen );
+               if( fftscore && scoremtx != -1 )
+               {
+                       for( i=0; i<clus1; i++ )
+                       {
+#if 1
+                               seq_vec_5( seqVector1[0], polarity, volume, eff1[i], tmpseq1[i] );
+#else
+                               seq_vec_2( seqVector1[0], polarity, eff1[i], tmpseq1[i] );
+                               seq_vec_2( seqVector1[1], volume,   eff1[i], tmpseq1[i] );
+#endif
+                       }
+               }
+               else
+               {
+#if 0
+                       for( i=0; i<clus1; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                               seq_vec( seqVector1[j], amino[j], eff1[i], tmpseq1[i] );
+#else
+                       for( i=0; i<clus1; i++ )
+                               seq_vec_3( seqVector1, eff1[i], tmpseq1[i] );
+#endif
+               }
+#if RND
+               for( i=0; i<clus1; i++ )
+               {
+                       vec_init2( seqVector1, rndseq1[i], eff1[i], len1, nlen );
+               }
+#endif
+#if 0
+fftfp = fopen( "seqVec", "w" );
+fprintf( fftfp, "before transform\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "nlen=%d\n", nlen );
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector1[k][l].R, seqVector1[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector2[j], nlen );
+               if( fftscore && scoremtx != -1 )
+               {
+                       for( i=0; i<clus2; i++ )
+                       {
+#if 1
+                               seq_vec_5( seqVector2[0], polarity, volume, eff2[i], tmpseq2[i] );
+#else
+                               seq_vec_2( seqVector2[0], polarity, eff2[i], tmpseq2[i] );
+                               seq_vec_2( seqVector2[1], volume,   eff2[i], tmpseq2[i] );
+#endif
+                       }
+               }
+               else
+               {
+#if 0
+                       for( i=0; i<clus2; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                               seq_vec( seqVector2[j], amino[j], eff2[i], tmpseq2[i] );
+#else
+                       for( i=0; i<clus2; i++ )
+                               seq_vec_3( seqVector2, eff2[i], tmpseq2[i] );
+#endif
+               }
+#if RND
+               for( i=0; i<clus2; i++ )
+               {
+                       vec_init2( seqVector2, rndseq2[i], eff2[i], len2, nlen );
+               }
+#endif
+
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "before fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ )
+               {
+                       fft( nlen, seqVector2[j], 0 );
+                       fft( nlen, seqVector1[j], 0 );
+               }
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "#after fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "#%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+          fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( k=0; k<n20or4or2; k++ ) 
+               {
+                       for( l=0; l<nlen; l++ ) 
+                               calcNaiseki( naiseki[k]+l, seqVector1[k]+l, seqVector2[k]+l );
+               }
+               for( l=0; l<nlen; l++ ) 
+               {
+                       naisekiNoWa[l].R = 0.0;
+                       naisekiNoWa[l].I = 0.0;
+                       for( k=0; k<n20or4or2; k++ ) 
+                       {
+                               naisekiNoWa[l].R += naiseki[k][l].R;
+                               naisekiNoWa[l].I += naiseki[k][l].I;
+                       }
+               }
+       
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#Before fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f %f\n", l, naisekiNoWa[l].R, naisekiNoWa[l].I ); 
+       fclose( fftfp );
+       system( "less naisekiNoWa < /dev/tty > /dev/tty " );
+#endif
+
+               fft( -nlen, naisekiNoWa, 0 );
+       
+               for( m=0; m<=nlen2; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen2-m].R;
+               for( m=nlen2+1; m<nlen; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen+nlen2-m].R;
+
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#After fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f\n", l, naisekiNoWa[l].R ); 
+       fclose( fftfp );
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'naisekiNoWa'\npause -1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot &" );
+#endif
+#if 0
+       fprintf( stderr, "soukan\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( stderr, "%d  %f\n", l-nlen2, soukan[l] ); 
+#if 0
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'frt'\n pause +1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot" );
+#endif
+#endif
+
+
+               getKouho( kouho, NKOUHO, soukan, nlen );
+
+#if 0
+               for( i=0; i<NKOUHO; i++ )
+               {
+                       fprintf( stderr, "kouho[%d] = %d\n", i, kouho[i] );
+               }
+#endif
+       }
+
+#if KEIKA
+       fprintf( stderr, "Searching anchors ... " );
+#endif
+       count = 0;
+
+
+
+#define CAND 0
+#if CAND
+       fftfp = fopen( "cand", "w" );
+       fclose( fftfp );
+#endif
+       if( kobetsubunkatsu )
+       {
+               maxk = 1;
+               kouho[0] = 0;
+       }
+       else
+       {
+               maxk = NKOUHO;
+       }
+
+       for( k=0; k<maxk; k++ ) 
+       {
+               lag = kouho[k];
+               if( lag <= -len1 || len2 <= lag ) continue;
+               zurasu2( lag, clus1, clus2, seq1, seq2, tmpptr1, tmpptr2 );
+#if CAND
+               fftfp = fopen( "cand", "a" );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr1[0] );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr2[0] );
+               fprintf( fftfp, ">\n", k+1, lag );
+               fclose( fftfp );
+#endif
+
+//             fprintf( stderr, "lag = %d\n", lag );
+               tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count );
+
+//             if( lag == -50 ) exit( 1 );
+               
+               if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" );
+
+
+               if( tmpint == 0 ) break; // 060430 iinoka ?
+               while( tmpint-- > 0 )
+               {
+#if 0
+                       if( segment[count].end - segment[count].start < fftWinSize )
+                       {
+                               count++;
+                               continue;
+                       }
+#endif
+                       if( lag > 0 )
+                       {
+                               segment1[count].start  = segment[count].start ;
+                               segment1[count].end    = segment[count].end   ;
+                               segment1[count].center = segment[count].center;
+                               segment1[count].score  = segment[count].score;
+
+                               segment2[count].start  = segment[count].start  + lag;
+                               segment2[count].end    = segment[count].end    + lag;
+                               segment2[count].center = segment[count].center + lag;
+                               segment2[count].score  = segment[count].score       ;
+                       }
+                       else
+                       {
+                               segment1[count].start  = segment[count].start  - lag;
+                               segment1[count].end    = segment[count].end    - lag;
+                               segment1[count].center = segment[count].center - lag;
+                               segment1[count].score  = segment[count].score       ;
+
+                               segment2[count].start  = segment[count].start ;
+                               segment2[count].end    = segment[count].end   ;
+                               segment2[count].center = segment[count].center;
+                               segment2[count].score  = segment[count].score ;
+                       }
+#if 0
+                       fprintf( stderr, "in 1 %d\n", segment1[count].center );
+                       fprintf( stderr, "in 2 %d\n", segment2[count].center );
+#endif
+                       segment1[count].pair = &segment2[count];
+                       segment2[count].pair = &segment1[count];
+                       count++;
+               }
+       }
+#if 0
+       if( !kobetsubunkatsu && fftkeika )
+               fprintf( stderr, "%d anchors found\r", count );
+#endif
+       if( !count && fftNoAnchStop )
+               ErrorExit( "Cannot detect anchor!" );
+#if 0
+       fprintf( stderr, "RESULT before sort:\n" );
+       for( l=0; l<count+1; l++ )
+       {
+               fprintf( stderr, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( stderr, "%d score = %f\n", segment2[l].center, segment1[l].score );
+       }
+#endif
+
+#if KEIKA
+       fprintf( stderr, "done. (%d anchors)\n", count );
+       fprintf( stderr, "Aligning anchors ... " );
+#endif
+       for( i=0; i<count; i++ )
+       {
+               sortedseg1[i] = &segment1[i];
+               sortedseg2[i] = &segment2[i];
+       }
+#if 0
+       tmpsort( count, sortedseg1 ); 
+       tmpsort( count, sortedseg2 ); 
+       qsort( sortedseg1, count, sizeof( Segment * ), segcmp );
+       qsort( sortedseg2, count, sizeof( Segment * ), segcmp );
+#else
+       mymergesort( 0, count-1, sortedseg1 ); 
+       mymergesort( 0, count-1, sortedseg2 ); 
+#endif
+       for( i=0; i<count; i++ ) sortedseg1[i]->number = i;
+       for( i=0; i<count; i++ ) sortedseg2[i]->number = i;
+
+
+       if( kobetsubunkatsu )
+       {
+               for( i=0; i<count; i++ )
+           {
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+               cut1[0] = 0;
+               cut2[0] = 0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+       }
+       else
+       {
+               if( crossscoresize < count+2 )
+               {
+                       crossscoresize = count+2;
+#if 1
+                       if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize );
+#endif
+                       if( crossscore ) FreeDoubleMtx( crossscore );
+                       crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+               }
+               for( i=0; i<count+2; i++ ) for( j=0; j<count+2; j++ )
+                       crossscore[i][j] = 0.0;
+               for( i=0; i<count; i++ )
+               {
+                       crossscore[segment1[i].number+1][segment1[i].pair->number+1] = segment1[i].score;
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+
+#if 0
+               fprintf( stderr, "AFTER SORT\n" );
+               for( i=0; i<count+1; i++ ) fprintf( stderr, "%d, %d\n", cut1[i], cut2[i] );
+               fprintf( stderr, "crossscore = \n" );
+               for( i=0; i<count+1; i++ )
+               {
+                       for( j=0; j<count+1; j++ )
+                               fprintf( stderr, "%.0f ", crossscore[i][j] );
+                       fprintf( stderr, "\n" );
+               }
+#endif
+
+               crossscore[0][0] = 10000000.0;
+               cut1[0] = 0; 
+               cut2[0] = 0;
+               crossscore[count+1][count+1] = 10000000.0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+               count0 = count;
+       
+               blockAlign2( cut1, cut2, sortedseg1, sortedseg2, crossscore, &count );
+
+//             if( count-count0 )
+//                     fprintf( stderr, "%d unused anchors\n", count0-count );
+
+               if( !kobetsubunkatsu && fftkeika )
+                       fprintf( stderr, "%d anchors found\n", count );
+               if( fftkeika )
+               {
+                       if( count0 > count )
+                       {
+#if 0
+                               fprintf( stderr, "\7 REPEAT!? \n" ); 
+#else
+                               fprintf( stderr, "REPEAT!? \n" ); 
+#endif
+                               if( fftRepeatStop ) exit( 1 );
+                       }
+#if KEIKA
+                       else fprintf( stderr, "done\n" );
+#endif
+               }
+       }
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( fftfp, "%d\n", segment2[l].center );
+       }
+       fclose( fftfp );
+#endif
+
+#if 0
+       fprintf( stderr, "RESULT after blckalign:\n" );
+       for( l=0; l<count+1; l++ )
+       {
+               fprintf( stderr, "cut : %d %d\n", cut1[l], cut2[l] );
+       }
+#endif
+
+#if 0
+       fprintf( trap_g, "Devided to %d segments\n", count-1 );
+       fprintf( trap_g, "%d  %d forg\n", MIN( clus1, clus2 ), count-1 );
+#endif
+
+       totallen = 0;
+       for( j=0; j<clus1; j++ ) result1[j][0] = 0;
+       for( j=0; j<clus2; j++ ) result2[j][0] = 0;
+       totalscore = 0.0;
+       *fftlog = -1;
+       for( i=0; i<count-1; i++ )
+       {
+               *fftlog += 1;
+               if( i == 0 ) headgp = outgap; else headgp = 1;
+               if( i == count-2 ) tailgp = outgap; else tailgp = 1;
+
+
+               if( cut1[i] ) // chuui
+               {
+//                     getkyokaigap( sgap1, tmpres1, nlen-1, clus1 );
+//                     getkyokaigap( sgap2, tmpres2, nlen-1, clus2 );
+                       getkyokaigap( sgap1, tmpres1, nlen-1, clus1 );
+                       getkyokaigap( sgap2, tmpres2, nlen-1, clus2 );
+               }
+               else
+               {
+                       for( j=0; j<clus1; j++ ) sgap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) sgap2[j] = 'o';
+               }
+               if( cut1[i+1] != len1 ) // chuui
+               {       
+                       getkyokaigap( egap1, seq1, cut1[i+1], clus1 );
+                       getkyokaigap( egap2, seq2, cut2[i+1], clus2 );
+               }       
+               else    
+               {       
+                       for( j=0; j<clus1; j++ ) egap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) egap2[j] = 'o';
+               }
+#if 0
+               {
+                       fprintf( stderr, "kyokkaigap1(%d)=", cut1[i]-1 );
+                       for( j=0; j<clus1; j++ )
+                               fprintf( stderr, "%c", sgap1[j] );
+                       fprintf( stderr, "=kyokkaigap1-start\n" );
+               }
+               {
+                       fprintf( stderr, "kyokkaigap2(%d)=", cut2[i]-1 );
+                       for( j=0; j<clus2; j++ )
+                               fprintf( stderr, "%c", sgap2[j] );
+                       fprintf( stderr, "=kyokkaigap2-start\n" );
+               }
+               {
+                       fprintf( stderr, "kyokkaigap1(%d)=", cut1[i]-1 );
+                       for( j=0; j<clus1; j++ )
+                               fprintf( stderr, "%c", egap1[j] );
+                       fprintf( stderr, "=kyokkaigap1-end\n" );
+               }
+               {
+                       fprintf( stderr, "kyokkaigap2(%d)=", cut2[i]-1 );
+                       for( j=0; j<clus2; j++ )
+                               fprintf( stderr, "%c", egap2[j] );
+                       fprintf( stderr, "=kyokkaigap2-end\n" );
+               }
+#endif
+
+#if DEBUG
+               fprintf( stderr, "DP %03d / %03d %4d to ", i+1, count-1, totallen );
+#else
+#if KEIKA
+               fprintf( stderr, "DP %03d / %03d\r", i+1, count-1 );
+#endif
+#endif
+               for( j=0; j<clus1; j++ )
+               {
+                       strncpy( tmpres1[j], seq1[j]+cut1[i], cut1[i+1]-cut1[i] );
+                       tmpres1[j][cut1[i+1]-cut1[i]] = 0;
+               }
+               if( kobetsubunkatsu && fftkeika ) commongappick( clus1, tmpres1 ); //dvtditr \e$B$K8F$P$l$?$H$-\e(B fftkeika=1
+//             if( kobetsubunkatsu ) commongappick( clus1, tmpres1 );
+               for( j=0; j<clus2; j++ )
+               {
+                       strncpy( tmpres2[j], seq2[j]+cut2[i], cut2[i+1]-cut2[i] );
+                       tmpres2[j][cut2[i+1]-cut2[i]] = 0;
+               }
+               if( kobetsubunkatsu && fftkeika ) commongappick( clus2, tmpres2 ); //dvtditr \e$B$K8F$P$l$?$H$-\e(B fftkeika=1
+//             if( kobetsubunkatsu ) commongappick( clus2, tmpres2 );
+
+               if( constraint )
+               {
+                       fprintf( stderr, "Not supported\n" );
+                       exit( 1 );
+               }
+#if 0
+               fprintf( stderr, "i=%d, before alignment", i );
+               fprintf( stderr, "%4d\n", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+
+#if 0
+               fprintf( stdout, "writing input\n" );
+               for( j=0; j<clus1; j++ )
+               {
+                       fprintf( stdout, ">%d of GROUP1\n", j );
+                       fprintf( stdout, "%s\n", tmpres1[j] );
+               }
+               for( j=0; j<clus2; j++ )
+               {
+                       fprintf( stdout, ">%d of GROUP2\n", j );
+                       fprintf( stdout, "%s\n", tmpres2[j] );
+               }
+               fflush( stdout );
+#endif
+               switch( alg )
+               {
+                       case( 'a' ):
+                               totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen );
+                               break;
+                       case( 'M' ):
+                                       totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp );
+                               break;
+                       case( 'A' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                               {
+                                       totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               }
+                               else
+                                       totalscore += A__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres, headgp, tailgp );
+                               break;
+                       case( 'H' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                               {
+                                       totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               }
+                               else
+                                       totalscore += H__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 );
+                               break;
+                       case( 'Q' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                               {
+                                       totalscore += G__align11( tmpres1, tmpres2, alloclen, headgp, tailgp );
+                               }
+                               else
+                                       totalscore += Q__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, NULL, &dumfl, sgap1, sgap2, egap1, egap2 );
+                               break;
+                       default:
+                               fprintf( stderr, "alg = %c\n", alg );
+                               ErrorExit( "ERROR IN SOURCE FILE Falign.c" );
+                               break;
+               }
+
+#ifdef enablemultithread
+               if( chudanres && *chudanres )
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! at Falign_localhom\n" );
+                       return( -1.0 );
+               }
+#endif
+
+               nlen = strlen( tmpres1[0] );
+               if( totallen + nlen > alloclen )
+               {
+                       fprintf( stderr, "totallen=%d +  nlen=%d > alloclen = %d\n", totallen, nlen, alloclen );
+                       ErrorExit( "LENGTH OVER in Falign\n " );
+               }
+               for( j=0; j<clus1; j++ ) strcat( result1[j], tmpres1[j] );
+               for( j=0; j<clus2; j++ ) strcat( result2[j], tmpres2[j] );
+               totallen += nlen;
+#if 0
+               fprintf( stderr, "i=%d", i );
+               fprintf( stderr, "%4d\n", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+       }
+#if KEIKA
+       fprintf( stderr, "DP ... done   \n" );
+#endif
+
+       for( j=0; j<clus1; j++ ) strcpy( seq1[j], result1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( seq2[j], result2[j] );
+#if 0
+       for( j=0; j<clus1; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result1[j] );
+       }
+       fprintf( stderr, "- - - - - - - - - - -\n" );
+       for( j=0; j<clus2; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result2[j] );
+       }
+#endif
+       return( totalscore );
+}
+
+
+
+
+
+
+
+
+/*
+sakujo wo kentou (2010/10/05)
+*/
+float Falign_udpari_long( char  **seq1, char  **seq2, 
+                         double *eff1, double *eff2, 
+                         int    clus1, int    clus2,
+                         int alloclen, int *fftlog )
+{
+       int i, j, k, l, m, maxk;
+       int nlen, nlen2, nlen4;
+       static TLS int prevalloclen = 0;
+       static TLS int crossscoresize = 0;
+       static TLS char **tmpseq1 = NULL;
+       static TLS char **tmpseq2 = NULL;
+       static TLS char **tmpptr1 = NULL;
+       static TLS char **tmpptr2 = NULL;
+       static TLS char **tmpres1 = NULL;
+       static TLS char **tmpres2 = NULL;
+       static TLS char **result1 = NULL;
+       static TLS char **result2 = NULL;
+#if RND
+       static TLS char **rndseq1 = NULL;
+       static TLS char **rndseq2 = NULL;
+#endif
+       static TLS Fukusosuu **seqVector1 = NULL;
+       static TLS Fukusosuu **seqVector2 = NULL;
+       static TLS Fukusosuu **naiseki = NULL;   
+       static TLS Fukusosuu *naisekiNoWa = NULL; 
+       static TLS double *soukan = NULL;
+       static TLS double **crossscore = NULL;
+       int nlentmp;
+       static TLS int *kouho = NULL;
+       static TLS Segment *segment = NULL;
+       static TLS Segment *segment1 = NULL;
+       static TLS Segment *segment2 = NULL;
+       static TLS Segment **sortedseg1 = NULL;
+       static TLS Segment **sortedseg2 = NULL;
+       static TLS int *cut1 = NULL;
+       static TLS int *cut2 = NULL;
+       static TLS char *sgap1, *egap1, *sgap2, *egap2;
+       static TLS int localalloclen = 0;
+       int lag;
+       int tmpint;
+       int count, count0;
+       int len1, len2;
+       int totallen;
+       float totalscore;
+       int nkouho = 0;
+       int headgp, tailgp;
+//     float dumfl = 0.0;
+
+
+
+       len1 = strlen( seq1[0] );
+       len2 = strlen( seq2[0] );
+       nlentmp = MAX( len1, len2 );
+
+       nlen = 1;
+       while( nlentmp >= nlen ) nlen <<= 1;
+#if 0
+       fprintf( stderr, "###   nlen    = %d\n", nlen );
+#endif
+
+       nlen2 = nlen/2; nlen4 = nlen2 / 2;
+
+#if 0
+       fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 );
+       fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen );
+#endif
+
+       if( prevalloclen != alloclen ) // Falign_noudp mo kaeru
+       {
+               if( prevalloclen )
+               {
+                       FreeCharMtx( result1 );
+                       FreeCharMtx( result2 );
+                       FreeCharMtx( tmpres1 );
+                       FreeCharMtx( tmpres2 );
+               }
+//             fprintf( stderr, "\n\n\nreallocating ...\n" ); 
+               result1 = AllocateCharMtx( njob, alloclen );
+               result2 = AllocateCharMtx( njob, alloclen );
+               tmpres1 = AllocateCharMtx( njob, alloclen );
+               tmpres2 = AllocateCharMtx( njob, alloclen );
+               prevalloclen = alloclen;
+       }
+
+       if( !localalloclen )
+       {
+               sgap1 = AllocateCharVec( njob );
+               egap1 = AllocateCharVec( njob );
+               sgap2 = AllocateCharVec( njob );
+               egap2 = AllocateCharVec( njob );
+               kouho = AllocateIntVec( NKOUHO_LONG );
+               cut1 = AllocateIntVec( MAXSEG );
+               cut2 = AllocateIntVec( MAXSEG );
+               tmpptr1 = AllocateCharMtx( njob, 0 );
+               tmpptr2 = AllocateCharMtx( njob, 0 );
+               segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) )
+                       ErrorExit( "Allocation error\n" );
+
+               if     ( scoremtx == -1 ) n20or4or2 = 1;
+               else if( fftscore )       n20or4or2 = 1;
+               else                      n20or4or2 = 20;
+       }
+       if( localalloclen < nlen )
+       {
+               if( localalloclen )
+               {
+#if 1
+                       if( !kobetsubunkatsu )
+                       {
+                               FreeFukusosuuMtx ( seqVector1 );
+                               FreeFukusosuuMtx ( seqVector2 );
+                               FreeFukusosuuVec( naisekiNoWa );
+                               FreeFukusosuuMtx( naiseki );
+                               FreeDoubleVec( soukan );
+                       }
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+#endif
+#if RND
+                       FreeCharMtx( rndseq1 );
+                       FreeCharMtx( rndseq2 );
+#endif
+               }
+
+
+               tmpseq1 = AllocateCharMtx( njob, nlen );
+               tmpseq2 = AllocateCharMtx( njob, nlen );
+               if( !kobetsubunkatsu )
+               {
+                       naisekiNoWa = AllocateFukusosuuVec( nlen );
+                       naiseki = AllocateFukusosuuMtx( n20or4or2, nlen );
+                       seqVector1 = AllocateFukusosuuMtx( n20or4or2, nlen+1 );
+                       seqVector2 = AllocateFukusosuuMtx( n20or4or2, nlen+1 );
+                       soukan = AllocateDoubleVec( nlen+1 );
+               }
+#if RND
+               rndseq1 = AllocateCharMtx( njob, nlen );
+               rndseq2 = AllocateCharMtx( njob, nlen );
+               for( i=0; i<njob; i++ )
+               {
+                       generateRndSeq( rndseq1[i], nlen );
+                       generateRndSeq( rndseq2[i], nlen );
+               }
+#endif
+               localalloclen = nlen;
+       }
+       
+       for( j=0; j<clus1; j++ ) strcpy( tmpseq1[j], seq1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( tmpseq2[j], seq2[j] );
+
+#if 0
+fftfp = fopen( "input_of_Falign", "w" );
+fprintf( fftfp, "nlen = %d\n", nlen );
+fprintf( fftfp, "seq1: ( %d sequences ) \n", clus1 );
+for( i=0; i<clus1; i++ )
+       fprintf( fftfp, "%s\n", seq1[i] );
+fprintf( fftfp, "seq2: ( %d sequences ) \n", clus2 );
+for( i=0; i<clus2; i++ )
+       fprintf( fftfp, "%s\n", seq2[i] );
+fclose( fftfp );
+system( "less input_of_Falign < /dev/tty > /dev/tty" );
+#endif
+       if( !kobetsubunkatsu )
+       {
+               fprintf( stderr,  " FFT ... " );
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector1[j], nlen );
+               if( scoremtx == -1 )
+               {
+                       for( i=0; i<clus1; i++ )
+                               seq_vec_4( seqVector1[0], eff1[i], tmpseq1[i] );
+               }
+               else if( fftscore )
+               {
+                       for( i=0; i<clus1; i++ )
+                       {
+#if 0
+                               seq_vec_2( seqVector1[0], polarity, eff1[i], tmpseq1[i] );
+                               seq_vec_2( seqVector1[1], volume,   eff1[i], tmpseq1[i] );
+#else
+                               seq_vec_5( seqVector1[0], polarity, volume, eff1[i], tmpseq1[i] );
+#endif
+                       }
+               }
+               else
+               {
+                       for( i=0; i<clus1; i++ )
+                               seq_vec_3( seqVector1, eff1[i], tmpseq1[i] );
+               }
+#if RND
+               for( i=0; i<clus1; i++ )
+               {
+                       vec_init2( seqVector1, rndseq1[i], eff1[i], len1, nlen );
+               }
+#endif
+#if 0
+fftfp = fopen( "seqVec", "w" );
+fprintf( fftfp, "before transform\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "nlen=%d\n", nlen );
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector1[k][l].R, seqVector1[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector2[j], nlen );
+               if( scoremtx == -1 )
+               {
+                       for( i=0; i<clus2; i++ )
+                               seq_vec_4( seqVector2[0], eff2[i], tmpseq2[i] );
+               }
+               else if( fftscore )
+               {
+                       for( i=0; i<clus2; i++ )
+                       {
+#if 0
+                               seq_vec_2( seqVector2[0], polarity, eff2[i], tmpseq2[i] );
+                               seq_vec_2( seqVector2[1], volume,   eff2[i], tmpseq2[i] );
+#else
+                               seq_vec_5( seqVector2[0], polarity, volume, eff2[i], tmpseq2[i] );
+#endif
+                       }
+               }
+               else
+               {
+                       for( i=0; i<clus2; i++ )
+                               seq_vec_3( seqVector2, eff2[i], tmpseq2[i] );
+               }
+#if RND
+               for( i=0; i<clus2; i++ )
+               {
+                       vec_init2( seqVector2, rndseq2[i], eff2[i], len2, nlen );
+               }
+#endif
+
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "before fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ )
+               {
+                       fft( nlen, seqVector2[j], 0 );
+                       fft( nlen, seqVector1[j], 0 );
+               }
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "#after fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "#%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+          fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( k=0; k<n20or4or2; k++ ) 
+               {
+                       for( l=0; l<nlen; l++ ) 
+                               calcNaiseki( naiseki[k]+l, seqVector1[k]+l, seqVector2[k]+l );
+               }
+               for( l=0; l<nlen; l++ ) 
+               {
+                       naisekiNoWa[l].R = 0.0;
+                       naisekiNoWa[l].I = 0.0;
+                       for( k=0; k<n20or4or2; k++ ) 
+                       {
+                               naisekiNoWa[l].R += naiseki[k][l].R;
+                               naisekiNoWa[l].I += naiseki[k][l].I;
+                       }
+               }
+       
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#Before fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f %f\n", l, naisekiNoWa[l].R, naisekiNoWa[l].I ); 
+       fclose( fftfp );
+       system( "less naisekiNoWa < /dev/tty > /dev/tty " );
+#endif
+
+               fft( -nlen, naisekiNoWa, 0 );
+       
+               for( m=0; m<=nlen2; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen2-m].R;
+               for( m=nlen2+1; m<nlen; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen+nlen2-m].R;
+
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#After fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f\n", l, naisekiNoWa[l].R ); 
+       fclose( fftfp );
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'naisekiNoWa'\npause -1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot &" );
+#endif
+#if 0
+       fprintf( stderr, "soukan\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( stderr, "%d  %f\n", l-nlen2, soukan[l] ); 
+#if 0
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'frt'\n pause +1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot" );
+#endif
+#endif
+
+
+               nkouho = getKouho( kouho, NKOUHO_LONG, soukan, nlen );
+
+#if 0
+               for( i=0; i<nkouho; i++ )
+               {
+                       fprintf( stderr, "kouho[%d] = %d\n", i, kouho[i] );
+               }
+#endif
+       }
+
+#if KEIKA
+       fprintf( stderr, "Searching anchors ... " );
+#endif
+       count = 0;
+
+
+
+#define CAND 0
+#if CAND
+       fftfp = fopen( "cand", "w" );
+       fclose( fftfp );
+#endif
+       if( kobetsubunkatsu )
+       {
+               maxk = 1;
+               kouho[0] = 0;
+       }
+       else
+       {
+               maxk = nkouho;
+       }
+
+       for( k=0; k<maxk; k++ ) 
+       {
+               lag = kouho[k];
+               if( lag <= -len1 || len2 <= lag ) continue;
+//             fprintf( stderr, "k=%d, lag=%d\n", k, lag );
+               zurasu2( lag, clus1, clus2, seq1, seq2, tmpptr1, tmpptr2 );
+#if CAND
+               fftfp = fopen( "cand", "a" );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr1[0] );
+               fprintf( fftfp, ">Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr2[0] );
+               fprintf( fftfp, ">\n", k+1, lag );
+               fclose( fftfp );
+#endif
+
+//             fprintf( stderr, "lag = %d\n", lag );
+               tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count );
+//             fprintf( stderr, "lag = %d, %d found\n", lag, tmpint );
+
+//             if( lag == -50 ) exit( 1 );
+               
+               if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" );
+
+//             fprintf( stderr, "##### k=%d / %d\n", k, maxk );
+//             if( tmpint == 0 ) break; // 060430 iinoka ? // 090530 yameta
+               while( tmpint-- > 0 )
+               {
+#if 0
+                       if( segment[count].end - segment[count].start < fftWinSize )
+                       {
+                               count++;
+                               continue;
+                       }
+#endif
+                       if( lag > 0 )
+                       {
+                               segment1[count].start  = segment[count].start ;
+                               segment1[count].end    = segment[count].end   ;
+                               segment1[count].center = segment[count].center;
+                               segment1[count].score  = segment[count].score;
+
+                               segment2[count].start  = segment[count].start  + lag;
+                               segment2[count].end    = segment[count].end    + lag;
+                               segment2[count].center = segment[count].center + lag;
+                               segment2[count].score  = segment[count].score       ;
+                       }
+                       else
+                       {
+                               segment1[count].start  = segment[count].start  - lag;
+                               segment1[count].end    = segment[count].end    - lag;
+                               segment1[count].center = segment[count].center - lag;
+                               segment1[count].score  = segment[count].score       ;
+
+                               segment2[count].start  = segment[count].start ;
+                               segment2[count].end    = segment[count].end   ;
+                               segment2[count].center = segment[count].center;
+                               segment2[count].score  = segment[count].score ;
+                       }
+#if 0
+                       fprintf( stderr, "##### k=%d / %d\n", k, maxk );
+                       fprintf( stderr, "anchor %d, score = %f\n", count, segment1[count].score );
+                       fprintf( stderr, "in 1 %d\n", segment1[count].center );
+                       fprintf( stderr, "in 2 %d\n", segment2[count].center );
+#endif
+                       segment1[count].pair = &segment2[count];
+                       segment2[count].pair = &segment1[count];
+                       count++;
+#if 0
+                       fprintf( stderr, "count=%d\n", count );
+#endif
+               }
+       }
+#if 1
+       if( !kobetsubunkatsu )
+               fprintf( stderr, "done. (%d anchors) ", count );
+#endif
+       if( !count && fftNoAnchStop )
+               ErrorExit( "Cannot detect anchor!" );
+#if 0
+       fprintf( stderr, "RESULT before sort:\n" );
+       for( l=0; l<count+1; l++ )
+       {
+               fprintf( stderr, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( stderr, "%d score = %f\n", segment2[l].center, segment1[l].score );
+       }
+#endif
+
+       for( i=0; i<count; i++ )
+       {
+               sortedseg1[i] = &segment1[i];
+               sortedseg2[i] = &segment2[i];
+       }
+#if 0
+       tmpsort( count, sortedseg1 ); 
+       tmpsort( count, sortedseg2 ); 
+       qsort( sortedseg1, count, sizeof( Segment * ), segcmp );
+       qsort( sortedseg2, count, sizeof( Segment * ), segcmp );
+#else
+       mymergesort( 0, count-1, sortedseg1 ); 
+       mymergesort( 0, count-1, sortedseg2 ); 
+#endif
+       for( i=0; i<count; i++ ) sortedseg1[i]->number = i;
+       for( i=0; i<count; i++ ) sortedseg2[i]->number = i;
+
+
+
+       if( kobetsubunkatsu )
+       {
+               for( i=0; i<count; i++ )
+           {
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+               cut1[0] = 0;
+               cut2[0] = 0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+       }
+
+       else
+       {
+               if( count < 5000 )
+               {
+                       if( crossscoresize < count+2 )
+                       {
+                               crossscoresize = count+2;
+#if 1
+                               if( fftkeika ) fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize );
+#endif
+                               if( crossscore ) FreeDoubleMtx( crossscore );
+                               crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+                       }
+                       for( i=0; i<count+2; i++ ) for( j=0; j<count+2; j++ )
+                               crossscore[i][j] = 0.0;
+                       for( i=0; i<count; i++ )
+                       {
+                               crossscore[segment1[i].number+1][segment1[i].pair->number+1] = segment1[i].score;
+                               cut1[i+1] = sortedseg1[i]->center;
+                               cut2[i+1] = sortedseg2[i]->center;
+                       }
+       
+#if 0
+                       fprintf( stderr, "AFTER SORT\n" );
+                       for( i=0; i<count+1; i++ ) fprintf( stderr, "%d, %d\n", cut1[i], cut2[i] );
+                       fprintf( stderr, "crossscore = \n" );
+                       for( i=0; i<count+1; i++ )
+                       {
+                               for( j=0; j<count+1; j++ )
+                                       fprintf( stderr, "%.0f ", crossscore[i][j] );
+                               fprintf( stderr, "\n" );
+                       }
+#endif
+
+                       crossscore[0][0] = 10000000.0;
+                       cut1[0] = 0; 
+                       cut2[0] = 0;
+                       crossscore[count+1][count+1] = 10000000.0;
+                       cut1[count+1] = len1;
+                       cut2[count+1] = len2;
+                       count += 2;
+                       count0 = count;
+               
+//                     fprintf( stderr, "\n\n\ncalling blockAlign2\n\n\n\n" );
+                       blockAlign2( cut1, cut2, sortedseg1, sortedseg2, crossscore, &count );
+       
+//                     if( count-count0 )
+//                             fprintf( stderr, "%d unused anchors\n", count0-count );
+       
+                       if( !kobetsubunkatsu && fftkeika )
+                               fprintf( stderr, "%d anchors found\n", count );
+                       if( fftkeika )
+                       {
+                               if( count0 > count )
+                               {
+#if 0
+                                       fprintf( stderr, "\7 REPEAT!? \n" ); 
+#else
+                                       fprintf( stderr, "REPEAT!? \n" ); 
+#endif
+                                       if( fftRepeatStop ) exit( 1 );
+                               }
+#if KEIKA
+                               else fprintf( stderr, "done\n" );
+#endif
+                       }
+               }
+
+
+               else
+               {
+                       fprintf( stderr, "\nMany anchors were found. The upper-level DP is skipped.\n\n" );
+
+                       cut1[0] = 0; 
+                       cut2[0] = 0;
+                       count0 = 0;
+                       for( i=0; i<count; i++ )
+                       {
+//                             fprintf( stderr, "i=%d, %d-%d ?\n", i, sortedseg1[i]->center, sortedseg1[i]->pair->center );
+                               if( sortedseg1[i]->center > cut1[count0]
+                                && sortedseg1[i]->pair->center > cut2[count0] )
+                               {
+                                       count0++;
+                                       cut1[count0] = sortedseg1[i]->center;
+                                       cut2[count0] = sortedseg1[i]->pair->center;
+                               }
+                               else
+                               {
+                                       if( i && sortedseg1[i]->score > sortedseg1[i-1]->score )
+                                       {
+                                               if( sortedseg1[i]->center > cut1[count0-1]
+                                                && sortedseg1[i]->pair->center > cut2[count0-1] )
+                                               {
+                                                       cut1[count0] = sortedseg1[i]->center;
+                                                       cut2[count0] = sortedseg1[i]->pair->center;
+                                               }
+                                               else
+                                               {
+//                                                     count0--;
+                                               }
+                                       }
+                               }
+                       }
+//                     if( count-count0 )
+//                             fprintf( stderr, "%d anchors unused\n", count-count0 );
+                       cut1[count0+1] = len1;
+                       cut2[count0+1] = len2;
+                       count = count0 + 2;
+                       count0 = count;
+       
+               }
+       }
+
+//     exit( 0 );
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( fftfp, "%d\n", segment2[l].center );
+       }
+       fclose( fftfp );
+#endif
+
+#if 0
+       fprintf( stderr, "RESULT after blckalign:\n" );
+       for( l=0; l<count+1; l++ )
+       {
+               fprintf( stderr, "cut : %d %d\n", cut1[l], cut2[l] );
+       }
+#endif
+
+#if 0
+       fprintf( trap_g, "Devided to %d segments\n", count-1 );
+       fprintf( trap_g, "%d  %d forg\n", MIN( clus1, clus2 ), count-1 );
+#endif
+
+       totallen = 0;
+       for( j=0; j<clus1; j++ ) result1[j][0] = 0;
+       for( j=0; j<clus2; j++ ) result2[j][0] = 0;
+       totalscore = 0.0;
+       *fftlog = -1;
+       for( i=0; i<count-1; i++ )
+       {
+               *fftlog += 1;
+               if( i == 0 ) headgp = outgap; else headgp = 1;
+               if( i == count-2 ) tailgp = outgap; else tailgp = 1;
+
+               if( cut1[i] )
+               {
+//                     getkyokaigap( sgap1, seq1, cut1[i]-1, clus1 );
+//                     getkyokaigap( sgap2, seq2, cut2[i]-1, clus2 );
+                       getkyokaigap( sgap1, tmpres1, nlen-1, clus1 );
+                       getkyokaigap( sgap2, tmpres2, nlen-1, clus2 );
+               }
+               else
+               {
+                       for( j=0; j<clus1; j++ ) sgap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) sgap2[j] = 'o';
+               }
+               if( cut1[i+1] != len1 )
+               {       
+                       getkyokaigap( egap1, seq1, cut1[i+1], clus1 );
+                       getkyokaigap( egap2, seq2, cut2[i+1], clus2 );
+               }       
+               else    
+               {       
+                       for( j=0; j<clus1; j++ ) egap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) egap2[j] = 'o';
+               }
+#if DEBUG
+               fprintf( stderr, "DP %03d / %03d %4d to ", i+1, count-1, totallen );
+#else
+#if 1
+               fprintf( stderr, "DP %05d / %05d \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b", i+1, count-1 );
+#endif
+#endif
+               for( j=0; j<clus1; j++ )
+               {
+                       strncpy( tmpres1[j], seq1[j]+cut1[i], cut1[i+1]-cut1[i] );
+                       tmpres1[j][cut1[i+1]-cut1[i]] = 0;
+               }
+               if( kobetsubunkatsu && fftkeika ) commongappick( clus1, tmpres1 ); //dvtditr \e$B$K8F$P$l$?$H$-\e(B fftkeika=1
+//             if( kobetsubunkatsu ) commongappick( clus1, tmpres1 );
+               for( j=0; j<clus2; j++ )
+               {
+//                     fprintf( stderr, "### cut2[i+1]-cut2[i] = %d\n", cut2[i+1]-cut2[i] );
+                       if( cut2[i+1]-cut2[i] <= 0 )
+                               fprintf( stderr, "### cut2[i+1]=%d, cut2[i]=%d\n", cut2[i+1], cut2[i] );
+                       strncpy( tmpres2[j], seq2[j]+cut2[i], cut2[i+1]-cut2[i] );
+                       tmpres2[j][cut2[i+1]-cut2[i]] = 0;
+               }
+               if( kobetsubunkatsu && fftkeika ) commongappick( clus2, tmpres2 ); //dvtditr \e$B$K8F$P$l$?$H$-\e(B fftkeika=1
+//             if( kobetsubunkatsu ) commongappick( clus2, tmpres2 );
+
+               if( constraint )
+               {
+                       fprintf( stderr, "Not supported\n" );
+                       exit( 1 );
+               }
+#if 0
+               fprintf( stderr, "i=%d, before alignment", i );
+               fprintf( stderr, "%4d\n", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+
+#if 0
+               fprintf( stdout, "writing input\n" );
+               for( j=0; j<clus1; j++ )
+               {
+                       fprintf( stdout, ">%d of GROUP1\n", j );
+                       fprintf( stdout, "%s\n", tmpres1[j] );
+               }
+               for( j=0; j<clus2; j++ )
+               {
+                       fprintf( stdout, ">%d of GROUP2\n", j );
+                       fprintf( stdout, "%s\n", tmpres2[j] );
+               }
+               fflush( stdout );
+#endif
+               switch( alg )
+               {
+                       case( 'M' ):
+                                       totalscore += MSalignmm( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, sgap1, sgap2, egap1, egap2, NULL, 0, NULL, headgp, tailgp );
+                               break;
+                       default:
+                               fprintf( stderr, "alg = %c\n", alg );
+                               ErrorExit( "ERROR IN SOURCE FILE Falign.c" );
+                               break;
+               }
+
+               nlen = strlen( tmpres1[0] );
+               if( totallen + nlen > alloclen )
+               {
+                       fprintf( stderr, "totallen=%d +  nlen=%d > alloclen = %d\n", totallen, nlen, alloclen );
+                       ErrorExit( "LENGTH OVER in Falign\n " );
+               }
+               for( j=0; j<clus1; j++ ) strcat( result1[j], tmpres1[j] );
+               for( j=0; j<clus2; j++ ) strcat( result2[j], tmpres2[j] );
+               totallen += nlen;
+#if 0
+               fprintf( stderr, "i=%d", i );
+               fprintf( stderr, "%4d\n", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+       }
+#if KEIKA
+       fprintf( stderr, "DP ... done   \n" );
+#endif
+
+       for( j=0; j<clus1; j++ ) strcpy( seq1[j], result1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( seq2[j], result2[j] );
+#if 0
+       for( j=0; j<clus1; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result1[j] );
+       }
+       fprintf( stderr, "- - - - - - - - - - -\n" );
+       for( j=0; j<clus2; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result2[j] );
+       }
+#endif
+       return( totalscore );
+}
diff --git a/binaries/src/mafft/core/Falign_localhom.c b/binaries/src/mafft/core/Falign_localhom.c
new file mode 100644 (file)
index 0000000..ba2dee3
--- /dev/null
@@ -0,0 +1,871 @@
+#include "mltaln.h"
+
+//static FILE *fftfp;
+static TLS int n20or4or2;
+
+#define KEIKA 0
+#define RND   0
+#define DEBUG 0
+
+extern int fft( int, Fukusosuu *, int );
+
+
+#if 0
+static void generateRndSeq( char *seq, int len )
+{
+       while( len-- )
+#if 1
+               *seq++ = (int)( rnd() * n20or4or2 );
+#else
+               *seq++ = (int)1;
+#endif
+}
+#endif
+
+static void vec_init( Fukusosuu *result, int nlen )
+{
+       while( nlen-- )
+       {
+               result->R = result->I = 0.0;
+               result++;
+       }
+}
+
+#if 0
+static void vec_init2( Fukusosuu **result, char *seq, double eff, int st, int ed )
+{
+       int i;
+       for( i=st; i<ed; i++ )
+               result[(int)*seq++][i].R += eff;
+}
+#endif
+
+static void seq_vec_2( Fukusosuu *result, double *score, double incr, char *seq )
+{
+       static TLS int n;
+       for( ; *seq; result++ )
+       {
+               n = amino_n[(int)*seq++];
+               if( n < 20 && n >= 0 ) result->R += incr * score[n];
+#if 0
+               fprintf( stderr, "n=%d, score=%f, inc=%f R=%f\n",n,  score[n], incr * score[n], result->R );
+#endif
+       }
+}
+
+static void seq_vec_3( Fukusosuu **result, double incr, char *seq )
+{
+       int i;
+       int n;
+       for( i=0; *seq; i++ )
+       {
+               n = amino_n[(int)*seq++];
+               if( n < n20or4or2 && n >= 0 ) result[n][i].R += incr;
+       }
+}
+
+       
+#if 0
+static void seq_vec( Fukusosuu *result, char query, double incr, char *seq )
+{
+#if 0
+       int bk = nlen;
+#endif
+       while( *seq )
+       {
+               if( *seq++ == query ) result->R += incr;
+               result++;
+#if 0
+fprintf( stderr, "i = %d result->R = %f\n", bk-nlen, (result-1)->R );
+#endif
+       }
+}
+
+static int checkRepeat( int num, int *cutpos )
+{
+       int tmp, buf;
+
+       buf = *cutpos;
+       while( num-- )
+       {
+               if( ( tmp = *cutpos++ ) < buf ) return( 1 );
+               buf = tmp;
+       }
+       return( 0 );
+}
+
+static int segcmp( void *ptr1, void *ptr2 )
+{
+       int diff;
+       Segment **seg1 = (Segment **)ptr1;
+       Segment **seg2 = (Segment **)ptr2;
+#if 0
+       return( (*seg1)->center - (*seg2)->center );
+#else
+       diff = (*seg1)->center - (*seg2)->center;
+       if( diff ) return( diff );
+
+       diff = (*seg1)->start - (*seg2)->start;
+       if( diff ) return( diff );
+
+       diff = (*seg1)->end - (*seg2)->end;
+       if( diff ) return( diff );
+
+       fprintf( stderr, "USE STABLE SORT !!\n" );
+       exit( 1 );
+       return( 0 );
+#endif
+}
+
+#endif
+
+
+static void mymergesort( int first, int last, Segment **seg )
+{
+       int middle;
+       static TLS int i, j, k, p;
+       static TLS int allo = 0;
+       static TLS Segment **work = NULL;
+
+       if( seg == NULL )
+       {
+               free( work ); work = NULL;
+               return;
+       }
+
+       if( last > allo )
+       {
+               allo = last;
+               if( work ) free( work );
+               work = (Segment **)calloc( allo / 2 + 1, sizeof( Segment *) );
+       }
+
+       if( first < last )
+       {
+               middle = ( first + last ) / 2;
+               mymergesort( first, middle, seg );
+               mymergesort( middle+1, last, seg );
+               p = 0;
+               for( i=first; i<=middle; i++ ) work[p++] = seg[i];
+               i = middle + 1; j = 0; k = first;
+               while( i <= last && j < p )
+               {
+                       if( work[j]->center <= seg[i]->center ) 
+                               seg[k++] = work[j++];
+                       else
+                               seg[k++] = seg[i++];
+               }
+               while( j < p ) seg[k++] = work[j++];
+       }
+}
+
+
+float Falign_localhom( char  **seq1, char  **seq2, 
+                         double *eff1, double *eff2, 
+                         int    clus1, int    clus2,
+                         int alloclen, 
+                          LocalHom ***localhom, float *totalimpmatch,
+                          int *gapmap1, int *gapmap2,
+                               int *chudanpt, int chudanref, int *chudanres )
+{
+   // tditeration.c deha alloclen ha huhen nanode
+   // prevalloclen ha iranai.
+       int i, j, k, l, m, maxk;
+       int nlen, nlen2, nlen4;
+       static TLS int crossscoresize = 0;
+       static TLS char **tmpseq1 = NULL;
+       static TLS char **tmpseq2 = NULL;
+       static TLS char **tmpptr1 = NULL;
+       static TLS char **tmpptr2 = NULL;
+       static TLS char **tmpres1 = NULL;
+       static TLS char **tmpres2 = NULL;
+       static TLS char **result1 = NULL;
+       static TLS char **result2 = NULL;
+#if RND
+       static TLS char **rndseq1 = NULL;
+       static TLS char **rndseq2 = NULL;
+#endif
+       static TLS Fukusosuu **seqVector1 = NULL;
+       static TLS Fukusosuu **seqVector2 = NULL;
+       static TLS Fukusosuu **naiseki = NULL;   
+       static TLS Fukusosuu *naisekiNoWa = NULL; 
+       static TLS double *soukan = NULL;
+       static TLS double **crossscore = NULL;
+       int nlentmp;
+       static TLS int *kouho = NULL;
+       static TLS Segment *segment = NULL;
+       static TLS Segment *segment1 = NULL;
+       static TLS Segment *segment2 = NULL;
+       static TLS Segment **sortedseg1 = NULL;
+       static TLS Segment **sortedseg2 = NULL;
+       static TLS int *cut1 = NULL;
+       static TLS int *cut2 = NULL;
+       static TLS char *sgap1, *egap1, *sgap2, *egap2;
+       static TLS int localalloclen = 0;
+       int lag;
+       int tmpint;
+       int count, count0;
+       int len1, len2;
+       int totallen;
+       float totalscore;
+       float impmatch;
+
+       extern Fukusosuu   *AllocateFukusosuuVec();
+       extern Fukusosuu  **AllocateFukusosuuMtx();
+
+       if( seq1 == NULL )
+       {
+               if( result1 ) 
+               {
+//                     fprintf( stderr, "Freeing localarrays in Falign\n" );
+                       localalloclen = 0;
+                       mymergesort( 0, 0, NULL );
+                       alignableReagion( 0, 0, NULL, NULL, NULL, NULL, NULL );
+                       fft( 0, NULL, 1 );
+                       A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 );
+                       G__align11( NULL, NULL, 0, 0, 0 );
+                       partA__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL );
+                       blockAlign2( NULL, NULL, NULL, NULL, NULL, NULL );
+                       if( crossscore ) FreeDoubleMtx( crossscore );
+                       FreeCharMtx( result1 );
+                       FreeCharMtx( result2 );
+                       FreeCharMtx( tmpres1 );
+                       FreeCharMtx( tmpres2 );
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+                       free( sgap1 );
+                       free( egap1 );
+                       free( sgap2 );
+                       free( egap2 );
+                       free( kouho );
+                       free( cut1 );
+                       free( cut2 );
+                       free( tmpptr1 );
+                       free( tmpptr2 );
+                       free( segment );
+                       free( segment1 );
+                       free( segment2 );
+                       free( sortedseg1 );
+                       free( sortedseg2 );
+                       if( !kobetsubunkatsu )
+                       {
+                               FreeFukusosuuMtx ( seqVector1 );
+                               FreeFukusosuuMtx ( seqVector2 );
+                               FreeFukusosuuVec( naisekiNoWa );
+                               FreeFukusosuuMtx( naiseki );
+                               FreeDoubleVec( soukan );
+                       }
+               }
+               else
+               {
+//                     fprintf( stderr, "Did not allocate localarrays in Falign\n" );
+               }
+
+               return( 0.0 );
+       }
+
+       len1 = strlen( seq1[0] );
+       len2 = strlen( seq2[0] );
+       nlentmp = MAX( len1, len2 );
+
+       nlen = 1;
+       while( nlentmp >= nlen ) nlen <<= 1;
+#if 0
+       fprintf( stderr, "###   nlen    = %d\n", nlen );
+#endif
+
+       nlen2 = nlen/2; nlen4 = nlen2 / 2;
+
+#if DEBUG
+       fprintf( stderr, "len1 = %d, len2 = %d\n", len1, len2 );
+       fprintf( stderr, "nlentmp = %d, nlen = %d\n", nlentmp, nlen );
+#endif
+
+       if( !localalloclen )
+       {
+               sgap1 = AllocateCharVec( njob ); 
+               egap1 = AllocateCharVec( njob ); 
+               sgap2 = AllocateCharVec( njob ); 
+               egap2 = AllocateCharVec( njob ); 
+               kouho = AllocateIntVec( NKOUHO );
+               cut1 = AllocateIntVec( MAXSEG );
+               cut2 = AllocateIntVec( MAXSEG );
+               tmpptr1 = AllocateCharMtx( njob, 0 );
+               tmpptr2 = AllocateCharMtx( njob, 0 );
+               result1 = AllocateCharMtx( njob, alloclen );
+               result2 = AllocateCharMtx( njob, alloclen );
+               tmpres1 = AllocateCharMtx( njob, alloclen );
+               tmpres2 = AllocateCharMtx( njob, alloclen );
+//             crossscore = AllocateDoubleMtx( MAXSEG, MAXSEG );
+               segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment1 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               segment2 = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+               sortedseg1 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               sortedseg2 = (Segment **)calloc( MAXSEG, sizeof( Segment * ) );
+               if( !( segment && segment1 && segment2 && sortedseg1 && sortedseg2 ) )
+                       ErrorExit( "Allocation error\n" );
+
+               if     ( scoremtx == -1 ) n20or4or2 = 4;
+               else if( fftscore == 1  ) n20or4or2 = 2;
+               else                      n20or4or2 = 20;
+       }
+       if( localalloclen < nlen )
+       {
+               if( localalloclen )
+               {
+#if 1
+                       if( !kobetsubunkatsu )
+                       {
+                               FreeFukusosuuMtx ( seqVector1 );
+                               FreeFukusosuuMtx ( seqVector2 );
+                               FreeFukusosuuVec( naisekiNoWa );
+                               FreeFukusosuuMtx( naiseki );
+                               FreeDoubleVec( soukan );
+                       }
+                       FreeCharMtx( tmpseq1 );
+                       FreeCharMtx( tmpseq2 );
+#endif
+#if RND
+                       FreeCharMtx( rndseq1 );
+                       FreeCharMtx( rndseq2 );
+#endif
+               }
+
+               tmpseq1 = AllocateCharMtx( njob, nlen );
+               tmpseq2 = AllocateCharMtx( njob, nlen );
+               if( !kobetsubunkatsu )
+               {
+                       naisekiNoWa = AllocateFukusosuuVec( nlen );
+                       naiseki = AllocateFukusosuuMtx( n20or4or2, nlen );
+                       seqVector1 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+                       seqVector2 = AllocateFukusosuuMtx( n20or4or2+1, nlen+1 );
+                       soukan = AllocateDoubleVec( nlen+1 );
+               }
+#if RND
+               rndseq1 = AllocateCharMtx( njob, nlen );
+               rndseq2 = AllocateCharMtx( njob, nlen );
+               for( i=0; i<njob; i++ )
+               {
+                       generateRndSeq( rndseq1[i], nlen );
+                       generateRndSeq( rndseq2[i], nlen );
+               }
+#endif
+               localalloclen = nlen;
+       }
+       
+       for( j=0; j<clus1; j++ ) strcpy( tmpseq1[j], seq1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( tmpseq2[j], seq2[j] );
+
+#if 0
+fftfp = fopen( "input_of_Falign", "w" );
+fprintf( fftfp, "nlen = %d\n", nlen );
+fprintf( fftfp, "seq1: ( %d sequences ) \n", clus1 );
+for( i=0; i<clus1; i++ )
+       fprintf( fftfp, "%s\n", seq1[i] );
+fprintf( fftfp, "seq2: ( %d sequences ) \n", clus2 );
+for( i=0; i<clus2; i++ )
+       fprintf( fftfp, "%s\n", seq2[i] );
+fclose( fftfp );
+system( "less input_of_Falign < /dev/tty > /dev/tty" );
+#endif
+       if( !kobetsubunkatsu )
+       {
+               fprintf( stderr,  "FFT ... " );
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector1[j], nlen );
+               if( fftscore && scoremtx != -1 )
+               {
+                       for( i=0; i<clus1; i++ )
+                       {
+                               seq_vec_2( seqVector1[0], polarity, eff1[i], tmpseq1[i] );
+                               seq_vec_2( seqVector1[1], volume,   eff1[i], tmpseq1[i] );
+                       }
+               }
+               else
+               {
+#if 0
+                       for( i=0; i<clus1; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                               seq_vec( seqVector1[j], amino[j], eff1[i], tmpseq1[i] );
+#else
+                       for( i=0; i<clus1; i++ )
+                               seq_vec_3( seqVector1, eff1[i], tmpseq1[i] );
+#endif
+               }
+#if RND
+               for( i=0; i<clus1; i++ )
+               {
+                       vec_init2( seqVector1, rndseq1[i], eff1[i], len1, nlen );
+               }
+#endif
+#if 0
+fftfp = fopen( "seqVec", "w" );
+fprintf( fftfp, "before transform\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "nlen=%d\n", nlen );
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector1[k][l].R, seqVector1[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ ) vec_init( seqVector2[j], nlen );
+               if( fftscore && scoremtx != -1 )
+               {
+                       for( i=0; i<clus2; i++ )
+                       {
+                               seq_vec_2( seqVector2[0], polarity, eff2[i], tmpseq2[i] );
+                               seq_vec_2( seqVector2[1], volume,   eff2[i], tmpseq2[i] );
+                       }
+               }
+               else
+               {
+#if 0
+                       for( i=0; i<clus2; i++ ) for( j=0; j<n20or4or2; j++ ) 
+                               seq_vec( seqVector2[j], amino[j], eff2[i], tmpseq2[i] );
+#else
+                       for( i=0; i<clus2; i++ )
+                               seq_vec_3( seqVector2, eff2[i], tmpseq2[i] );
+#endif
+               }
+#if RND
+               for( i=0; i<clus2; i++ )
+               {
+                       vec_init2( seqVector2, rndseq2[i], eff2[i], len2, nlen );
+               }
+#endif
+
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "before fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+   fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( j=0; j<n20or4or2; j++ )
+               {
+                       fft( nlen, seqVector2[j], (j==0) );
+                       fft( nlen, seqVector1[j], 0 );
+               }
+#if 0
+fftfp = fopen( "seqVec2", "w" );
+fprintf( fftfp, "#after fft\n" );
+for( k=0; k<n20or4or2; k++ ) 
+{
+   fprintf( fftfp, "#%c\n", amino[k] );
+   for( l=0; l<nlen; l++ )
+          fprintf( fftfp, "%f %f\n", seqVector2[k][l].R, seqVector2[k][l].I );
+}
+fclose( fftfp );
+system( "less seqVec2 < /dev/tty > /dev/tty" );
+#endif
+
+               for( k=0; k<n20or4or2; k++ ) 
+               {
+                       for( l=0; l<nlen; l++ ) 
+                               calcNaiseki( naiseki[k]+l, seqVector1[k]+l, seqVector2[k]+l );
+               }
+               for( l=0; l<nlen; l++ ) 
+               {
+                       naisekiNoWa[l].R = 0.0;
+                       naisekiNoWa[l].I = 0.0;
+                       for( k=0; k<n20or4or2; k++ ) 
+                       {
+                               naisekiNoWa[l].R += naiseki[k][l].R;
+                               naisekiNoWa[l].I += naiseki[k][l].I;
+                       }
+               }
+       
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#Before fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f %f\n", l, naisekiNoWa[l].R, naisekiNoWa[l].I ); 
+       fclose( fftfp );
+       system( "less naisekiNoWa < /dev/tty > /dev/tty " );
+#endif
+
+               fft( -nlen, naisekiNoWa, 0 );
+       
+               for( m=0; m<=nlen2; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen2-m].R;
+               for( m=nlen2+1; m<nlen; m++ ) 
+                       soukan[m] = naisekiNoWa[nlen+nlen2-m].R;
+
+#if 0
+       fftfp = fopen( "naisekiNoWa", "w" );
+       fprintf( fftfp, "#After fft\n" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f\n", l, naisekiNoWa[l].R ); 
+       fclose( fftfp );
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'naisekiNoWa'\npause -1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot &" );
+#endif
+#if 0
+       fprintf( stderr, "frt write start\n" );
+       fftfp = fopen( "frt", "w" );
+       for( l=0; l<nlen; l++ )
+               fprintf( fftfp, "%d  %f\n", l-nlen2, soukan[l] ); 
+       fclose( fftfp );
+       system( "less frt < /dev/tty > /dev/tty" );
+#if 0
+       fftfp = fopen( "list.plot", "w"  );
+       fprintf( fftfp, "plot 'frt'\n pause +1" );
+       fclose( fftfp );
+       system( "/usr/bin/gnuplot list.plot" );
+#endif
+#endif
+
+
+               getKouho( kouho, NKOUHO, soukan, nlen );
+
+#if 0
+               for( i=0; i<NKOUHO; i++ )
+               {
+                       fprintf( stderr, "kouho[%d] = %d\n", i, kouho[i] );
+               }
+#endif
+       }
+
+#if KEIKA
+       fprintf( stderr, "Searching anchors ... " );
+#endif
+       count = 0;
+
+
+
+#define CAND 0
+#if CAND
+       fftfp = fopen( "cand", "w" );
+       fclose( fftfp );
+#endif
+       if( kobetsubunkatsu )
+       {
+               maxk = 1;
+               kouho[0] = 0;
+       }
+       else
+       {
+               maxk = NKOUHO;
+       }
+
+       for( k=0; k<maxk; k++ ) 
+       {
+               lag = kouho[k];
+               zurasu2( lag, clus1, clus2, seq1, seq2, tmpptr1, tmpptr2 );
+#if CAND
+               fftfp = fopen( "cand", "a" );
+               fprintf( fftfp, "Candidate No.%d lag = %d\n", k+1, lag );
+               fprintf( fftfp, "%s\n", tmpptr1[0] );
+               fprintf( fftfp, "%s\n", tmpptr2[0] );
+               fclose( fftfp );
+#endif
+               tmpint = alignableReagion( clus1, clus2, tmpptr1, tmpptr2, eff1, eff2, segment+count );
+               
+               if( count+tmpint > MAXSEG -3 ) ErrorExit( "TOO MANY SEGMENTS.\n" );
+
+
+               while( tmpint-- > 0 )
+               {
+                       if( lag > 0 )
+                       {
+                               segment1[count].start  = segment[count].start ;
+                               segment1[count].end    = segment[count].end   ;
+                               segment1[count].center = segment[count].center;
+                               segment1[count].score  = segment[count].score;
+
+                               segment2[count].start  = segment[count].start  + lag;
+                               segment2[count].end    = segment[count].end    + lag;
+                               segment2[count].center = segment[count].center + lag;
+                               segment2[count].score  = segment[count].score       ;
+                       }
+                       else
+                       {
+                               segment1[count].start  = segment[count].start  - lag;
+                               segment1[count].end    = segment[count].end    - lag;
+                               segment1[count].center = segment[count].center - lag;
+                               segment1[count].score  = segment[count].score       ;
+
+                               segment2[count].start  = segment[count].start ;
+                               segment2[count].end    = segment[count].end   ;
+                               segment2[count].center = segment[count].center;
+                               segment2[count].score  = segment[count].score ;
+                       }
+#if 0
+                       fftfp = fopen( "cand", "a" );
+                       fprintf( fftfp, "Goukaku=%dko\n", tmpint ); 
+                       fprintf( fftfp, "in 1 %d\n", segment1[count].center );
+                       fprintf( fftfp, "in 2 %d\n", segment2[count].center );
+                       fclose( fftfp );
+#endif
+                       segment1[count].pair = &segment2[count];
+                       segment2[count].pair = &segment1[count];
+                       count++;
+#if 0
+                       fprintf( stderr, "count=%d\n", count );
+#endif
+               }
+       }
+#if 1
+       if( !kobetsubunkatsu )
+               fprintf( stderr, "%d segments found\n", count );
+#endif
+       if( !count && fftNoAnchStop )
+               ErrorExit( "Cannot detect anchor!" );
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT before sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( fftfp, "%d score = %f\n", segment2[l].center, segment1[l].score );
+       }
+       fclose( fftfp );
+#endif
+
+#if KEIKA
+       fprintf( stderr, "Aligning anchors ... " );
+#endif
+       for( i=0; i<count; i++ )
+       {
+               sortedseg1[i] = &segment1[i];
+               sortedseg2[i] = &segment2[i];
+       }
+#if 0
+       tmpsort( count, sortedseg1 ); 
+       tmpsort( count, sortedseg2 ); 
+       qsort( sortedseg1, count, sizeof( Segment * ), segcmp );
+       qsort( sortedseg2, count, sizeof( Segment * ), segcmp );
+#else
+       mymergesort( 0, count-1, sortedseg1 ); 
+       mymergesort( 0, count-1, sortedseg2 ); 
+#endif
+       for( i=0; i<count; i++ ) sortedseg1[i]->number = i;
+       for( i=0; i<count; i++ ) sortedseg2[i]->number = i;
+
+
+       if( kobetsubunkatsu )
+       {
+               for( i=0; i<count; i++ )
+           {
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+               cut1[0] = 0;
+               cut2[0] = 0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+       }
+       else
+       {
+               if( crossscoresize < count+2 )
+               {
+                       crossscoresize = count+2;
+#if 1
+                       fprintf( stderr, "######allocating crossscore, size = %d\n", crossscoresize );
+#endif
+                       if( crossscore ) FreeDoubleMtx( crossscore );
+                       crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+               }
+               for( i=0; i<count+2; i++ ) for( j=0; j<count+2; j++ )
+                       crossscore[i][j] = 0.0;
+               for( i=0; i<count; i++ )
+               {
+                       crossscore[segment1[i].number+1][segment1[i].pair->number+1] = segment1[i].score;
+                       cut1[i+1] = sortedseg1[i]->center;
+                       cut2[i+1] = sortedseg2[i]->center;
+               }
+
+#if DEBUG
+               fprintf( stderr, "AFTER SORT\n" );
+               for( i=0; i<count; i++ ) fprintf( stderr, "%d, %d\n", segment1[i].start, segment2[i].start );
+#endif
+
+               crossscore[0][0] = 10000000.0;
+               cut1[0] = 0; 
+               cut2[0] = 0;
+               crossscore[count+1][count+1] = 10000000.0;
+               cut1[count+1] = len1;
+               cut2[count+1] = len2;
+               count += 2;
+               count0 = count;
+       
+               blockAlign2( cut1, cut2, sortedseg1, sortedseg2, crossscore, &count );
+               if( count0 > count )
+               {
+#if 0
+                       fprintf( stderr, "\7 REPEAT!? \n" ); 
+#else
+                       fprintf( stderr, "REPEAT!? \n" ); 
+#endif
+                       if( fftRepeatStop ) exit( 1 );
+               }
+#if KEIKA
+               else fprintf( stderr, "done\n" );
+#endif
+       }
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut[%d]=%d, ", l, segment1[l].center );
+               fprintf( fftfp, "%d\n", segment2[l].center );
+       }
+       fclose( fftfp );
+#endif
+
+#if 0
+       fftfp = fopen( "fft", "a" );
+       fprintf( fftfp, "RESULT after sort:\n" );
+       for( l=0; l<count; l++ )
+       {
+               fprintf( fftfp, "cut : %d %d\n", cut1[l], cut2[l] );
+       }
+       fclose( fftfp );
+#endif
+
+#if KEIKA
+       fprintf( trap_g, "Devided to %d segments\n", count-1 );
+       fprintf( trap_g, "%d  %d forg\n", MIN( clus1, clus2 ), count-1 );
+#endif
+
+       totallen = 0;
+       for( j=0; j<clus1; j++ ) result1[j][0] = 0;
+       for( j=0; j<clus2; j++ ) result2[j][0] = 0;
+       totalscore = 0.0;
+       *totalimpmatch = 0.0;
+       for( i=0; i<count-1; i++ )
+       {
+#if DEBUG
+               fprintf( stderr, "DP %03d / %03d %4d to ", i+1, count-1, totallen );
+#else
+#if KEIKA
+               fprintf( stderr, "DP %03d / %03d\r", i+1, count-1 );
+#endif
+#endif
+
+               if( cut1[i] ) 
+               {
+                       getkyokaigap( sgap1, seq1, cut1[i]-1, clus1 );
+                       getkyokaigap( sgap2, seq2, cut2[i]-1, clus2 );
+               }
+               else
+               {
+                       for( j=0; j<clus1; j++ ) sgap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) sgap2[j] = 'o';
+               }
+               if( cut1[i+1] != len1 )
+               {
+                       getkyokaigap( egap1, seq1, cut1[i+1], clus1 );
+                       getkyokaigap( egap2, seq2, cut2[i+1], clus2 );
+               }
+               else
+               {
+                       for( j=0; j<clus1; j++ ) egap1[j] = 'o';
+                       for( j=0; j<clus2; j++ ) egap2[j] = 'o';
+               }
+
+               for( j=0; j<clus1; j++ )
+               {
+                       strncpy( tmpres1[j], seq1[j]+cut1[i], cut1[i+1]-cut1[i] );
+                       tmpres1[j][cut1[i+1]-cut1[i]] = 0;
+               }
+               if( kobetsubunkatsu ) commongappick_record( clus1, tmpres1, gapmap1 );
+               for( j=0; j<clus2; j++ )
+               {
+                       strncpy( tmpres2[j], seq2[j]+cut2[i], cut2[i+1]-cut2[i] );
+                       tmpres2[j][cut2[i+1]-cut2[i]] = 0;
+               }
+               if( kobetsubunkatsu ) commongappick_record( clus2, tmpres2, gapmap2 );
+
+#if 0
+               fprintf( stderr, "count = %d\n", count );
+               fprintf( stderr, "### reg1 = %d-%d\n", cut1[i], cut1[i+1]-1 );
+               fprintf( stderr, "### reg2 = %d-%d\n", cut2[i], cut2[i+1]-1 );
+#endif
+
+               switch( alg )
+               {
+                       case( 'a' ):
+                               totalscore += Aalign( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen );
+                               break;
+                       case( 'Q' ):
+                               totalscore += partQ__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2 );
+                               *totalimpmatch += impmatch;
+//                             fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch );
+                               break;
+                       case( 'A' ):
+                               totalscore += partA__align( tmpres1, tmpres2, eff1, eff2, clus1, clus2, alloclen, localhom, &impmatch, cut1[i], cut1[i+1]-1, cut2[i], cut2[i+1]-1, gapmap1, gapmap2, sgap1, sgap2, egap1, egap2, chudanpt, chudanref, chudanres );
+                               *totalimpmatch += impmatch;
+//                             fprintf( stderr, "*totalimpmatch in Falign_localhom = %f\n", *totalimpmatch );
+
+
+                               break;
+                       default:
+                               fprintf( stderr, "alg = %c\n", alg );
+                               ErrorExit( "ERROR IN SOURCE FILE Falign.c" );
+                               break;
+               }
+#ifdef enablemultithread
+               if( chudanres && *chudanres )
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! at Falign_localhom\n" );
+                       return( -1.0 );
+               }
+#endif
+
+               nlen = strlen( tmpres1[0] );
+               if( totallen + nlen > alloclen )
+               {
+                       fprintf( stderr, "totallen=%d +  nlen=%d > alloclen = %d\n", totallen, nlen, alloclen );
+                       ErrorExit( "LENGTH OVER in Falign\n " );
+               }
+               for( j=0; j<clus1; j++ ) strcat( result1[j], tmpres1[j] );
+               for( j=0; j<clus2; j++ ) strcat( result2[j], tmpres2[j] );
+               totallen += nlen;
+#if 0
+               fprintf( stderr, "%4d\r", totallen );
+               fprintf( stderr, "\n\n" );
+               for( j=0; j<clus1; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres1[j] );
+               }
+               fprintf( stderr, "-------\n" );
+               for( j=0; j<clus2; j++ ) 
+               {
+                       fprintf( stderr, "%s\n", tmpres2[j] );
+               }
+#endif
+       }
+#if KEIKA
+       fprintf( stderr, "DP ... done   \n" );
+#endif
+
+       for( j=0; j<clus1; j++ ) strcpy( seq1[j], result1[j] );
+       for( j=0; j<clus2; j++ ) strcpy( seq2[j], result2[j] );
+#if 0
+       for( j=0; j<clus1; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result1[j] );
+       }
+       fprintf( stderr, "- - - - - - - - - - -\n" );
+       for( j=0; j<clus2; j++ ) 
+       {
+               fprintf( stderr, "%s\n", result2[j] );
+       }
+#endif
+       return( totalscore );
+}
diff --git a/binaries/src/mafft/core/Galign11.c b/binaries/src/mafft/core/Galign11.c
new file mode 100644 (file)
index 0000000..2ee7ce0
--- /dev/null
@@ -0,0 +1,758 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr = amino_dis[(int)s1[0][i1]];
+
+       while( lgth2-- )
+               *match++ = intptr[(int)*seq2++];
+}
+static void match_calc_mtx( int mtx[0x80][0x80], float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr = mtx[(int)s1[0][i1]];
+
+       while( lgth2-- )
+               *match++ = intptr[(int)*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        int **ijp,
+                                               int tailgp )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       float wm;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       if( tailgp == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+
+
+       iin = lgth1; jin = lgth2;
+       limk = lgth1+lgth2 + 1;
+       for( k=0; k<limk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+
+float G__align11( char **seq1, char **seq2, int alloclen, int headgp, int tailgp )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+                       free( mseq1 );
+                       free( mseq2 );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+               return( 0.0 );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 <= 0 || lgth2 <= 0 )
+       {
+               fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+
+#if 1
+       if( lgth1 == 0 && lgth2 == 0 )
+               return( 0.0 );
+
+       if( lgth1 == 0 )
+       {
+               seq1[0][lgth2] = 0;
+               while( lgth2 ) seq1[0][--lgth2] = '-';
+//             fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               return( 0.0 );
+       }
+
+       if( lgth2 == 0 )
+       {
+               seq2[0][lgth1] = 0;
+               while( lgth1 ) seq2[0][--lgth1] = '-';
+//             fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
+               return( 0.0 );
+       }
+#endif
+
+
+       wm = 0.0;
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+       if( headgp == 1 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += fpenalty;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += fpenalty;
+               }
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+       }
+
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0;               // lgth2==0 no toki error
+       else
+               lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
+
+       if( tailgp ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( (g=*prept) >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt + fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( (g=*prept) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
+       }
+
+       Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, tailgp );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+#if 0
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+       fprintf( stderr, "wm = %f\n", wm );
+#endif
+
+       return( wm );
+}
+
+float G__align11_noalign( int scoremtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+//     int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penal;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penal_ex;
+#endif
+#if 1
+       float *wtmp;
+       float *mjpt, *prept, *curpt;
+//     int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+                       free( m );
+
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+               return( 0.0 );
+       }
+
+       wm = 0.0;
+
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+
+
+       if( lgth1 <= 0 || lgth2 <= 0 )
+       {
+               fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+
+
+
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+
+
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+
+
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc_mtx( scoremtx, initverticalw, seq2, seq1, 0, lgth1 );
+
+
+       match_calc_mtx( scoremtx, currentw, seq1, seq2, 0, lgth2 );
+
+       if( 1 ) // tsuneni outgap-1
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += fpenalty;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += fpenalty;
+               }
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1];
+       }
+
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0;               // lgth2==0 no toki error
+       else
+               lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
+
+       if( 1 ) lasti = lgth1+1; else lasti = lgth1; // tsuneni outgap-1
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc_mtx( scoremtx, currentw, seq1, seq2, i, lgth2 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0];
+
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+                       }
+                       if( (g=*prept) >= mi )
+                       {
+                               mi = g;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt + fpenalty) > wm )
+                       {
+                               wm = g;
+                       }
+                       if( (g=*prept) >= *mjpt )
+                       {
+                               *mjpt = g;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       mjpt++;
+                       prept++;
+               }
+               lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
+       }
+
+#if 0
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+       fprintf( stderr, "wm = %f\n", wm );
+#endif
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/Halignmm.c b/binaries/src/mafft/core/Halignmm.c
new file mode 100644 (file)
index 0000000..bec9de2
--- /dev/null
@@ -0,0 +1,1419 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 1
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+static TLS float **impmtx = NULL;
+
+#if 0 // by D.Mathog
+static float countnocountxx( Gappat *pat1, float diaf1, Gappat *pat2, int offset1, int offset2 )
+{
+//     return( 0.0 );
+       float gclose;
+       float gmatch;
+       Gappat *pat1bk = pat1;
+       Gappat *pat2bk = pat2;
+
+       gmatch = 0.0;
+       for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0
+       {
+               if( pat2->len + offset2 == offset1 )
+               {
+                       gmatch = diaf1 * pat2->freq;
+               }
+       }
+       for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) // excl. len=0
+       {
+               for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0
+               {
+                       if( pat1->len + offset1 == pat2->len + offset2 )
+                       {
+                               gmatch += pat1->freq * pat2->freq;
+//                             if( r ) fprintf( stderr, "match1!!, len=%d, gmatch=%f * %f\n", pat2->len, pat1->freq, pat2->freq );
+                       }
+               }
+       }
+       return( gmatch );
+}
+#endif
+
+static float countnocountmatchx( Gappat *pat1, Gappat *pat2, int offset1, int offset2, int r )
+{
+       Gappat *pat1bk = pat1;
+       Gappat *pat2bk = pat2;
+       float val = 0.0;
+       // pat1[][0] ha total gap.
+       for( pat1=pat1bk+1; pat1->len != 0; pat1++ )
+       {
+               for( pat2=pat2bk+1; pat2->len != 0; pat2++ )
+               {
+                       if( pat1->len + offset1 == pat2->len + offset2 )
+                       {
+                               val += pat1->freq * pat2->freq;
+                               if( r ) fprintf( stderr, "y %d-%d, len=%d,%d, val = %f\n", (int)(pat1-pat1bk), (int)(pat2-pat2bk), pat1->len, pat2->len, val ); // 070405
+//                             if( r ) fprintf( stderr, "y %d-%d, len=%d,%d, val = %f\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len, val );
+                       }
+               } 
+       }
+       if( r ) fprintf( stderr, "nocountmatch=%f\n", val );
+       return( val );
+}
+
+#if 0 // by D.Mathog
+static float countnocountmatch( Gappat *pat1, Gappat *pat2, int r )
+{
+//     return( 0.0 );
+       Gappat *pat1bk = pat1;
+       Gappat *pat2bk = pat2;
+       float val = 0.0;
+       // pat1[][0] ha total gap.
+       for( pat1=pat1bk+1; pat1->len != 0; pat1++ )
+       {
+//             if( r ) fprintf( stderr, "b %d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len );
+               for( pat2=pat2bk+1; pat2->len != 0; pat2++ )
+               {
+                       if( pat1->len == pat2->len )
+                       {
+//                             if( r ) fprintf( stderr, " x%d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len );
+                               val += pat1->freq * pat2->freq;
+//                             if( r ) fprintf( stderr, "y %d-%d, val = %f\n", pat1-pat1bk, pat2-pat2bk,val );
+//                             if( r ) fprintf( stderr, "z tsugi, %d-%d, len=%d,%d\n", pat1-pat1bk+1, pat2-pat2bk+1, (pat1+1)->len, (pat2+1)->len );
+                       }
+//                     if( r ) fprintf( stderr, "a %d-%d, len=%d,%d\n", pat1-pat1bk, pat2-pat2bk, pat1->len, pat2->len );
+               } 
+       }
+//     fprintf( stderr, "nocountmatch=%f\n", val );
+       return( val );
+}
+#endif
+
+static float countnocountx( Gappat *pat1, float diaf1, Gappat *pat2, int offset1, int r )
+{
+//     return( 0.0 );
+       float gmatch;
+       Gappat *pat1bk = pat1;
+       Gappat *pat2bk = pat2;
+
+       gmatch = 0.0;
+       for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0
+       {
+               if( pat2->len == offset1 )
+               {
+                       gmatch = diaf1 * pat2->freq;
+//                     if( r ) fprintf( stderr, "match0!!, len=%d, gmatch=%f * %f\n", pat2->len, diaf1, pat2->freq );
+               }
+       }
+       for( pat1=pat1bk+1; pat1->len != 0; pat1++ ) // excl. len=0
+       {
+               for( pat2=pat2bk+1; pat2->len != 0; pat2++ ) // excl. len=0
+               {
+                       if( pat1->len + offset1 == pat2->len )
+                       {
+                               gmatch += pat1->freq * pat2->freq;
+//                             if( r ) fprintf( stderr, "match1!!, len=%d, gmatch=%f * %f\n", pat2->len, pat1->freq, pat2->freq );
+                       }
+               }
+       }
+       return( gmatch );
+}
+
+#if 0 // by D.Mathog
+static float countnocount( Gappat *pat1, Gappat *pat2, int offset1, int offset2 ) //osoi
+{
+//     return( 0.0 );
+       Gappat *pat1bk = pat1;
+       Gappat *pat2bk = pat2;
+       float val = 0.0;
+       // pat1[][0] ha total gap.
+       for( pat1=pat1bk+1; pat1->len != -1; pat1++ )
+       {
+               for( pat2=pat2bk+1; pat2->len != -1; pat2++ )
+               {
+                       if( pat1->len+offset1 == pat2->len+offset2 )
+                       {
+                               val += pat1->freq * pat2->freq;
+                       }
+               } 
+       }
+//     fprintf( stderr, "nocount=%f\n", val );
+       return( val );
+}
+#endif
+
+
+
+#if 1 // tditeration 
+float imp_match_out_scH( int i1, int j1 )
+{
+//     fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold );
+//     fprintf( stderr, "val = %f\n", impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+}
+#endif
+
+static void imp_match_out_veadH( float *imp, int i1, int lgth2 )
+{
+#if FASTMATCHCALC 
+       float *pt = impmtx[i1];
+       while( lgth2-- )
+               *imp++ += *pt++;
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[j];
+#endif
+}
+static void imp_match_out_vead_tateH( float *imp, int j1, int lgth1 )
+{
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[i][j1];
+}
+
+#if 1 // tbfast.c kara yobareru.
+void imp_match_init_strictH( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       static TLS int impalloclen = 0;
+       float effij;
+       double effijx;
+       char *pt, *pt1, *pt2;
+       static TLS char *nocount1 = NULL;
+       static TLS char *nocount2 = NULL;
+       LocalHom *tmpptr;
+
+       if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx =  fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = (float)( eff1[i] * eff2[j] * effijx );
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = pt - seq1[i] - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = pt - seq1[i] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = pt - seq1[i] - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = pt - seq2[j] - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = pt - seq2[j] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = pt - seq2[j] - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+#if 1
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+                                               impmtx[k1][k2] += tmpptr->fimportance * effij;
+//                                             fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+//                                             fprintf( stderr, "%d (%c) - %d (%c)  - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+#else
+                               while( k1 <= end1 && k2 <= end2 )
+                               {
+                                       fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 );
+                                       if( !nocount1[k1] && !nocount2[k2] )
+                                       {
+                                               impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j]  * fastathreshold;
+                                               fprintf( stderr, "marked\n" );
+                                       }
+                                       else
+                                               fprintf( stderr, "no count\n" );
+                                       k1++; k2++;
+                               }
+#endif
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+#if 0
+       if( clus1 == 1 && clus2 == 6 )
+       {
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "seq1[0] =  %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] =  %s\n", seq2[0] );
+               fprintf( stderr, "impmtx = \n" );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", (double)k2 );
+               fprintf( stderr, "\n" );
+               for( k1=0; k1<lgth1; k1++ )
+               {
+                       fprintf( stderr, "%d ", k1 );
+                       for( k2=0; k2<3; k2++ )
+                               fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+                       fprintf( stderr, "\n" );
+               }
+               exit( 1 );
+       }
+#endif
+}
+#endif
+
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+                               scarr[l] += n_dis[j][l] * cpmx1[j][i1];
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+// simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_scH( iin, jin );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+       return( 0.0 );
+}
+
+float H__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS Gappat **gappat1;
+       static TLS Gappat **gappat2;
+       static TLS float *digf1;
+       static TLS float *digf2;
+       static TLS float *diaf1;
+       static TLS float *diaf2;
+       static TLS float *gapz1;
+       static TLS float *gapz2;
+       static TLS float *gapf1;
+       static TLS float *gapf2;
+       static TLS float *ogcp1g;
+       static TLS float *ogcp2g;
+       static TLS float *fgcp1g;
+       static TLS float *fgcp2g;
+       static TLS float *ogcp1;
+       static TLS float *ogcp2;
+       static TLS float *fgcp1;
+       static TLS float *fgcp2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float fpenalty = (float)penalty;
+       float tmppenal;
+       float cumpenal;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fgcp1va;
+       float ogcp1va;
+       int maegap;
+
+
+
+#if 0
+       fprintf( stderr, "####  eff in SA+++align\n" );
+       fprintf( stderr, "####  seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "####  strlen( seq1[0] ) = %d\n", strlen( seq1[0] ) );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 0
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+#endif
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       free( gappat1 );
+                       free( gappat2 );
+                       FreeFloatVec( digf1 );
+                       FreeFloatVec( digf2 );
+                       FreeFloatVec( diaf1 );
+                       FreeFloatVec( diaf2 );
+                       FreeFloatVec( gapz1 );
+                       FreeFloatVec( gapz2 );
+                       FreeFloatVec( gapf1 );
+                       FreeFloatVec( gapf2 );
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+                       FreeFloatVec( ogcp1g );
+                       FreeFloatVec( ogcp2g );
+                       FreeFloatVec( fgcp1g );
+                       FreeFloatVec( fgcp2g );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               digf1 = AllocateFloatVec( ll1+2 );
+               digf2 = AllocateFloatVec( ll2+2 );
+               diaf1 = AllocateFloatVec( ll1+2 );
+               diaf2 = AllocateFloatVec( ll2+2 );
+               gappat1 = (Gappat **)calloc( ll1+2, sizeof( Gappat * ) );
+               gappat2 = (Gappat **)calloc( ll2+2, sizeof( Gappat * ) );
+               gapz1 = AllocateFloatVec( ll1+2 );
+               gapz2 = AllocateFloatVec( ll2+2 );
+               gapf1 = AllocateFloatVec( ll1+2 );
+               gapf2 = AllocateFloatVec( ll2+2 );
+               ogcp1 = AllocateFloatVec( ll1+2 );
+               ogcp2 = AllocateFloatVec( ll2+2 );
+               fgcp1 = AllocateFloatVec( ll1+2 );
+               fgcp2 = AllocateFloatVec( ll2+2 );
+               ogcp1g = AllocateFloatVec( ll1+2 );
+               ogcp2g = AllocateFloatVec( ll2+2 );
+               fgcp1g = AllocateFloatVec( ll1+2 );
+               fgcp2g = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+#if 0
+       {
+               float t = 0.0;
+               for( i=0; i<icyc; i++ )
+                       t += eff1[i];
+       fprintf( stderr, "## totaleff = %f\n", t );
+       }
+#endif
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap1 );
+               new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap1, egap2 );
+               getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 ); // sgap1 ha iranai ?
+               getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 ); // sgap1 ha iranai ?
+               getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 ); // sgap1 ha iranai ?
+               getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap1, egap2 ); // sgap1 ha iranai ?
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 ); // atode
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 ); // atode
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 ); // atode
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 ); // atode
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
+               st_getGapPattern( gappat1, icyc, seq1, eff1, lgth1 );
+               st_getGapPattern( gappat2, jcyc, seq2, eff2, lgth2 );
+               getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
+               getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
+               getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
+               getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead_tateH( initverticalw, 0, lgth1 ); // 060306
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_veadH( currentw, 0, lgth2 ); // 060306
+
+
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+       if( outgap == 1 )
+       {
+//             if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+//             initverticalw[0] += g;
+//             currentw[0] += g;
+
+//             if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+//             initverticalw[0] += g;
+//             currentw[0] += g;
+
+               for( i=1; i<lgth1+1; i++ )
+               {
+//                     initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+
+                       tmppenal = 0.0;
+//                     tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+0.0) + gapz2[0]*(1.0-digf1[0] - diaf1[0]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-0.0)*(1.0-ogcp1g[0]+0.0) + 0.0*(1.0-0.0-0.0) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-0.0) * (1.0-diaf1[0]) + 0.0 ) * 0.5 * fpenalty; // 0.
+//                     tmppenal -= ( (1.0-gapf2[j-1]) * ogcp1g[i] + gapf2[j-1] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 1 = %f\n", i, 0, tmppenal );
+                       initverticalw[i] += tmppenal;
+
+                       tmppenal = diaf1[i] * ( 1.0 - gapf2[0] ) * fpenalty;
+                       if( gappat1[i][0].freq )
+                       {
+                               tmppenal += ( gappat1[i][0].freq ) * ( 1.0 - gapf2[0] ) * fpenalty;
+                               tmppenal -= ( countnocountx( gappat2[0], diaf2[0], gappat1[i], i, 1 ) ) * fpenalty;
+                       }
+//                     tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapz2[1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[0])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[0]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[0]) * (1.0-diaf1[i]) + gapf2[0] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j]) * fgcp1g[i] + gapf2[j] ) * 0.5 * fpenalty;
+                       initverticalw[i] += tmppenal;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 2 = %f, cumpenal=%f, fgcp1g[i]=%f, ogcp1g[i]=%f\n", i, 0, tmppenal, cumpenal, fgcp1g[i], ogcp1g[i] );
+
+               }
+               cumpenal = 0.0;
+               for( j=1; j<lgth2+1; j++ )
+               {
+//                     currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+
+                       tmppenal = 0.0;
+//                     tmppenal = ( (1.0-gapf1[i-1])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapf1[i-1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+0.0) + gapz1[0]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-0.0)*(1.0-ogcp2g[0]+0.0) + 0.0*(1.0-0.0-0.0) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-0.0) * (1.0-diaf2[0]) + 0.0 ) * 0.5 * fpenalty; // 0.
+//                     tmppenal -= ( (1.0-gapf1[0]) * fgcp2g[j] + gapf1[0] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 3 = %f\n", 0, j, tmppenal );
+                       currentw[j] += tmppenal;
+
+                       tmppenal = diaf2[j] * ( 1.0 - gapf1[0] ) * fpenalty;
+                       if( gappat2[j][0].freq )
+                       {
+                               tmppenal += ( gappat2[j][0].freq ) * ( 1.0 - gapf1[0] ) * fpenalty;
+                               tmppenal -= ( countnocountx( gappat1[0], diaf1[0], gappat2[j], j, 1 ) ) * fpenalty;
+                       }
+//                     tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapz1[1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[0])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[0]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[0]) * (1.0-diaf2[j]) + gapf1[0] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[0]) * ogcp2g[j] + gapf1[i-1] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 4 = %f\n", 0, j, tmppenal );
+                       currentw[j] += tmppenal;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       m[0] = 0.0; // iranai
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+//             m[j] = currentw[j-1] + ogcp1[1]; 
+               mp[j] = 0;
+
+               tmppenal = 0.0;
+//             tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[1]+fgcp1g[1]) + gapz2[j]*(1.0-digf1[1]-diaf1[1]) ) * 0.5 * fpenalty; // mada
+//             tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[1]+fgcp1g[1]) + gapf2[j-1]*(1.0-digf1[1]-diaf1[1]) ) * 0.5 * fpenalty; // mada
+//             tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//             tmppenal = 0.5 * fpenalty;
+//             tmppenal -= ( (1.0-0.0) * (1.0-0.0) + 0.0 ) * 0.5 * fpenalty;
+//             tmppenal -= ( (1.0-gapf2[-1]) * (1.0-diaf1[0]) + gapf2[-1] ) * 0.5 * fpenalty;
+//             if( tmppenal ) fprintf( stderr, "%c=%c, end j tmppenal=%f\n", seq1[0][0], seq2[0][j-1], tmppenal );
+               m[j] = currentw[j-1] + tmppenal + fpenalty * 10000;  
+//             m[j] = currentw[j-1] + ogcp1[1]; 
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_veadH( currentw, i, lgth2 );
+#else
+                       imp_match_out_veadH( currentw, i, lgth2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+
+//             mi = previousw[0] + ogcp2[1];  // machigai
+               tmppenal = 0.0;
+//             tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[1]+fgcp2g[1]) + gapz1[i]*(1.0-digf2[1]-diaf2[1]) ) * 0.5 * fpenalty; // mada
+//             tmppenal = ( (1.0-gapf1[i-1])*(1.0-ogcp2g[1]+fgcp2g[1]) + gapf1[i-1]*(1.0-digf2[1]-diaf2[1]) ) * 0.5 * fpenalty; // mada
+//             fprintf( stderr, "%c=%c, end i tmppenal=%f, ogcp2g[1]=%f\n", seq1[0][i-1], seq2[0][0], tmppenal, ogcp2g[1] );
+//             mi = previousw[0] + tmppenal;
+               mi = previousw[0] + tmppenal + fpenalty * 10000;
+
+               mpi = 0;
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fgcp2pt = fgcp2;
+               ogcp2pt = ogcp2 + 1;
+               fgcp1va = fgcp1[i-1];
+               ogcp1va = ogcp1[i];
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+
+                       if( gappat2[j][0].freq )
+                       {
+                               g = diaf1[i] * gappat2[j][0].freq * fpenalty;
+//                             if( seq1[0][i] == 'D' && seq2[0][j] == 'D' )
+//                             if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g/fpenalty, seq1[0][i], seq2[0][j] );
+                               wm += g;
+                       }
+
+                       if( gappat1[i][0].freq )
+                       {
+                               g = diaf2[j] * gappat1[i][0].freq * fpenalty;
+//                             if( seq1[0][i] == 'D' && seq2[0][j] == 'D' )
+//                             if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g/fpenalty, seq1[0][i], seq2[0][j] );
+                               wm += g;
+                       }
+                       {
+                               g = ( (gappat1[i][0].freq) * (gappat2[j][0].freq) ) * fpenalty;
+//                             if( seq1[0][i] == 'D' && seq2[0][j] == 'D' )
+//                             if( g ) fprintf( stderr, "match penal3=%f, %c-%c\n", g/fpenalty, seq1[0][i], seq2[0][j] );
+                               wm += g;
+                       }
+                       if( 0 )
+                       {
+                               maegap = ijp[i-1][j-1];
+//                             if( seq1[0][i] == 'Y' && seq2[0][j] == 'Y' )
+//                                     fprintf( stderr, "i,j=%d,%d, maegap=%d\n", i, j, maegap );
+                               maegap = 0;
+
+                               if( maegap == 0 )
+                               {
+                                       g = ( countnocountmatchx( gappat1[i], gappat2[j], 0, 0, 0 ) ) * fpenalty;
+//                                     if( seq1[0][i] == 'D' && seq2[0][j] == 'D' )
+//                                             fprintf( stderr, "kanwa0 %c-%c, i,j=%d,%d, g/fpenalty=%f, nocount=%f\n", seq1[0][i], seq2[0][j], i, j, g/fpenalty, countnocountmatchx( gappat1[i], gappat2[j], 0, -maegap, 1 ) );
+                               }
+#if 0 // atta houga yoi hazu
+                               else if( maegap < 0 ) // i jump
+                               {
+                                       g = ( countnocountmatchx( gappat1[i], gappat2[j], 0, -maegap, 0 ) ) * fpenalty;
+                                       if( seq1[0][i] == 'Y' && seq2[0][j] == 'Y' )
+                                       {
+                                               fprintf( stderr, "i-jumped, offset1=%d\n", maegap );
+                                               fprintf( stderr, "kanwa1 %c-%c, i,j=%d,%d, g/fpenalty=%f, nocount=%f, nocount=%f\n", seq1[0][i], seq2[0][j], i, j, g/fpenalty, countnocountmatchx( gappat1[i], gappat2[j], 0, -maegap, 0 ) );
+                                       }
+                               }
+                               else                  // j jump
+                               {
+                                       g = ( countnocountmatchx( gappat1[i], gappat2[j], maegap, 0, 0 ) ) * fpenalty;
+                                       if( seq1[0][i] == 'Y' && seq2[0][j] == 'Y' )
+                                       {
+                                               fprintf( stderr, "j-jumped, offset1=%d\n", maegap );
+                                               fprintf( stderr, "kanwa2, %c-%c, i,j=%d,%d, g/fpenalty=%f, nocount=%f\n", seq1[0][i], seq2[0][j], i, j, g/fpenalty, countnocountmatchx( gappat1[i], gappat2[j], 0, -maegap, 1 ) );
+                                       }
+                               }
+#endif
+                               wm -= g;
+                       }
+
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+//                     tmppenal = fpenalty;
+                       tmppenal = diaf2[j] * ( 1.0 - gapf1[i] ) * fpenalty;
+                       if( gappat2[j][0].freq )
+                       {
+                               tmppenal += ( gappat2[j][0].freq ) * ( 1.0 - gapf1[i] ) * fpenalty;
+//                             tmppenal -= ( countnocountx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, 0 ) ) * fpenalty;
+                               maegap = ijp[i-1][mpi];
+                               maegap = 0;
+                               if( maegap == 0 )
+                               {
+                                       tmppenal -= ( countnocountx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, 0 ) ) * fpenalty;
+                               }
+#if 0 // attahouga yoi hazu
+                               else if( maegap < 0 ) // i jump
+                               {
+                                       maegap = -maegap;
+                                       tmppenal -= ( countnocountxx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1+maegap, 0 ) ) * fpenalty;
+                               }
+                               else                  // j jump
+                               {
+                                       tmppenal -= ( countnocountxx( gappat1[i], diaf1[i], gappat2[j], j-mpi-1, maegap ) ) * fpenalty;
+                               }
+#endif
+                       }
+                       if( (g=mi+tmppenal) > wm )
+                       {
+//                             if( seq1[0][i] == 'A' && seq2[0][j] == 'A' ) fprintf( stderr, "jump i start=%f (i,j=%d,%d, *ijppt=%d, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, i, j, -(j-mpi), digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( (g=*prept) >= mi )
+                       {
+//                             fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               mi = g;
+                               mpi = j-1;
+                       }
+                       else if( j != 1 )
+                       {
+//                             mi += ( ogcp2g[j-0] + fgcp2g[j] ) * fpenalty * 0.5;
+//                             fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", '=', '=', seq2[0][j-1], seq2[0][j], ogcp2g[j-0] * fpenalty*0.5, fgcp2g[j] * fpenalty*0.5 );
+                       }
+#if USE_PENALTY_EX
+                               mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+
+//                     tmppenal = fpenalty;
+                       tmppenal = diaf1[i] * ( 1.0 - gapf2[j] ) * fpenalty;
+                       if( gappat1[i][0].freq )
+                       {
+                               tmppenal += ( gappat1[i][0].freq ) * ( 1.0 - gapf2[j] ) * fpenalty;
+//                             tmppenal -= ( countnocountx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, 1 ) ) * fpenalty;
+                               maegap = ijp[*mpjpt][j-1];
+                               if( maegap == 0 )
+                               {
+                                       tmppenal -= ( countnocountx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, 1 ) ) * fpenalty;
+                               }
+#if 0 // attahouga yoi hazu
+                               else if( maegap > 0 ) // j jump
+                               {
+                                       tmppenal -= ( countnocountxx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1+maegap, 0 ) ) * fpenalty;
+                               }
+                               else                  // i jump
+                               {
+                                       maegap = -maegap;
+                                       tmppenal -= ( countnocountxx( gappat2[j], diaf2[j], gappat1[i], i-*mpjpt-1, maegap ) ) * fpenalty;
+                               }
+#endif
+                       }
+                       if( (g=*mjpt+tmppenal) > wm )
+                       {
+//                             if( seq1[0][i] == 'S' && seq2[0][j] == 'S' ) fprintf( stderr, "jump j start at %d, %d, g=%f, %c-%c\n", i, j, g-*mjpt, seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( (g=*prept) >= *mjpt )
+                       {
+//                             fprintf( stderr, "jump j end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+                       else if( i != 1 )
+                       {
+//                             m[j] += ( ogcp1g[i-0] + fgcp1g[i] ) * fpenalty * 0.5;
+//                             fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", seq1[0][i-1], seq1[0][i], '=', '=', ogcp1g[i-0] * fpenalty*0.5, fgcp1g[i] * fpenalty*0.5 );
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+       fprintf( stderr, "wm = %f\n", wm );
+
+       for( i=0; i<lgth1+1; i++ ) 
+       {
+               free( gappat1[i] );
+               gappat1[i] = NULL;
+       }
+       for( i=0; i<lgth2+1; i++ ) 
+       {
+               free( gappat2[i] );
+               gappat2[i] = NULL;
+       }
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/JTT.c b/binaries/src/mafft/core/JTT.c
new file mode 100644 (file)
index 0000000..0fee40d
--- /dev/null
@@ -0,0 +1,244 @@
+#if 0
+#include "mltaln.h"
+#endif
+#define DEFAULTGOP_J -1530
+#define DEFAULTGEP_J   -00 
+#define DEFAULTOFS_J  -123  /* +10 -- -50  teido ka ? */
+#define DEFAULTPAMN  200
+
+void JTTmtx( double **rsr, double *freq, char locamino[26], char locgrp[26], int isTM )
+{
+       int i, j;
+       double r[20][20];
+//     char locamino0[] = "ARNDCQEGHILKMFPSTWYVBZX.-U";
+       char locamino0[] = "ARNDCQEGHILKMFPSTWYVBZX.-J";
+       char locgrp0[] = 
+       {
+               0, 3, 2, 2, 5, 2, 2, 0, 3, 1, 1, 3, 1, 4, 0, 0, 0, 4, 4, 1, 2, 2,
+               6, 6, 6, 1, 
+       };
+
+       double freq0[20] = 
+       {
+               0.077,
+               0.051,
+               0.043,
+               0.052,
+               0.020,
+               0.041,
+               0.062,
+               0.074,
+               0.023,
+               0.052,
+               0.091,
+               0.059,
+               0.024,
+               0.040,
+               0.051,
+               0.069,
+               0.059,
+               0.014,
+               0.032,
+               0.066,
+       };
+       double freq0_TM[20] = 
+       {
+                0.1051,
+                0.0157,
+                0.0185,
+                0.0089,
+                0.0219,
+                0.0141,
+                0.0097,
+                0.0758,
+                0.0168,
+                0.1188,
+                0.1635,
+                0.0112,
+                0.0333,
+                0.0777,
+                0.0260,
+                0.0568,
+                0.0523,
+                0.0223,
+                0.0324,
+                0.1195,
+       };
+
+    /* Lower triangular is JTT's Accepted point mutations */
+    r[ 1][ 0]=  247;
+
+    r[ 2][ 0]=  216; r[ 2][ 1]=  116;
+
+    r[ 3][ 0]=  386; r[ 3][ 1]=   48; r[ 3][ 2]= 1433;
+
+    r[ 4][ 0]=  106; r[ 4][ 1]=  125; r[ 4][ 2]=   32; r[ 4][ 3]=   13;
+
+    r[ 5][ 0]=  208; r[ 5][ 1]=  750; r[ 5][ 2]=  159; r[ 5][ 3]=  130;
+    r[ 5][ 4]=    9;
+
+    r[ 6][ 0]=  600; r[ 6][ 1]=  119; r[ 6][ 2]=  180; r[ 6][ 3]= 2914;
+    r[ 6][ 4]=    8; r[ 6][ 5]= 1027;
+
+    r[ 7][ 0]= 1183; r[ 7][ 1]=  614; r[ 7][ 2]=  291; r[ 7][ 3]=  577;
+    r[ 7][ 4]=   98; r[ 7][ 5]=   84; r[ 7][ 6]=  610;
+
+    r[ 8][ 0]=   46; r[ 8][ 1]=  446; r[ 8][ 2]=  466; r[ 8][ 3]=  144;
+    r[ 8][ 4]=   40; r[ 8][ 5]=  635; r[ 8][ 6]=   41; r[ 8][ 7]=   41;
+
+    r[ 9][ 0]=  173; r[ 9][ 1]=   76; r[ 9][ 2]=  130; r[ 9][ 3]=   37;
+    r[ 9][ 4]=   19; r[ 9][ 5]=   20; r[ 9][ 6]=   43; r[ 9][ 7]=   25;
+    r[ 9][ 8]=   26;
+
+    r[10][ 0]=  257; r[10][ 1]=  205; r[10][ 2]=   63; r[10][ 3]=   34;
+    r[10][ 4]=   36; r[10][ 5]=  314; r[10][ 6]=   65; r[10][ 7]=   56;
+    r[10][ 8]=  134; r[10][ 9]= 1324;
+
+    r[11][ 0]=  200; r[11][ 1]= 2348; r[11][ 2]=  758; r[11][ 3]=  102;
+    r[11][ 4]=    7; r[11][ 5]=  858; r[11][ 6]=  754; r[11][ 7]=  142;
+    r[11][ 8]=   85; r[11][ 9]=   75; r[11][10]=   94;
+
+    r[12][ 0]=  100; r[12][ 1]=   61; r[12][ 2]=   39; r[12][ 3]=   27;
+    r[12][ 4]=   23; r[12][ 5]=   52; r[12][ 6]=   30; r[12][ 7]=   27;
+    r[12][ 8]=   21; r[12][ 9]=  704; r[12][10]=  974; r[12][11]=  103;
+
+    r[13][ 0]=   51; r[13][ 1]=   16; r[13][ 2]=   15; r[13][ 3]=    8;
+    r[13][ 4]=   66; r[13][ 5]=    9; r[13][ 6]=   13; r[13][ 7]=   18;
+    r[13][ 8]=   50; r[13][ 9]=  196; r[13][10]= 1093; r[13][11]=    7;
+    r[13][12]=   49;
+
+    r[14][ 0]=  901; r[14][ 1]=  217; r[14][ 2]=   31; r[14][ 3]=   39;
+    r[14][ 4]=   15; r[14][ 5]=  395; r[14][ 6]=   71; r[14][ 7]=   93;
+    r[14][ 8]=  157; r[14][ 9]=   31; r[14][10]=  578; r[14][11]=   77;
+    r[14][12]=   23; r[14][13]=   36;
+
+    r[15][ 0]= 2413; r[15][ 1]=  413; r[15][ 2]= 1738; r[15][ 3]=  244;
+    r[15][ 4]=  353; r[15][ 5]=  182; r[15][ 6]=  156; r[15][ 7]= 1131;
+    r[15][ 8]=  138; r[15][ 9]=  172; r[15][10]=  436; r[15][11]=  228;
+    r[15][12]=   54; r[15][13]=  309; r[15][14]= 1138;
+
+    r[16][ 0]= 2440; r[16][ 1]=  230; r[16][ 2]=  693; r[16][ 3]=  151;
+    r[16][ 4]=   66; r[16][ 5]=  149; r[16][ 6]=  142; r[16][ 7]=  164;
+    r[16][ 8]=   76; r[16][ 9]=  930; r[16][10]=  172; r[16][11]=  398;
+    r[16][12]=  343; r[16][13]=   39; r[16][14]=  412; r[16][15]= 2258;
+
+    r[17][ 0]=   11; r[17][ 1]=  109; r[17][ 2]=    2; r[17][ 3]=    5;
+    r[17][ 4]=   38; r[17][ 5]=   12; r[17][ 6]=   12; r[17][ 7]=   69;
+    r[17][ 8]=    5; r[17][ 9]=   12; r[17][10]=   82; r[17][11]=    9;
+    r[17][12]=    8; r[17][13]=   37; r[17][14]=    6; r[17][15]=   36;
+    r[17][16]=    8;
+
+    r[18][ 0]=   41; r[18][ 1]=   46; r[18][ 2]=  114; r[18][ 3]=   89;
+    r[18][ 4]=  164; r[18][ 5]=   40; r[18][ 6]=   15; r[18][ 7]=   15;
+    r[18][ 8]=  514; r[18][ 9]=   61; r[18][10]=   84; r[18][11]=   20;
+    r[18][12]=   17; r[18][13]=  850; r[18][14]=   22; r[18][15]=  164;
+    r[18][16]=   45; r[18][17]=   41;
+
+    r[19][ 0]= 1766; r[19][ 1]=   69; r[19][ 2]=   55; r[19][ 3]=  127;
+    r[19][ 4]=   99; r[19][ 5]=   58; r[19][ 6]=  226; r[19][ 7]=  276;
+    r[19][ 8]=   22; r[19][ 9]= 3938; r[19][10]= 1261; r[19][11]=   58;
+    r[19][12]=  559; r[19][13]=  189; r[19][14]=   84; r[19][15]=  219;
+    r[19][16]=  526; r[19][17]=   27; r[19][18]=   42;
+
+
+    /* Upper triangular is JTT's Accepted point mutations for transmembrane */
+ r[ 0][ 1]=   21; r[ 0][ 2]=    2; r[ 0][ 3]=    7; r[ 0][ 4]=   13;
+ r[ 0][ 5]=    4; r[ 0][ 6]=    6; r[ 0][ 7]=  160; r[ 0][ 8]=    6;
+ r[ 0][ 9]=   44; r[ 0][10]=   43; r[ 0][11]=    5; r[ 0][12]=   10;
+ r[ 0][13]=   21; r[ 0][14]=   34; r[ 0][15]=  198; r[ 0][16]=  202;
+ r[ 0][17]=    0; r[ 0][18]=    1; r[ 0][19]=  292; 
+ r[ 1][ 2]=    0; r[ 1][ 3]=    1; r[ 1][ 4]=    2; r[ 1][ 5]=   21;
+ r[ 1][ 6]=    3; r[ 1][ 7]=   22; r[ 1][ 8]=   21; r[ 1][ 9]=    4;
+ r[ 1][10]=    8; r[ 1][11]=   53; r[ 1][12]=   19; r[ 1][13]=    0;
+ r[ 1][14]=    1; r[ 1][15]=    5; r[ 1][16]=    5; r[ 1][17]=   28;
+ r[ 1][18]=    0; r[ 1][19]=    0; 
+ r[ 2][ 3]=   14; r[ 2][ 4]=    1; r[ 2][ 5]=    7; r[ 2][ 6]=    0;
+ r[ 2][ 7]=    0; r[ 2][ 8]=    8; r[ 2][ 9]=    4; r[ 2][10]=    5;
+ r[ 2][11]=   11; r[ 2][12]=    3; r[ 2][13]=    1; r[ 2][14]=    2;
+ r[ 2][15]=   32; r[ 2][16]=   19; r[ 2][17]=    1; r[ 2][18]=    1;
+ r[ 2][19]=    2; 
+ r[ 3][ 4]=    0; r[ 3][ 5]=    0; r[ 3][ 6]=   12; r[ 3][ 7]=   15;
+ r[ 3][ 8]=    4; r[ 3][ 9]=    1; r[ 3][10]=    0; r[ 3][11]=    2;
+ r[ 3][12]=    1; r[ 3][13]=    0; r[ 3][14]=    1; r[ 3][15]=    0;
+ r[ 3][16]=    6; r[ 3][17]=    0; r[ 3][18]=    1; r[ 3][19]=    4;
+ r[ 4][ 5]=    0; r[ 4][ 6]=    0; r[ 4][ 7]=   13; r[ 4][ 8]=    2;
+ r[ 4][ 9]=    4; r[ 4][10]=   11; r[ 4][11]=    0; r[ 4][12]=    1;
+ r[ 4][13]=   34; r[ 4][14]=    0; r[ 4][15]=   48; r[ 4][16]=   13;
+ r[ 4][17]=    8; r[ 4][18]=   23; r[ 4][19]=   47; 
+ r[ 5][ 6]=   16; r[ 5][ 7]=    1; r[ 5][ 8]=   26; r[ 5][ 9]=    1;
+ r[ 5][10]=   16; r[ 5][11]=    6; r[ 5][12]=    3; r[ 5][13]=    0;
+ r[ 5][14]=    5; r[ 5][15]=    7; r[ 5][16]=    2; r[ 5][17]=    0;
+ r[ 5][18]=    0; r[ 5][19]=    0; 
+ r[ 6][ 7]=   21; r[ 6][ 8]=    0; r[ 6][ 9]=    0; r[ 6][10]=    0;
+ r[ 6][11]=    0; r[ 6][12]=    0; r[ 6][13]=    0; r[ 6][14]=    0;
+ r[ 6][15]=    4; r[ 6][16]=    2; r[ 6][17]=    0; r[ 6][18]=    0;
+ r[ 6][19]=    7; 
+ r[ 7][ 8]=    1; r[ 7][ 9]=   10; r[ 7][10]=    0; r[ 7][11]=    0;
+ r[ 7][12]=    3; r[ 7][13]=    4; r[ 7][14]=    7; r[ 7][15]=   64;
+ r[ 7][16]=   12; r[ 7][17]=    5; r[ 7][18]=    0; r[ 7][19]=   53;
+ r[ 8][ 9]=    3; r[ 8][10]=    2; r[ 8][11]=    0; r[ 8][12]=    1;
+ r[ 8][13]=    0; r[ 8][14]=    0; r[ 8][15]=    0; r[ 8][16]=    4;
+ r[ 8][17]=    0; r[ 8][18]=   29; r[ 8][19]=    2;
+
+ r[ 9][10]=  273; r[ 9][11]=    0; r[ 9][12]=  161; r[ 9][13]=   66;
+ r[ 9][14]=    4; r[ 9][15]=   22; r[ 9][16]=  150; r[ 9][17]=    1;
+ r[ 9][18]=    4; r[ 9][19]=  883;
+
+ r[10][11]=    1; r[10][12]=  153; r[10][13]=  251; r[10][14]=   37;
+ r[10][15]=   43; r[10][16]=   26; r[10][17]=   20; r[10][18]=    6;
+ r[10][19]=  255;
+
+ r[11][12]=    4; r[11][13]=    0; r[11][14]=    0; r[11][15]=    1;
+ r[11][16]=    2; r[11][17]=    0; r[11][18]=    5; r[11][19]=    1;
+
+ r[12][13]=    8; r[12][14]=    0; r[12][15]=    1; r[12][16]=   32;
+ r[12][17]=    1; r[12][18]=    5; r[12][19]=   89;
+
+ r[13][14]=    0; r[13][15]=   32; r[13][16]=    9; r[13][17]=    2;
+ r[13][18]=   54; r[13][19]=   37;
+
+ r[14][15]=    9; r[14][16]=   10; r[14][17]=    0; r[14][18]=    1;
+ r[14][19]=    1;
+
+ r[15][16]=  134; r[15][17]=    1; r[15][18]=   22; r[15][19]=   13;
+
+ r[16][17]=    1; r[16][18]=    3; r[16][19]=   48;
+
+ r[17][18]=    2; r[17][19]=   18;
+
+ r[18][19]=    2;
+
+
+
+       for (i = 0; i < 20; i++) r[i][i] = 0.0;
+       if( isTM )
+       {
+               for (i = 1; i < 20; i++) for (j = 0; j < i; j++)
+               {
+                       r[j][i] /= 400.0 * freq0_TM[i] * freq0_TM[j];
+                       r[i][j] = r[j][i];
+               }
+               for( i=0; i<20; i++ ) freq[i] = freq0_TM[i];
+       }
+       else
+       {
+               for (i = 1; i < 20; i++) for (j = 0; j < i; j++)
+               {
+                       r[i][j] /= 400.0 * freq0[i] * freq0[j];
+                       r[j][i] = r[i][j];
+               }
+               for( i=0; i<20; i++ ) freq[i] = freq0[i];
+       }
+
+       for( i=0; i<26; i++ ) locamino[i] = locamino0[i];
+       for( i=0; i<26; i++ ) locgrp[(int)locamino[i]] = locgrp0[i];
+       for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) rsr[i][j] = r[i][j];
+}
diff --git a/binaries/src/mafft/core/Lalign11.c b/binaries/src/mafft/core/Lalign11.c
new file mode 100644 (file)
index 0000000..a5b9b3c
--- /dev/null
@@ -0,0 +1,559 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define DEBUG2 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+
+static TLS int localstop; // 060910
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr;
+
+       intptr = amino_dis[(int)s1[0][i1]];
+       while( lgth2-- )
+               *match++ = intptr[(int)*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+#if 0
+static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+#endif
+
+static float Ltracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        int **ijp, int *off1pt, int *off2pt, int endi, int endj )
+{
+       int i, j, l, iin, jin, lgth1, lgth2, k, limk;
+       int ifi=0, jfi=0; // by D.Mathog, a guess
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = localstop;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = localstop;
+    }
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = endi; jin = endj;
+       limk = lgth1+lgth2;
+       for( k=0; k<=limk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+               if( ijp[ifi][jfi] == localstop ) break;
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
+       if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
+
+//     fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
+
+
+       return( 0.0 );
+}
+
+
+float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+//     static TLS int **intwork;
+//     static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float maxwm;
+       int endali = 0, endalj = 0; // by D.Mathog, a guess
+//     int endali, endalj;
+       float localthr = -offset;
+       float localthr2 = -offset;
+//     float localthr = 100;
+//     float localthr2 = 100;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+                       free( mseq1 );
+                       free( mseq2 );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+               }
+               return( 0.0 );
+       }
+
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+
+//                     FreeFloatMtx( floatwork );
+//                     FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+
+//             floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+//             intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+#if 0
+               if( m[j] < localthr ) m[j] = localthr2;
+#endif
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       lasti = lgth1+1;
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999999999.9;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( *prept > mi )
+                       {
+                               mi = *prept;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( *prept > *mjpt )
+                       {
+                               *mjpt = *prept;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               *ijppt = localstop;
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+#if 0
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+
+       if( ijp[endali][endalj] == localstop )
+       {
+               strcpy( seq1[0], "" );
+               strcpy( seq2[0], "" );
+               *off1pt = *off2pt = 0;
+               return( 0.0 );
+       }
+               
+       Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj );
+
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+
+#if 0
+       fprintf( stderr, "wm=%f\n", wm );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "   wm = %f\n",    wm );
+#endif
+
+       return( maxwm );
+}
+
diff --git a/binaries/src/mafft/core/Lalign11.c.fast b/binaries/src/mafft/core/Lalign11.c.fast
new file mode 100644 (file)
index 0000000..e481626
--- /dev/null
@@ -0,0 +1,887 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define DEBUG2 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+static short localstop;
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr;
+
+       intptr = amino_dis[s1[0][i1]];
+       while( lgth2-- )
+               *match++ = intptr[*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static float Ltracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        short **ijp, int *off1pt, int *off2pt, int endi, int endj )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
+       char gap[] = "-";
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = localstop;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = localstop;
+    }
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = endi; jin = endj;
+       limk = lgth1+lgth2;
+       for( k=0; k<=limk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+               if( ijp[ifi][jfi] == localstop ) break;
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
+       if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
+
+//     fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
+
+
+       return( 0.0 );
+}
+
+
+float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static float mi, *m;
+       static short **ijp;
+       static int mpi, *mp;
+       static float *w1, *w2;
+       static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static char **mseq;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+       float maxwm;
+       int endali, endalj;
+       float localthr = -offset;
+       float localthr2 = -offset;
+//     float localthr = 100;
+//     float localthr2 = 100;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeShortMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateShortMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+#if 0
+               if( m[j] < localthr ) m[j] = localthr2;
+#endif
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       lasti = lgth1+1;
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999.9;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( *prept > mi )
+                       {
+                               mi = *prept;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( *prept > *mjpt )
+                       {
+                               *mjpt = *prept;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               *ijppt = localstop;
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+#if DEBUG2
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+               
+       Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, off1pt, off2pt, endali, endalj );
+
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+
+#if 0
+       fprintf( stderr, "wm=%f\n", wm );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+#endif
+
+
+       return( wm );
+}
+
+float L__align11_noalign( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static float mi, *m;
+       static short **ijp;
+       static int mpi, *mp;
+       static float *w1, *w2;
+       static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static char **mseq;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+       float maxwm;
+       int endali, endalj;
+       float localthr = -offset;
+       float localthr2 = -offset;
+//     float localthr = 100;
+//     float localthr2 = 100;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+#if 0
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeShortMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateShortMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+#endif
+//     ijp = commonIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+#if 0
+               if( m[j] < localthr ) m[j] = localthr2;
+#endif
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       lasti = lgth1+1;
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999.9;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+//             mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+//                     *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       if( *prept > mi )
+                       {
+                               mi = *prept;
+//                             mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+fpenalty) > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+                       if( *prept > *mjpt )
+                       {
+                               *mjpt = *prept;
+//                             *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+//                             *ijppt = localstop;
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt++ += wm;
+//                     ijppt++;
+                       mjpt++;
+                       prept++;
+//                     mpjpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+#if DEBUG2
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+
+#if 0
+               
+       Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, off1pt, off2pt, endali, endalj );
+
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+
+       fprintf( stderr, "wm=%f\n", wm );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+#endif
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/Lalign11.c_nostatic b/binaries/src/mafft/core/Lalign11.c_nostatic
new file mode 100644 (file)
index 0000000..134a46a
--- /dev/null
@@ -0,0 +1,522 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define DEBUG2 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr;
+
+       intptr = amino_dis[(int)s1[0][i1]];
+       while( lgth2-- )
+               *match++ = intptr[(int)*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+#if 0
+static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+#endif
+
+static float Ltracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        int **ijp, int *off1pt, int *off2pt, int endi, int endj, int localstop )
+{
+       int i, j, l, iin, jin, lgth1, lgth2, k, limk;
+       int ifi=0, jfi=0; // by D.Mathog, a guess
+       char gap[] = "-";
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = localstop;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = localstop;
+    }
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = endi; jin = endj;
+       limk = lgth1+lgth2;
+       for( k=0; k<=limk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+               if( ijp[ifi][jfi] == localstop ) break;
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
+       if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
+
+//     fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
+
+
+       return( 0.0 );
+}
+
+
+float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       int **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+//     int **intwork;
+//     float **floatwork;
+       float maxwm;
+       int endali = 0, endalj = 0; // by D.Mathog, a guess
+//     int endali, endalj;
+       float localthr = -offset;
+       float localthr2 = -offset;
+//     float localthr = 100;
+//     float localthr2 = 100;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       int **localIP = NULL;
+       int localAlloc1 = 0, localAlloc2 = 0;
+       int localstop; // 060910
+
+
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       {
+               int ll1, ll2;
+
+
+               ll1 = (int)(1.3*lgth1) + 100;
+               ll2 = (int)(1.3*lgth2) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+
+//             floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+//             intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       {
+               int ll1, ll2;
+
+
+               ll1 = (int)(1.3*lgth1) + 100;
+               ll2 = (int)(1.3*lgth2) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               localIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               localAlloc1 = ll1;
+               localAlloc2 = ll2;
+       }
+       ijp = localIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+#if 0
+               if( m[j] < localthr ) m[j] = localthr2;
+#endif
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       lasti = lgth1+1;
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999999999.9;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( *prept > mi )
+                       {
+                               mi = *prept;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( *prept > *mjpt )
+                       {
+                               *mjpt = *prept;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               *ijppt = localstop;
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+#if 0
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+
+       if( ijp[endali][endalj] == localstop )
+       {
+               strcpy( seq1[0], "" );
+               strcpy( seq2[0], "" );
+               *off1pt = *off2pt = 0;
+               return( 0.0 );
+       }
+               
+       Ltracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, off1pt, off2pt, endali, endalj, localstop );
+
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+
+#if 0
+       fprintf( stderr, "wm=%f\n", wm );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "   wm = %f\n",    wm );
+#endif
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( match );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeCharMtx( mseq );
+
+
+
+//     FreeFloatMtx( floatwork );
+//     FreeIntMtx( intwork );
+
+       FreeIntMtx( localIP );
+
+       return( maxwm );
+}
+
diff --git a/binaries/src/mafft/core/Lalignmm.c b/binaries/src/mafft/core/Lalignmm.c
new file mode 100644 (file)
index 0000000..19f26ec
--- /dev/null
@@ -0,0 +1,2685 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MEMSAVE 1
+
+#define DEBUG 0
+#define USE_PENALTY_EX  0
+#define STOREWM 1
+
+#define DPTANNI 10
+
+#define LOCAL 0
+
+static int reccycle = 0;
+
+static float localthr;
+
+static void match_ribosum( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[38];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+       float *matchpt;
+       float **cpmxpdpt;
+       int **cpmxpdnpt;
+       int cpkd;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<37; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<37; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<37; k++ )
+               {
+                       scarr[l] += ribosumdis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#else
+       matchpt = match;
+       cpmxpdnpt = cpmxpdn;
+       cpmxpdpt = cpmxpd;
+       while( lgth2-- )
+       {
+               *matchpt = 0.0;
+               for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ )
+                       *matchpt += scarr[cpkd] * (*cpmxpdpt)[k];
+               matchpt++;
+               cpmxpdnpt++;
+               cpmxpdpt++;
+       }
+#endif
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+       float *matchpt;
+       float **cpmxpdpt;
+       int **cpmxpdnpt;
+       int cpkd;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += (n_dis[k][l]-RNAthr) * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#else
+       matchpt = match;
+       cpmxpdnpt = cpmxpdn;
+       cpmxpdpt = cpmxpd;
+       while( lgth2-- )
+       {
+               *matchpt = 0.0;
+               for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ )
+                       *matchpt += scarr[cpkd] * (*cpmxpdpt)[k];
+               matchpt++;
+               cpmxpdnpt++;
+               cpmxpdpt++;
+       }
+#endif
+}
+
+#if 0
+static void match_add( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+       float *matchpt;
+       float **cpmxpdpt;
+       int **cpmxpdnpt;
+       int cpkd;
+
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#else
+       matchpt = match;
+       cpmxpdnpt = cpmxpdn;
+       cpmxpdpt = cpmxpd;
+       while( lgth2-- )
+       {
+//             *matchpt = 0.0; // add dakara
+               for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ )
+                       *matchpt += scarr[cpkd] * (*cpmxpdpt)[k];
+               matchpt++;
+               cpmxpdnpt++;
+               cpmxpdpt++;
+       }
+#endif
+}
+#endif
+
+#if 0
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i]+ist, gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j]+jst, gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+#endif
+
+
+static float MSalign2m2m_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo, float **map )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2;
+       int lasti, lastj, imid, jmid = 0;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+//     float fpenalty = (float)penalty;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       int lgth1, lgth2;
+       float maxwm = 0.0;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj = 0;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if 0
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+       localthr = -offset + 500; // 0?
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     if( lgth1 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 );
+//     if( lgth2 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 );
+//
+
+#if 0
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+//             fprintf( stderr, "\n\n==== jimei\n\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+#if MEMSAVE
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = mseq1[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = mseq2[i];
+#else
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+#endif
+
+//  if( lgth1 < DPTANNI && lgth2 < DPTANNI ) // & dato lgth ==1 no kanousei ga arunode yokunai 
+//    if( lgth1 < DPTANNI ) // kore mo lgth2 ga mijikasugiru kanousei ari
+    if( lgth1 < DPTANNI || lgth2 < DPTANNI ) // zettai ni anzen ka?
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+//             value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+#if MEMSAVE
+               free( aseq1 );
+               free( aseq2 );
+#else
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+#endif
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_ribosum( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_ribosum( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_ribosum( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+#if LOCAL
+            if( wm < localthr )
+            {       
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               wm = 0;
+            }       
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_ribosum( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_ribosum( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+       firstmp = lgth1-1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_ribosum( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if LOCAL
+            if( wm < localthr )
+            {       
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               wm = 0;
+            }       
+#endif
+
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j] += *curpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+//             WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( jmid > 0 && midn[jmid-1] > wm ) //060413
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if 0
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+                               jumpi = firstmp - 1;
+                               imid = firstmp;
+                       }
+
+#if 0
+                       else if( jmid == lgth2 ) 
+                       {
+                               fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+#else // 060414
+                       else if( jmid >= lgth2 ) 
+                       {
+//                             fprintf( stderr, "CHUI1!\n" );
+                               jumpi=imid-1; jmid=lgth2;
+                               jumpj = lgth2-1;
+                       }
+#endif
+                       else
+                       {
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+
+#if STOREWM
+//                     break;
+#else
+                       break;
+#endif
+               }
+       }
+#if 0
+               jumpi=0; jumpj=0;
+               imid=lgth1-1; jmid=lgth2-1;
+       }
+#endif
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               map[i][j] = WMMTX[i][j] / maxwm;
+//             map[i][j] = WMMTX2[i][j] / maxwm;
+
+#if STOREWM
+
+#if 0
+       for( i=0; i<lgth1; i++ )
+       {
+               float maxpairscore = -9999.9;
+               float tmpscore;
+
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( maxpairscore < (tmpscore=WMMTX[i][j]) )
+                       {
+                               map12[i].pos = j;
+                               map12[i].score = tmpscore;
+                               maxpairscore = tmpscore;
+                       }
+               }
+
+               for( k=0; k<lgth1; k++ )
+               {
+                       if( i == k ) continue;
+                       if( map12[i].score <= WMMTX[k][map12[i].pos] )
+                               break;
+               }
+               if( k != lgth1 )
+               {
+                       map12[i].pos = -1;
+                       map12[i].score = -1.0;
+               }
+               fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", i, map12[i].pos, map12[i].score, seq1[0][i], seq2[0][map12[i].pos] );
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               float maxpairscore = -9999.9;
+               float tmpscore;
+
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( maxpairscore < (tmpscore=WMMTX[i][j]) )
+                       {
+                               map21[j].pos = i;
+                               map21[j].score = tmpscore;
+                               maxpairscore = tmpscore;
+                       }
+               }
+
+               for( k=0; k<lgth2; k++ )
+               {
+                       if( j == k ) continue;
+                       if( map21[j].score <= WMMTX[map21[j].pos][k] )
+                               break;
+               }
+               if( k != lgth2 )
+               {
+                       map21[j].pos = -1;
+                       map21[j].score = -1.0;
+               }
+               fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", j, map21[j].pos, map21[j].score, seq2[0][j], seq1[0][map21[j].pos] );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               if( map12[i].pos != -1 ) if( map21[map12[i].pos].pos != i ) 
+                       fprintf( stderr, "ERROR i=%d, but map12[i].pos=%d and map21[map12[i].pos]=%d\n", i, map12[i].pos, map21[map12[i].pos].pos );
+       }
+#endif
+
+#if 0
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+//     fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+#endif
+
+#if 0
+    fprintf( stdout, "#WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+//        fprintf( stdout, "%d ", i ); 
+        for( j=0; j<lgth2; j++ )
+        {
+//          if( WMMTX[i][j] > amino_dis['a']['g'] -1 )
+                fprintf( stdout, "%d %d %8.1f", i, j, WMMTX[i][j] );
+                       if( WMMTX[i][j] == maxwm )
+                fprintf( stdout, "selected \n" );
+                       else
+                fprintf( stdout, "\n" );
+        }
+        fprintf( stdout, "\n" );
+    }
+#endif
+
+#if 0
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+#endif
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+       return( value );
+
+}
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo, float **map )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+       int alnlen;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid=0;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)RNApenalty_ex;
+#endif
+//     float fpenalty = (float)penalty;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       int lgth1, lgth2;
+       float maxwm = 0.0;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj = 0;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if 0
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+       localthr = -offset + 500; // 0?
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     if( lgth1 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 );
+//     if( lgth2 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 );
+//
+
+#if 0
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+//             fprintf( stderr, "\n\n==== jimei\n\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+#if MEMSAVE
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = mseq1[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = mseq2[i];
+#else
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+#endif
+
+//  if( lgth1 < DPTANNI && lgth2 < DPTANNI ) // & dato lgth ==1 no kanousei ga arunode yokunai 
+//    if( lgth1 < DPTANNI ) // kore mo lgth2 ga mijikasugiru kanousei ari
+    if( lgth1 < DPTANNI || lgth2 < DPTANNI ) // zettai ni anzen ka?
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+//             value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+#if MEMSAVE
+               free( aseq1 );
+               free( aseq2 );
+#else
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+#endif
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+#if LOCAL
+            if( wm < localthr )
+            {       
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               wm = 0;
+            }       
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+       firstmp = lgth1-1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if LOCAL
+            if( wm < localthr )
+            {       
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               wm = 0;
+            }       
+#endif
+
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j] += *curpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+//             WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( jmid > 0 && midn[jmid-1] > wm ) //060413
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if 0
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+                               jumpi = firstmp - 1;
+                               imid = firstmp;
+                       }
+
+#if 0
+                       else if( jmid == lgth2 ) 
+                       {
+                               fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+#else // 060414
+                       else if( jmid >= lgth2 ) 
+                       {
+//                             fprintf( stderr, "CHUI1!\n" );
+                               jumpi=imid-1; jmid=lgth2;
+                               jumpj = lgth2-1;
+                       }
+#endif
+                       else
+                       {
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+
+#if STOREWM
+//                     break;
+#else
+                       break;
+#endif
+               }
+       }
+#if 0
+               jumpi=0; jumpj=0;
+               imid=lgth1-1; jmid=lgth2-1;
+       }
+#endif
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               map[i][j] = WMMTX[i][j] / maxwm;
+//             map[i][j] = WMMTX2[i][j] / maxwm;
+
+#if STOREWM
+
+#if 0
+       for( i=0; i<lgth1; i++ )
+       {
+               float maxpairscore = -9999.9;
+               float tmpscore;
+
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( maxpairscore < (tmpscore=WMMTX[i][j]) )
+                       {
+                               map12[i].pos = j;
+                               map12[i].score = tmpscore;
+                               maxpairscore = tmpscore;
+                       }
+               }
+
+               for( k=0; k<lgth1; k++ )
+               {
+                       if( i == k ) continue;
+                       if( map12[i].score <= WMMTX[k][map12[i].pos] )
+                               break;
+               }
+               if( k != lgth1 )
+               {
+                       map12[i].pos = -1;
+                       map12[i].score = -1.0;
+               }
+               fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", i, map12[i].pos, map12[i].score, seq1[0][i], seq2[0][map12[i].pos] );
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               float maxpairscore = -9999.9;
+               float tmpscore;
+
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( maxpairscore < (tmpscore=WMMTX[i][j]) )
+                       {
+                               map21[j].pos = i;
+                               map21[j].score = tmpscore;
+                               maxpairscore = tmpscore;
+                       }
+               }
+
+               for( k=0; k<lgth2; k++ )
+               {
+                       if( j == k ) continue;
+                       if( map21[j].score <= WMMTX[map21[j].pos][k] )
+                               break;
+               }
+               if( k != lgth2 )
+               {
+                       map21[j].pos = -1;
+                       map21[j].score = -1.0;
+               }
+               fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", j, map21[j].pos, map21[j].score, seq2[0][j], seq1[0][map21[j].pos] );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               if( map12[i].pos != -1 ) if( map21[map12[i].pos].pos != i ) 
+                       fprintf( stderr, "ERROR i=%d, but map12[i].pos=%d and map21[map12[i].pos]=%d\n", i, map12[i].pos, map21[map12[i].pos].pos );
+       }
+#endif
+
+#if 0
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+//     fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       exit( 1 );
+#endif
+
+#if 0
+    fprintf( stdout, "#WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+//        fprintf( stdout, "%d ", i ); 
+        for( j=0; j<lgth2; j++ )
+        {
+//          if( WMMTX[i][j] > amino_dis['a']['g'] -1 )
+                fprintf( stdout, "%d %d %8.1f", i, j, WMMTX[i][j] );
+                       if( WMMTX[i][j] == maxwm )
+                fprintf( stdout, "selected \n" );
+                       else
+                fprintf( stdout, "\n" );
+        }
+        fprintf( stdout, "\n" );
+    }
+       exit( 1 );
+#endif
+
+#if 0
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+#endif
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+       return( value );
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+#if 0
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
+#endif
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo, map ); 
+#if 0
+               fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
+               fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
+#endif
+#if MEMSAVE
+#else
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+//             fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value +=  ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+//             fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+#if MEMSAVE
+       alnlen = strlen( aseq1[0] );
+       for( i=0; i<icyc; i++ ) aseq1[i] += alnlen;
+       for( i=0; i<jcyc; i++ ) aseq2[i] += alnlen;
+#endif
+
+#if 0
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
+#endif
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo, map );  
+#if 0
+               fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
+               fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
+#endif
+
+
+
+#if DEBUG
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f\n", value, maxwm );
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+#endif
+
+#if MEMSAVE
+#else
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       free( gaps );
+#if MEMSAVE
+       free( aseq1 );
+       free( aseq2 );
+#else
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+#endif
+       
+       return( value );
+}
+
+
+
+float Lalignmm_hmout( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *sgap1, char *sgap2, char *egap1, char *egap2, float **map )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm = 0.0;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+//     char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+//     float fpenalty;
+       float fpenalty = (float)RNApenalty;
+       int nglen1, nglen2;
+
+
+
+
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       nglen1 = seqlen( seq1[0] );
+       nglen2 = seqlen( seq2[0] );
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
+               new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
+               new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap2 );
+               new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * fpenalty;
+               fgcp1[i] = 0.5 * fpenalty;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * fpenalty;
+               fgcp2[i] = 0.5 * fpenalty;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo, map );
+#if DEBUG
+               fprintf( stderr, " seq1[0] = %s\n", seq1[0] );
+               fprintf( stderr, " seq2[0] = %s\n", seq2[0] );
+               fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
+               fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
+#endif
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if 0
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+       if( seqlen( seq1[0] ) != nglen1 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen1) seqlen(seq1[0])=%d but nglen1=%d\n", seqlen( seq1[0] ), nglen1 );
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               exit( 1 );
+       }
+       if( seqlen( seq2[0] ) != nglen2 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen2) seqlen(seq2[0])=%d but nglen2=%d\n", seqlen( seq2[0] ), nglen2 );
+               exit( 1 );
+       }
+#endif
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+
+       return( wm );
+}
+
+float Lalign2m2m_hmout( char **seq1, char **seq2, char **seq1r, char **seq2r, char *dir1, char *dir2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *sgap1, char *sgap2, char *egap1, char *egap2, float **map )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm = 0.0;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+       float fpenalty = (float)penalty;
+       int nglen1, nglen2;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       nglen1 = seqlen( seq1[0] );
+       nglen2 = seqlen( seq2[0] );
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 39 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 39 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+
+#if 0
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+#else
+       cpmx_ribosum( seq1, seq1r, dir1, cpmx1, eff1, lgth1, icyc );
+       cpmx_ribosum( seq2, seq2r, dir2, cpmx2, eff2, lgth2, jcyc );
+#endif
+
+
+#if 1
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
+               new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
+               new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap2 );
+               new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * fpenalty;
+               fgcp1[i] = 0.5 * fpenalty;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * fpenalty;
+               fgcp2[i] = 0.5 * fpenalty;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalign2m2m_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo, map );
+#if DEBUG
+               fprintf( stderr, " seq1[0] = %s\n", seq1[0] );
+               fprintf( stderr, " seq2[0] = %s\n", seq2[0] );
+               fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
+               fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
+#endif
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if 0
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+       if( seqlen( seq1[0] ) != nglen1 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen1) seqlen(seq1[0])=%d but nglen1=%d\n", seqlen( seq1[0] ), nglen1 );
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               exit( 1 );
+       }
+       if( seqlen( seq2[0] ) != nglen2 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen2) seqlen(seq2[0])=%d but nglen2=%d\n", seqlen( seq2[0] ), nglen2 );
+               exit( 1 );
+       }
+#endif
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalign11.c b/binaries/src/mafft/core/MSalign11.c
new file mode 100644 (file)
index 0000000..2991db2
--- /dev/null
@@ -0,0 +1,665 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+
+static void extendmseq( char **mseq1, char **mseq2, char **seq1, char **seq2, int i, int j, int prevhiti, int prevhitj )
+{
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       int l;
+
+       fprintf( stderr, "i=%d, prevhiti=%d\n", i, prevhiti );
+       fprintf( stderr, "j=%d, prevhitj=%d\n", j, prevhitj );
+       l = prevhiti - i - 1;
+       fprintf( stderr, "l=%d\n", l );
+       while( l>0 ) 
+       {
+               *--mseq1[0] = seq1[0][i+l--];
+               *--mseq2[0] = *gap;
+       }
+       l= prevhitj - j - 1;
+       fprintf( stderr, "l=%d\n", l );
+       while( l>0 )
+       {
+               *--mseq1[0] = *gap;
+               *--mseq2[0] = seq2[0][j+l--];
+       }
+       if( i < 0 || j < 0 ) return;
+       *--mseq1[0] = seq1[0][i];
+       *--mseq2[0] = seq2[0][j];
+       fprintf( stderr, "added %c to mseq1, mseq1 = %s \n", seq1[0][i], mseq1[0] );
+       fprintf( stderr, "added %c to mseq2, mseq2 = %s \n", seq2[0][j], mseq2[0] );
+}
+
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       char tmpc = s1[0][i1];
+       char *seq2 = s2[0];
+
+       while( lgth2-- )
+               *match++ = amino_dis[(int)tmpc][(int)*seq2++];
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = lgth1; jin = lgth2;
+       limk = lgth1+lgth2 + 1;
+       for( k=0; k<limk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+void backdp( float **WMMTX, float wmmax, float *maxinw, float *maxinh, int lgth1, int lgth2, int alloclen, float *w1, float *w2, float *initverticalw, float *m, int *mp, int iin, int jin, char **seq1, char **seq2, char **mseq1, char **mseq2 )
+{
+       register int i, j;
+       int prevhiti, prevhitj;
+//     int lasti, lastj; 
+       float g;
+       float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+       float *currentw, *previousw, *wtmp;
+       float mi;
+       int mpi;
+       int *mpjpt;
+       float *mjpt, *prept, *curpt;
+       float wm = 0.0;
+       float forwwm;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, lgth2-1, lgth1 );
+       match_calc( currentw, seq1, seq2, lgth1-1, lgth2 );
+
+
+       prevhiti = iin;
+       prevhitj = jin;
+       fprintf( stderr, "prevhiti = %d, lgth1 = %d\n", prevhiti, lgth1 );
+       fprintf( stderr, "prevhitj = %d, lgth2 = %d\n", prevhitj, lgth2 );
+       extendmseq( mseq1, mseq2, seq1, seq2, prevhiti, prevhitj, lgth1, lgth2 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+               WMMTX[i][lgth2-1] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty;
+               WMMTX[lgth1-1][j] += fpenalty;
+       }
+
+
+#if 0
+       fprintf( stderr, "initverticalw = \n" );
+       for( i=0; i<lgth1; i++ )
+               fprintf( stderr, "% 8.2f", initverticalw[i] );
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "currentw = \n" );
+       for( i=0; i<lgth2; i++ )
+               fprintf( stderr, "% 8.2f", currentw[i] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( j=lgth2-1; j>0; --j ) 
+       {
+               m[j-1] = currentw[j]; 
+               mp[j] = 0; // iranai
+       }
+
+       for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       //m[lgth2-1] ga, irunoka iranainoka irahai.
+
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[lgth2-1] = initverticalw[i+1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+
+#if 0
+               fprintf( stderr, "i=%d, currentw = \n", i );
+               for( j=0; j<lgth2; j++ ) fprintf( stderr, "% 8.2f", currentw[j] );
+               fprintf( stderr, "\n" );
+#endif
+
+               currentw[lgth2-1] = initverticalw[i];
+
+               mi = previousw[lgth2-1]; 
+               mpi = lgth2-1; //iranai
+
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+
+//                     fprintf( stderr, "i,j=%d,%d %c-%c ", i, j, seq1[0][i], seq2[0][j] );
+                       wm = *prept;
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                       }
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j+1; //iranai
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                       }
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1; //iranai
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "*curpt = %5.0f \n", *curpt );
+#endif
+
+//                     forwwm = wm + MIN( maxinw[i], maxinh[j] );
+                       forwwm = wm + MIN( maxinw[i], maxinh[j] );
+                       WMMTX[i][j] = forwwm;
+                       if( forwwm == wmmax && i<prevhiti && j<prevhitj ) 
+                       {
+                               fprintf( stderr, "hit!\n" );
+                               extendmseq( mseq1, mseq2, seq1, seq2, i, j, prevhiti, prevhitj );
+                               if( forwwm == wmmax )
+                               {
+                                       *--mseq1[0] = 'u';
+                                       *--mseq2[0] = 'u';
+                               }
+                               prevhiti = i;
+                               prevhitj = j;
+                       }
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+       }
+       extendmseq( mseq1, mseq2, seq1, seq2, -1, -1, prevhiti, prevhitj );
+}
+
+
+float MSalign11( char **seq1, char **seq2, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;
+       int iin = 0, jin = 0;  // by Mathog, a guess
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+       float *maxinw = NULL, *maxinwpt = NULL; // by D.Mathog, guess
+       float *maxinh = NULL; // by D.Mathog, guess
+#if 1
+       float wmmax;
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static float mi, *m;
+       static int **ijp;
+       static int mpi, *mp;
+       static float *w1, *w2;
+       static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static char **mseq;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **WMMTX;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+                       FreeFloatVec( maxinw );
+                       FreeFloatVec( maxinh );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+               maxinw = AllocateFloatVec( ll1+2 );
+
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+               maxinh = AllocateFloatVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+                       FreeFloatMtx( WMMTX );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+               WMMTX = AllocateFloatMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+       WMMTX[0][0] = initverticalw[0];
+
+       maxinh[0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+               WMMTX[i][0] = initverticalw[i];
+               if( maxinh[0] < initverticalw[i] ) maxinh[0] = initverticalw[i];
+       }
+       maxinw[0] = currentw[0];
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty;
+               WMMTX[0][j] = currentw[j];
+               if( maxinw[0] < currentw[j] ) maxinw[0] = currentw[j];
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       lasti = lgth1+1;
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+               maxinwpt = maxinw + i;
+               *maxinwpt = currentw[0];
+
+               fprintf( stderr, "currentw[0]  = %f, *maxinwpt = %f\n", currentw[0], maxinw[i] );
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+                       WMMTX[i][j] = *curpt;
+
+
+                       if( j<lgth2 && *maxinwpt < *curpt ) *maxinwpt = *curpt;
+                       if( j<lgth2 && maxinh[j] < *curpt ) maxinh[j] = *curpt;
+//                     fprintf( stderr, "maxintwpt = %f\n", *maxinwpt );
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+       wmmax = -999.9;
+       for( i=0; i<lgth1; i++ )
+       {
+               g = lastverticalw[i];
+               if( g > wmmax ) 
+               {
+                       wmmax = g;
+                       iin = i;
+                       jin = lgth2-1;
+               }
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               g = currentw[j];
+               if( g > wmmax )
+               {
+                       wmmax = g;
+                       iin = lgth1-1;
+                       jin = j;
+               }
+       }
+
+       for( i=0; i<lgth1; i++ )
+               fprintf( stderr, "maxinw[%d] = %f\n", i, maxinw[i] );
+       for( j=0; j<lgth2; j++ )
+               fprintf( stderr, "maxinh[%d] = %f\n", j, maxinh[j] );
+
+       fprintf( stderr, "wmmax = %f (%d,%d)\n", wmmax, iin, jin );
+       if( iin == lgth1 - 1 && jin == lgth2 - 1 )
+               ;
+       else
+               wmmax += fpenalty;
+
+       fprintf( stderr, "wmmax = %f\n", wmmax );
+
+#if 0
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+
+       backdp( WMMTX, wmmax, maxinw, maxinh, lgth1, lgth2, alloclen, w1, w2, initverticalw, m, mp, iin, jin, seq1, seq2, mseq1, mseq2 );
+
+       fprintf( stderr, "\n" );
+#if 1
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">MSres\n%s\n", mseq1[0] );
+       fprintf( stderr, ">MSres\n%s\n", mseq2[0] );
+#endif
+
+#if 0
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+
+       Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp );
+
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+#if 1
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+#endif
+
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/MSalignmm.c b/binaries/src/mafft/core/MSalignmm.c
new file mode 100644 (file)
index 0000000..474d11f
--- /dev/null
@@ -0,0 +1,1753 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MEMSAVE 1
+
+#define DEBUG 0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 100
+
+
+static TLS int reccycle = 0;
+
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+       float *matchpt;
+       float **cpmxpdpt;
+       int **cpmxpdnpt;
+       int cpkd;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#else
+       matchpt = match;
+       cpmxpdnpt = cpmxpdn;
+       cpmxpdpt = cpmxpd;
+       while( lgth2-- )
+       {
+               *matchpt = 0.0;
+               for( k=0; (cpkd=(*cpmxpdnpt)[k])>-1; k++ )
+                       *matchpt += scarr[cpkd] * (*cpmxpdpt)[k];
+               matchpt++;
+               cpmxpdnpt++;
+               cpmxpdpt++;
+       }
+#endif
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw,
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen, 
+                                               int fulllen1, int fulllen2, int tailgp )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, tailgp=%d, ien=%d, fulllen1=%d, jen=%d, fulllen2=%d\n", tailgp, ien, fulllen1, jen, fulllen2 );
+
+       if( tailgp == 1 )
+               ;
+       else if( ien == fulllen1-1 || jen == fulllen2-1 )
+       {
+//             fprintf( stderr, "searching lasthorizontalw and lasthorizontalw\n" );
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+#if 0
+       else if( jen == fulllen2-1 )
+       {
+               fprintf( stderr, "searching lastverticalw\n" );
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+       }
+       else if( ien == fulllen1-1 )
+       {
+               fprintf( stderr, "searching lasthorizontalw\n" );
+               wm = lasthorizontalw[0];
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i]+ist, gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j]+jst, gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, int fulllen1, int fulllen2, char **mseq1, char **mseq2, float **gapinfo, int headgp, int tailgp )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       int **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       int **intmtx;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+//     char **aseq1;
+//     char **aseq2;
+//     char **aseq1bk, **aseq2bk;
+
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+#if STOREWM
+       char ttt1[10000], ttt2[10000];
+#endif
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if STOREWM
+       strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+       strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+       fprintf( stderr, "ttt1 = %s\n", ttt1 );
+       fprintf( stderr, "ttt2 = %s\n", ttt2 );
+#endif
+
+#if 0
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, fulllen1=%d\n", ist, ien, fulllen1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, fulllen2=%d\n", jst, jen, fulllen2 );
+       fprintf( stderr, "in _tanni seq1[0] = %-*.*s\n", ien-ist+1, ien-ist+1, seq1[0]+ist );
+       fprintf( stderr, "in _tanni seq2[0] = %-*.*s\n", jen-jst+1, jen-jst+1, seq2[0]+jst );
+#endif
+
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+//     aseq1 = AllocateCharMtx( icyc, 0 );
+//     aseq2 = AllocateCharMtx( jcyc, 0 );
+//     aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+//     aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+//     for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+//     for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       intmtx = AllocateIntMtx( ll1+1, ll2+1 );
+
+       ijp = intmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       if( headgp || ist != 0 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+               }
+       }
+       if( headgp || jst != 0 )
+       {
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+               }
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+
+       if( tailgp || jen != fulllen2-1 ) lasti = lgth1+1; else lasti = lgth1;
+//     if( 1 ) lasti = lgth1+1; else lasti = lgth1;
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+//             if( tailgp && jen != fulllen2-1 ) lastj = lgth2+1; else lastj = lgth2;
+               lastj = lgth2+1; 
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, ijp, icyc, jcyc, ist, ien, jst, jen, fulllen1, fulllen2, tailgp );
+#if 0
+       fprintf( stderr, "res in _tanni mseq1[0] = %s\n", mseq1[0] );
+       fprintf( stderr, "res in _tanni mseq2[0] = %s\n", mseq2[0] );
+#endif
+
+//     for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+//     for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeIntMtx( intmtx );
+
+
+//     FreeCharMtx( aseq1bk );
+//     FreeCharMtx( aseq2bk );
+
+//     free( aseq1 );
+//     free( aseq2 );
+
+       return( wm );
+
+}
+
+static void freearrays_rec1(
+       float *w1, float *w2, float *initverticalw, float *lastverticalw,
+       float *midw, float *midm, float *midn,
+       int *jumpbacki, int *jumpbackj, int *jumpforwi, int *jumpforwj, int *jumpdummi, int *jumpdummj,
+       float *m, int *mp,
+       float **floatwork, int **intwork
+#if STOREWM
+       , float **WMMTX, float **WMMTX2
+#endif
+)
+{
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+}
+
+static void freearrays_rec2( char *gaps, char **aseq1, char **aseq2 )
+{
+       free( gaps );
+#if MEMSAVE
+       free( aseq1 );
+       free( aseq2 );
+#else
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+#endif
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, int fulllen1, int fulllen2, char **mseq1, char **mseq2, int depth, float **gapinfo, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int alnlen;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid;
+       int jmid = 0; // by D.Mathog, a guess
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj = NULL; // by D.Mathog, a guess
+       int jumpi, jumpj = 0; // by D.Mathog, a guess
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if STOREWM
+       static TLS char ttt1[50000];
+       static TLS char ttt2[50000];
+#endif
+
+#if 0
+       int nglen1, nglen2;
+       nglen1 = seqlen( seq1[0] );
+       nglen2 = seqlen( seq2[0] );
+#endif
+
+//     fprintf( stderr, "fulllen1 = %d, fulllen2 = %d, headgp = %d, tailgp = %d\n", fulllen1, fulllen2, headgp, tailgp );
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     if( lgth1 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth1 = %d\n", lgth1 );
+//     if( lgth2 < 5 )
+//             fprintf( stderr, "\nWARNING: lgth2 = %d\n", lgth2 );
+//
+
+
+#if STOREWM
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+//             fprintf( stderr, "\n\n==== jimei\n\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+#if MEMSAVE
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = mseq1[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = mseq2[i];
+#else
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+#endif
+
+//     fprintf( stderr, "####(s) seq1[0] (%d) = \n%-*.*s\n (a%d-a%d)\n", depth, ien-ist+1, ien-ist+1, seq1[0]+ist, ist, ien );
+//     fprintf( stderr, "####(s) seq2[0] (%d) = \n%-*.*s\n (b%d-b%d)\n", depth, jen-jst+1, jen-jst+1, seq2[0]+jst, jst, jen );
+
+//  if( lgth1 < DPTANNI && lgth2 < DPTANNI ) // & dato lgth ==1 no kanousei ga arunode yokunai 
+//    if( lgth1 < DPTANNI ) // kore mo lgth2 ga mijikasugiru kanousei ari
+    if( lgth1 < DPTANNI || lgth2 < DPTANNI ) // zettai ni anzen ka?
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, fulllen1, fulllen2, aseq1, aseq2, gapinfo, headgp, tailgp );   
+
+
+#if MEMSAVE
+               free( aseq1 );
+               free( aseq2 );
+#else
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+#endif
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+#ifdef enablemultithread
+//             fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+               if( chudanpt && *chudanpt != chudanref ) 
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! zenhan\n" );
+                       *chudanres = 1;
+                       freearrays_rec1
+                       (
+                               w1, w2, initverticalw, lastverticalw, midw, midm, midn,
+                               jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj,
+                               m, mp,
+                               floatwork, intwork
+#if STOREWM
+                               , WMMTX, WMMTX2
+#endif
+                       );
+                       freearrays_rec2( gaps, aseq1, aseq2 );
+                       return( -1.0 );
+               }
+#endif
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += ( fgcp2[lgth2-1] + ogcp2[j+1] );
+               fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+//     firstmp = lgth1-1;
+       firstmp = lgth1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+#ifdef enablemultithread
+//             fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+               if( chudanpt && *chudanpt != chudanref ) 
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! kouhan\n" );
+                       *chudanres = 1;
+                       freearrays_rec1
+                       (
+                               w1, w2, initverticalw, lastverticalw, midw, midm, midn,
+                               jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj,
+                               m, mp,
+                               floatwork, intwork
+#if STOREWM
+                               , WMMTX, WMMTX2
+#endif
+                       );
+                       freearrays_rec2( gaps, aseq1, aseq2 );
+                       return( -1.0 );
+               }
+#endif
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j+1] += *mjpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+               WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( jmid > 0 && midn[jmid-1] > wm ) //060413
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if STOREWM
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "#### FIRST i=%d, jumpi<imid=%d<%d, ist=%d, ien=%d, firstmp=%d, lgth1=%d\n", i, jumpi, imid, ist, ien, firstmp, lgth1 );
+//                     fprintf( stderr, "#### mark 1\n" );
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "#### CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+#if 0 // v6.823 made
+                               jumpi = firstmp-1;
+                               imid = firstmp;
+#endif
+#if 0
+                               jumpi = 0;
+                               imid = 1;
+#else
+//                             if( 1 || firstmp > 100 ) // naze 100
+                               if( imid < firstmp-1 ) // naze 100
+                               {
+                                       jumpi = firstmp;
+                                       imid = firstmp+1;
+                               }
+#if 0
+                               else
+                               {
+                                       jumpi = 0;
+                                       imid = 1;
+                               }
+#endif
+#endif
+                       }
+
+#if 0
+                       else if( jmid == lgth2 ) 
+                       {
+                               fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+#else // 060414
+                       else if( jmid >= lgth2 ) 
+                       {
+//                             fprintf( stderr, "CHUI1!\n" );
+                               jumpi=imid-1; jmid=lgth2;
+                               jumpj = lgth2-1;
+                       }
+#endif
+                       else
+                       {
+//                             fprintf( stderr, "#### CHUI3!\n" );
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                               if( imid == jumpi ) jumpi = imid-1;
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+//                     fprintf( stderr, "#### FINAL i=%d, jumpi<imid=%d<%d, ist=%d, ien=%d, firstmp=%d\n", i, jumpi, imid, ist, ien, firstmp );
+
+#if STOREWM
+                       break;
+#else
+                       break;
+#endif
+               }
+       }
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if STOREWM
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+//     fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+       freearrays_rec1
+       (
+               w1, w2, initverticalw, lastverticalw, midw, midm, midn,
+               jumpbacki, jumpbackj, jumpforwi, jumpforwj, jumpdummi, jumpdummj,
+               m, mp,
+               floatwork, intwork
+#if STOREWM
+               , WMMTX, WMMTX2
+#endif
+       );
+
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, fulllen1, fulllen2, aseq1, aseq2, depth, gapinfo, NULL, 0, NULL, headgp, tailgp ); // chudan mada    
+#if 0
+               fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
+               fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
+#endif
+#if MEMSAVE
+#else
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+//             fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value +=  ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+//             fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+#if MEMSAVE
+       alnlen = strlen( aseq1[0] );
+       for( i=0; i<icyc; i++ ) aseq1[i] += alnlen;
+       for( i=0; i<jcyc; i++ ) aseq2[i] += alnlen;
+#endif
+
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, fulllen1, fulllen2, aseq1, aseq2, depth, gapinfo, NULL, 0, NULL, headgp, tailgp ); // chudan mada
+#if 0
+               fprintf( stderr, "aseq1[0] = %s\n", aseq1[0] );
+               fprintf( stderr, "aseq2[0] = %s\n", aseq2[0] );
+#endif
+
+
+
+#if DEBUG
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f\n", value, maxwm );
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+#endif
+
+#if MEMSAVE
+#else
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = \n%s\n (a%d-a%d)\n", depth, mseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = \n%s\n (b%d-b%d)\n", depth, mseq2[0], jst, jen );
+
+       freearrays_rec2( gaps, aseq1, aseq2 );
+
+#if 0
+       if( seqlen( seq1[0] ) != nglen1 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen1) seqlen(seq1[0])=%d but nglen1=%d\n", seqlen( seq1[0] ), nglen1 );
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               exit( 1 );
+       }
+       else
+               fprintf( stderr, "nglen1 is ok in _rec\n" );
+       if( seqlen( seq2[0] ) != nglen2 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen2) seqlen(seq2[0])=%d but nglen2=%d\n", seqlen( seq2[0] ), nglen2 );
+               exit( 1 );
+       }
+       else
+               fprintf( stderr, "nglen2 is ok in _rec\n" );
+#endif
+
+       return( value );
+}
+
+static void freearrays( 
+       float *ogcp1, 
+       float *ogcp2, 
+       float *fgcp1, 
+       float *fgcp2, 
+       float **cpmx1,
+       float **cpmx2, 
+       float **gapinfo, 
+       char **mseq1, 
+       char **mseq2 
+)
+{
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+}
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm = 0.0;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+       float fpenalty = (float)penalty;
+       int nglen1, nglen2;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       nglen1 = seqlen( seq1[0] );
+       nglen2 = seqlen( seq2[0] );
+
+#if 0
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "seq1[%d] at root = %s\n", i, seq1[i] );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "seq2[%d] at root = %s\n", j, seq2[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(lgth1) ) + 100;
+       ll2 = ( (int)(lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "bug! hairetsu ga kowareta!\n" );
+                       exit( 1 );
+               }
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
+               new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
+               new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap2 );
+               new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * fpenalty;
+               fgcp1[i] = 0.5 * fpenalty;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * fpenalty;
+               fgcp2[i] = 0.5 * fpenalty;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, lgth1, lgth2, mseq1, mseq2, 0, gapinfo, chudanpt, chudanref, chudanres, headgp, tailgp );
+#ifdef enablemultithread
+       if( chudanres && *chudanres ) 
+       {
+//             fprintf( stderr, "\n\n## CHUUDAN!!! relay\n" );
+               *chudanres = 1;
+               freearrays( ogcp1, ogcp2, fgcp1, fgcp2, cpmx1, cpmx2, gapinfo, mseq1, mseq2 );
+               return( -1.0 );
+       }
+#endif
+
+#if DEBUG
+               fprintf( stderr, " seq1[0] = %s\n", seq1[0] );
+               fprintf( stderr, " seq2[0] = %s\n", seq2[0] );
+               fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
+               fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
+#endif
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+       if( seqlen( seq1[0] ) != nglen1 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen1) seqlen(seq1[0])=%d but nglen1=%d\n", seqlen( seq1[0] ), nglen1 );
+               fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+               exit( 1 );
+       }
+       if( seqlen( seq2[0] ) != nglen2 )
+       {
+               fprintf( stderr, "bug! hairetsu ga kowareta! (nglen2) seqlen(seq2[0])=%d but nglen2=%d\n", seqlen( seq2[0] ), nglen2 );
+               exit( 1 );
+       }
+
+
+       freearrays( ogcp1, ogcp2, fgcp1, fgcp2, cpmx1, cpmx2, gapinfo, mseq1, mseq2 );
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       for( i=0; i<icyc; i++ ) 
+       {
+               if( strlen( seq1[i] ) != lgth1 )
+               {
+                       fprintf( stderr, "i = %d / %d\n", i, icyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               if( strlen( seq2[j] ) != lgth2 )
+               {
+                       fprintf( stderr, "j = %d / %d\n", j, jcyc );
+                       fprintf( stderr, "hairetsu ga kowareta (end of MSalignmm) !\n" );
+                       exit( 1 );
+               }
+       }
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.algAa b/binaries/src/mafft/core/MSalignmm.c.algAa
new file mode 100644 (file)
index 0000000..7b25b75
--- /dev/null
@@ -0,0 +1,1295 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 1000
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+//             totaleff+= eff[j];
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
+//             ogcp[i] /= totaleff;
+//     }
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len+1; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len+1; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+//             totaleff += eff[j];
+//             fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fgcp[i] /= totaleff;
+//             fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
+//     }
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       char **aseq1;
+       char **aseq2;
+       char **aseq1bk, **aseq2bk;
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+//     char ttt1[10000], ttt2[10000];
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+//     strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+//
+//     fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+//     fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+//     fprintf( stderr, "ttt1 = %s\n", ttt1 );
+//     fprintf( stderr, "ttt2 = %s\n", ttt2 );
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       free( aseq1 );
+       free( aseq2 );
+
+       return( wm );
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+//     float **WMMTX;
+//     float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+//     float *ogcp1 = gapinfo[0];
+//     float *fgcp1 = gapinfo[1];
+//     float *ogcp2 = gapinfo[2];
+//     float *fgcp2 = gapinfo[3];
+//     static char ttt1[50000];
+//     static char ttt2[50000];
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+//     strncpy( ttt1, seq1[0]+ist, lgth1 );
+//     strncpy( ttt2, seq2[0]+jst, lgth2 );
+//     ttt1[lgth1] = 0;
+//     ttt2[lgth2] = 0;
+//     fprintf( stderr, "seq1 = %s\n", ttt1 );
+//     fprintf( stderr, "seq2 = %s\n", ttt2 );
+       if( lgth2 <= 0 )
+       {
+               fprintf( stderr, "==== jimei\n" );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( (float)offset * lgth1 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );  
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+               return( wm );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+//             initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+               initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+//             currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+               currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+//             m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+               m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 / 2;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+//     for( i=1; i<lasti; i++ )
+       for( i=1; i<=imid; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+
+//             mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mi = previousw[0];
+               mpi = 0;
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+//                     *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+//                     g = *prept + fpenalty * ogcp2[j];
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     g = *mjpt + fpenalty  * fgcp1[i-1];
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+//                     g = *prept + fpenalty * ogcp1[i];
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+//             initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+//             currentw[j] += fpenalty * ( fgcp2[lgth1-1] + ogcp2[j+1] );
+               currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty;
+       }
+#endif
+
+       for( j=lgth2-1; j>0; --j )
+       {
+//             m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+               m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+               mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+//                     g = mi + fpenalty * ogcp2[j+1];
+                       g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                       }
+
+//                     g = *prept + fpenalty + fgcp2[j];
+                       g = *prept;
+                       if( g > mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+//                     g = *mjpt + fpenalty * ogcp1[i+1];
+                       g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+//                     g = *prept + fpenalty * fgcp1[i];
+                       g = *prept;
+                       if( g > *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+                               midm[j+1] += *mjpt + fpenalty; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+                               midn[j] += mi + fpenalty;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+                       WMMTX2[i][j+1] += *mjpt + fpenalty;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 1;
+                       for( j=2; j<lgth2; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+                       }
+//                     fprintf( stderr, "imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       {
+                               jumpi = imid-1;
+                               jumpj = jmid-1;
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                       }
+                       if( midn[jmid-1] >= wm )
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                       }
+#if 0
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       imid = jumpforwi[jumpj];
+                       jmid = jumpforwj[jumpj];
+//                     fprintf( stderr, "imid -> %d\n", imid );
+//                     fprintf( stderr, "jmid -> %d\n", jmid );
+                       break;
+               }
+       }
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if 0
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+#if DEBUG
+       fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
+       fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );        
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+//     fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//     fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+       free( gaps );
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( wm );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               seq2[j][lgth2] = 0;
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+       OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 1.0;
+               fgcp1[i] = 1.0;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 1.0;
+               fgcp2[i] = 1.0;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.algLargeA b/binaries/src/mafft/core/MSalignmm.c.algLargeA
new file mode 100644 (file)
index 0000000..fd77355
--- /dev/null
@@ -0,0 +1,1461 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 1000
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+//             gc = ( gappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
+//     }
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+//             gc = ( seq[j][0] == '-' );
+               gc = 0;
+               for( i=1; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) 
+                               {
+                                       fgcp[i-1] += feff;
+                               }
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+                       {
+//                             fprintf( stderr, "changed gc=%d, gb=%d\n", gc, gb );
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+//             fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
+//     }
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       char **aseq1;
+       char **aseq2;
+       char **aseq1bk, **aseq2bk;
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+#if STOREWM
+       char ttt1[10000], ttt2[10000];
+#endif
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if STOREWM
+       strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+       strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+       fprintf( stderr, "ttt1 = %s\n", ttt1 );
+       fprintf( stderr, "ttt2 = %s\n", ttt2 );
+#endif
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       free( aseq1 );
+       free( aseq2 );
+
+       return( wm );
+
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if STOREWM
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+
+#if STOREWM
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+               fprintf( stderr, "\n\n==== jimei\n\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+               fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+               fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = fpenalty * ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty  * fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + fpenalty * ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+               fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+       firstmp = lgth1-1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fpenalty * fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + fpenalty * ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fpenalty * fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty * ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fpenalty * fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j+1] += *mjpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fpenalty * fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+               WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( midn[jmid-1] > wm )
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if STOREWM
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+                               jumpi = firstmp - 1;
+                               imid = firstmp;
+                       }
+                       else if( jmid == lgth2 )
+                       {
+//                             fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+                       else
+                       {
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+
+#if STOREWM
+                       break;
+#else
+                       break;
+#endif
+               }
+       }
+#if 0
+               jumpi=0; jumpj=0;
+               imid=lgth1-1; jmid=lgth2-1;
+       }
+#endif
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if STOREWM
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+//     fprintf( stderr, "jumpi = %d\n", jumpi );
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+//             fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value += fpenalty * ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+//             fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += fpenalty * ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );       
+
+
+
+#if DEBUG
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f penalty = %f\n", value, maxwm, fpenalty );
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+#endif
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       free( gaps );
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( value );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               seq2[j][lgth2] = 0;
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5;
+               fgcp1[i] = 0.5;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5;
+               fgcp2[i] = 0.5;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.alga b/binaries/src/mafft/core/MSalignmm.c.alga
new file mode 100644 (file)
index 0000000..598e957
--- /dev/null
@@ -0,0 +1,1461 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 1000
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+//             gc = ( gappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
+//     }
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+//             gc = ( seq[j][0] == '-' );
+               gc = 0;
+               for( i=1; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) 
+                               {
+                                       fgcp[i-1] += feff;
+                               }
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+                       {
+//                             fprintf( stderr, "changed gc=%d, gb=%d\n", gc, gb );
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+//             fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
+//     }
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       char **aseq1;
+       char **aseq2;
+       char **aseq1bk, **aseq2bk;
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+#if STOREWM
+       char ttt1[10000], ttt2[10000];
+#endif
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if STOREWM
+       strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+       strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+       fprintf( stderr, "ttt1 = %s\n", ttt1 );
+       fprintf( stderr, "ttt2 = %s\n", ttt2 );
+#endif
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       free( aseq1 );
+       free( aseq2 );
+
+       return( wm );
+
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if STOREWM
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+
+#if STOREWM
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+               fprintf( stderr, "==== jimei\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+               fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+               fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = fpenalty * ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty  * fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + fpenalty * ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+               fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+       firstmp = lgth1-1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fpenalty * fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + fpenalty * ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fpenalty * fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty * ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fpenalty * fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j+1] += *mjpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fpenalty * fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+               WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( midn[jmid-1] > wm )
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if STOREWM
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+                               jumpi = firstmp - 1;
+                               imid = firstmp;
+                       }
+                       else if( jmid == lgth2 )
+                       {
+//                             fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+                       else
+                       {
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+
+#if STOREWM
+                       break;
+#else
+                       break;
+#endif
+               }
+       }
+#if 0
+               jumpi=0; jumpj=0;
+               imid=lgth1-1; jmid=lgth2-1;
+       }
+#endif
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if STOREWM
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+//     fprintf( stderr, "jumpi = %d\n", jumpi );
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+//             fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value += fpenalty * ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+//             fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += fpenalty * ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );       
+
+
+
+#if DEBUG
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f penalty = %f\n", value, maxwm, fpenalty );
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+#endif
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       free( gaps );
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( value );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               seq2[j][lgth2] = 0;
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5;
+               fgcp1[i] = 0.5;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5;
+               fgcp2[i] = 0.5;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.algsmalla b/binaries/src/mafft/core/MSalignmm.c.algsmalla
new file mode 100644 (file)
index 0000000..d19d68a
--- /dev/null
@@ -0,0 +1,1264 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 50
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       float totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = 0;
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += eff[j];
+                       }
+               }
+               totaleff+= eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               ogcp[i] /= totaleff;
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       float totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len+1; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += eff[j];
+                       }
+               }
+               totaleff += eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               fgcp[i] /= totaleff;
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float *gapinfo[4]  )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1 = gapinfo[0];
+       float *fgcp1 = gapinfo[1];
+       float *ogcp2 = gapinfo[2];
+       float *fgcp2 = gapinfo[3];
+       static char **aseq1 = NULL;
+       static char **aseq2 = NULL;
+       static char **aseq1bk, **aseq2bk;
+
+//     char ttt1[10000], ttt2[10000];
+
+       if( !aseq1 )
+       {
+               aseq1 = AllocateCharMtx( njob, 0 );
+               aseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+//     strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+//
+//     fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+//     fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+//     fprintf( stderr, "ttt1 = %s\n", ttt1 );
+//     fprintf( stderr, "ttt2 = %s\n", ttt2 );
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+       Atracking( currentw, lastverticalw, seq1, seq2, aseq1, aseq2, cpmx1+ist, cpmx2+jst, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       return( wm );
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float *gapinfo[4] )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+//     float **WMMTX;
+//     float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+//     float *ogcp1 = gapinfo[0];
+//     float *fgcp1 = gapinfo[1];
+//     float *ogcp2 = gapinfo[2];
+//     float *fgcp2 = gapinfo[3];
+//     static char ttt1[50000];
+//     static char ttt2[50000];
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+//     strncpy( ttt1, seq1[0]+ist, lgth1 );
+//     strncpy( ttt2, seq2[0]+jst, lgth2 );
+//     ttt1[lgth1] = 0;
+//     ttt2[lgth2] = 0;
+//     fprintf( stderr, "seq1 = %s\n", ttt1 );
+//     fprintf( stderr, "seq2 = %s\n", ttt2 );
+       if( lgth2 <= 0 )
+       {
+               fprintf( stderr, "==== jimei\n" );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( (float)offset * lgth1 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );  
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+               return( wm );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+//             initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+               initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+//             currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+               currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+//             m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+               m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 / 2;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+//     for( i=1; i<lasti; i++ )
+       for( i=1; i<=imid; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+
+//             mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mi = previousw[0];
+               mpi = 0;
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+//                     *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+//                     g = *prept + fpenalty * ogcp2[j];
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     g = *mjpt + fpenalty  * fgcp1[i-1];
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+//                     g = *prept + fpenalty * ogcp1[i];
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+//             initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+//             currentw[j] += fpenalty * ( fgcp2[lgth1-1] + ogcp2[j+1] );
+               currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty;
+       }
+#endif
+
+       for( j=lgth2-1; j>0; --j )
+       {
+//             m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+               m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+               mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+//                     g = mi + fpenalty * ogcp2[j+1];
+                       g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                       }
+
+//                     g = *prept + fpenalty + fgcp2[j];
+                       g = *prept;
+                       if( g > mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+//                     g = *mjpt + fpenalty * ogcp1[i+1];
+                       g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+//                     g = *prept + fpenalty * fgcp1[i];
+                       g = *prept;
+                       if( g > *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+                               midm[j+1] += *mjpt + fpenalty; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+                               midn[j] += mi + fpenalty;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+                       WMMTX2[i][j+1] += *mjpt + fpenalty;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 1;
+                       for( j=2; j<lgth2; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+                       }
+//                     fprintf( stderr, "imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       {
+                               jumpi = imid-1;
+                               jumpj = jmid-1;
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                       }
+                       if( midn[jmid-1] >= wm )
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                       }
+#if 0
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 10.2f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       imid = jumpforwi[jumpj];
+                       jmid = jumpforwj[jumpj];
+//                     fprintf( stderr, "imid -> %d\n", imid );
+//                     fprintf( stderr, "jmid -> %d\n", jmid );
+                       break;
+               }
+       }
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if 0
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+#if DEBUG
+       fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
+       fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );        
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+//     fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//     fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+       free( gaps );
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( wm );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       static char **mseq1 = NULL;
+       static char **mseq2 = NULL;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float *gapinfo[4];
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( mseq1 == NULL )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 26 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 26 );
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+#if 1
+       OpeningGapCount( ogcp1, icyc, seq1, eff1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2 );
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+       }
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+
+       FreeCharMtx( mseq );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.back b/binaries/src/mafft/core/MSalignmm.c.back
new file mode 100644 (file)
index 0000000..04fa17b
--- /dev/null
@@ -0,0 +1,939 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 1
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+
+#define DPTANNI 100
+
+static void OpeningGapCount( double *ogcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       double totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = 0;
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += eff[j];
+                       }
+               }
+               totaleff+= eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               ogcp[i] /= totaleff;
+}
+
+static void FinalGapCount( double *fgcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       double totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len+1; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += eff[j];
+                       }
+               }
+               totaleff += eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               fgcp[i] /= totaleff;
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+               fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+       fprintf( stderr, "in Atracking (owari), mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2  )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float **WMMTX;
+       float dumfl;
+       int lgth1, lgth2;
+       static char **aseq1 = NULL;
+       static char **aseq2 = NULL;
+       static char **aseq1bk, **aseq2bk;
+
+       if( !aseq1 )
+       {
+               aseq1 = AllocateCharMtx( icyc, 0 );
+               aseq2 = AllocateCharMtx( jcyc, 0 );
+       }
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+       fprintf( stderr, "seq1[0]+ist = %s\n", seq1[0]+ist );
+       fprintf( stderr, "seq2[0]+jst = %s\n", seq2[0]+jst );
+
+       fprintf( stderr, "ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+       match = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       fprintf( stderr, "calling match_calc\n" );
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty;
+               WMMTX[0][j] = currentw[j];
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1];
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       fprintf( stderr, "entering to loop\n" );
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               fprintf( stderr, "i=%d\n", i );
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               fprintf( stderr, "calling match_calc, ist=%d, lgth2=%d\n", ist, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               fprintf( stderr, "done\n" );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       fprintf( stderr, "j=%d\n", j );
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+                       WMMTX[i][j] = *curpt;
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+                       fprintf( stderr, "j=%d end\n", j );
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+               fprintf( stderr, "i=%d end\n", i );
+       }
+
+#if 1
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+       Atracking( currentw, lastverticalw, seq1, seq2, aseq1, aseq2, cpmx1+ist, cpmx2+jst, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+       fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+       fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( match );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+       FreeFloatMtx( WMMTX );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       return( wm );
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float **WMMTX;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+
+       depth++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+       fprintf( stderr, "==== MSalign (%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, ist, ien, jst, jen );
+       if( lgth2 <= 0 )
+       {
+               fprintf( stderr, "==== Jimei\n" );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+               fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+               fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( (float)offset * lgth1 );
+       }
+
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI )
+       {
+               fprintf( stderr, "==== Going to _tanni\n" );
+               wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2 );   
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+               fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+               fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+               return( wm );
+       }
+       fprintf( stderr, "Trying to divide the mtx\n" );
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+       match = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+
+#if DEBUG
+       fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty;
+               WMMTX[0][j] = currentw[j];
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1];
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 / 2;
+
+       lasti = lgth1+1;
+//     for( i=1; i<lasti; i++ )
+       for( i=1; i<=imid; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+                       WMMTX[i][j] = *curpt;
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+               WMMTX[i][lgth2-1] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty;
+               WMMTX[lgth1-1][j] += fpenalty;
+       }
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j];
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+       for( i=lgth1-2; i>=imid; i-- )
+//     for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+               mi = previousw[lgth2-1];
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       g = mi + fpenalty;
+                       if( g > wm ) wm = g;
+
+                       g = *prept;
+                       if( g >= mi ) mi = g;
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty;
+                       if( g > wm ) wm = g;
+
+                       g = *prept;
+                       if( g >= *mjpt ) *mjpt = g;
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       WMMTX[i][j] += wm;
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+       }
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+#endif
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+       maxwm = -999999999.9;
+       jmid = -100;
+       for( j=0; j<lgth2; j++ )
+       {
+               wm = WMMTX[imid][j];
+               if( wm > maxwm )
+               {
+                       jmid = j;
+                       maxwm = wm;
+               }
+       }
+       // gap no tochu de kirrareru kanousei ari.
+
+       fprintf( stderr, "wm = %f\n", wm );
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( match );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+       FreeFloatMtx( WMMTX );
+
+
+       fprintf( stderr, "==== calling myself (first)\n" );
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+imid, jst, jst+jmid, alloclen, aseq1, aseq2, depth ); 
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+       fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+       fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+
+       fprintf( stderr, "==== calling myself (second)\n" );
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid+1, ien, jst+jmid+1, jen, alloclen, aseq1, aseq2, depth );     
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+       fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+       fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+       fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( wm );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       static char **mseq1 = NULL;
+       static char **mseq2 = NULL;
+       char **mseq;
+       double *ogcp1;
+       double *ogcp2;
+       double *fgcp1;
+       double *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+
+#if 1
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( mseq1 == NULL )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+       ogcp1 = AllocateDoubleVec( ll1+2 );
+       ogcp2 = AllocateDoubleVec( ll2+2 );
+       fgcp1 = AllocateDoubleVec( ll1+2 );
+       fgcp2 = AllocateDoubleVec( ll2+2 );
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 26 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 26 );
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc );
+
+#if 0
+       OpeningGapCount( ogcp1, icyc, seq1, eff1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2 );
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 1.0 - ogcp1[i];
+               fgcp1[i] = 1.0 - fgcp1[i];
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 1.0 - ogcp2[i];
+               fgcp2[i] = 1.0 - fgcp2[i];
+       }
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0 );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeDoubleVec( ogcp1 );
+       FreeDoubleVec( ogcp2 );
+       FreeDoubleVec( fgcp1 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       FreeDoubleVec( fgcp2 );
+
+       FreeCharMtx( mseq );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.bkbk b/binaries/src/mafft/core/MSalignmm.c.bkbk
new file mode 100644 (file)
index 0000000..10621be
--- /dev/null
@@ -0,0 +1,1410 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 10
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+//             gc = ( gappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
+//     }
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+//             gc = ( seq[j][0] == '-' );
+               gc = 0;
+               for( i=1; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) 
+                               {
+                                       fgcp[i-1] += feff;
+                               }
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+                       {
+//                             fprintf( stderr, "changed gc=%d, gb=%d\n", gc, gb );
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+//             fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
+//     }
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       char **aseq1;
+       char **aseq2;
+       char **aseq1bk, **aseq2bk;
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+#if STOREWM
+       char ttt1[10000], ttt2[10000];
+#endif
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if STOREWM
+       strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+       strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+       fprintf( stderr, "ttt1 = %s\n", ttt1 );
+       fprintf( stderr, "ttt2 = %s\n", ttt2 );
+#endif
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       free( aseq1 );
+       free( aseq2 );
+
+       return( wm );
+
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+#if STOREWM
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+
+#if STOREWM
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 )
+       {
+               fprintf( stderr, "==== jimei\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( (float)offset * lgth1 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty  * fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + fpenalty * ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+               fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+               mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + fpenalty * ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                       }
+
+                       g = *prept + fpenalty * fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty * ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fpenalty * fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j+1] += *mjpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                                       jumpi = imid-1;
+                                       jumpj = jmid-1;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=1; j<lgth2; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                                       jumpi = jumpbackj[jmid];
+                                       jumpj = jmid-1;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=2; j<lgth2; j++ )
+                       {
+                               wm = midn[j-1];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j-1;
+                                       maxwm = wm;
+                                       jumpi = imid-1;
+                                       jumpj = jumpbacki[jmid];
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+                       if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+#if 0
+                       fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( midn[jmid-1] > wm )
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+                               fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+                               fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+#endif
+
+                       fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+                       fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if STOREWM
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       imid = jumpforwi[jumpj];
+                       jmid = jumpforwj[jumpj];
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#if STOREWM
+#else
+                       break;
+#endif
+               }
+       }
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if STOREWM
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+       fprintf( stderr, "jumpi = %d\n", jumpi );
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+               fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value += fpenalty * ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+               fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += fpenalty * ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );       
+
+
+
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f penalty = %f\n", value, maxwm, fpenalty );
+#if 1
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+#endif
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       free( gaps );
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( value );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               seq2[j][lgth2] = 0;
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5;
+               fgcp1[i] = 0.5;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5;
+               fgcp2[i] = 0.5;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.bug b/binaries/src/mafft/core/MSalignmm.c.bug
new file mode 100644 (file)
index 0000000..6dbc2cc
--- /dev/null
@@ -0,0 +1,1492 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MEMSAVE 1
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define STOREWM 0
+
+#define DPTANNI 1000
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+//             gc = ( gappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "ogcp[%d] = %30.20f\n", i, ogcp[i] );
+//     }
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+//             gc = ( seq[j][0] == '-' );
+               gc = 0;
+               for( i=1; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) 
+                               {
+                                       fgcp[i-1] += feff;
+                               }
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+                       {
+//                             fprintf( stderr, "changed gc=%d, gb=%d\n", gc, gb );
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+//             fprintf( stderr, "eff[%d] = %30.20f\n", j, eff[j] );
+       }
+//     for( i=0; i<len; i++ ) 
+//     {
+//             fprintf( stderr, "fgcp[%d] = %30.20f\n", i, fgcp[i] );
+//     }
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       char **aseq1;
+       char **aseq2;
+       char **aseq1bk, **aseq2bk;
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+#if STOREWM
+       char ttt1[10000], ttt2[10000];
+#endif
+
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if STOREWM
+       strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+       strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+       fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+       fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+       fprintf( stderr, "ttt1 = %s\n", ttt1 );
+       fprintf( stderr, "ttt2 = %s\n", ttt2 );
+#endif
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 27 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       Atracking( seq1, seq2, aseq1, aseq2, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       free( aseq1 );
+       free( aseq2 );
+
+       return( wm );
+
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float **gapinfo )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int alnlen;
+       float value = 0.0;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+#if STOREWM
+       float **WMMTX;
+       float **WMMTX2;
+#endif
+       float *midw;
+       float *midm;
+       float *midn;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforwi;
+       int *jumpforwj;
+       int *jumpbacki;
+       int *jumpbackj;
+       int *jumpdummi; //muda
+       int *jumpdummj; //muda
+       int jumpi, jumpj;
+       char *gaps;
+       int ijpi, ijpj;
+       float *ogcp1;
+       float *fgcp1;
+       float *ogcp2;
+       float *fgcp2;
+       float firstm;
+       int firstmp;
+#if STOREWM
+       static char ttt1[50000];
+       static char ttt2[50000];
+#endif
+
+       ogcp1 = gapinfo[0] + ist;
+       fgcp1 = gapinfo[1] + ist;
+       ogcp2 = gapinfo[2] + jst;
+       fgcp2 = gapinfo[3] + jst;
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+
+#if STOREWM
+       fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+       strncpy( ttt1, seq1[0]+ist, lgth1 );
+       strncpy( ttt2, seq2[0]+jst, lgth2 );
+       ttt1[lgth1] = 0;
+       ttt2[lgth2] = 0;
+       fprintf( stderr, "seq1 = %s\n", ttt1 );
+       fprintf( stderr, "seq2 = %s\n", ttt2 );
+#endif
+       if( lgth2 <= 0 ) // lgth1 <= 0 ha?
+       {
+//             fprintf( stderr, "\n\n==== jimei\n\n" );
+//             exit( 1 );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( 0.0 );
+       }
+
+#if MEMSAVE
+       aseq1 = AllocateCharMtx( icyc, 0 );
+       aseq2 = AllocateCharMtx( jcyc, 0 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = mseq1[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = mseq2[i];
+#else
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+#endif
+
+       if( lgth1 < DPTANNI || lgth2 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               value = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );       
+
+
+#if MEMSAVE
+#else
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+#endif
+
+//             fprintf( stderr, "value = %f\n", value );
+
+               return( value );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midn = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpbacki = AllocateIntVec( ll2+2 );
+       jumpbackj = AllocateIntVec( ll2+2 );
+       jumpforwi = AllocateIntVec( ll2+2 );
+       jumpforwj = AllocateIntVec( ll2+2 );
+       jumpdummi = AllocateIntVec( ll2+2 );
+       jumpdummj = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if STOREWM
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty  * ( ogcp1[0] + fgcp1[i-1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               WMMTX[0][j] = currentw[j];
+       }
+#endif
+
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1];
+//             m[j] = currentw[j-1];
+               mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 * 0.5;
+
+       jumpi = 0; // atode kawaru.
+       lasti = lgth1+1;
+#if STOREWM
+       for( i=1; i<lasti; i++ )
+#else
+       for( i=1; i<=imid; i++ )
+#endif
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               m[0] = fpenalty * ogcp1[i];
+#if STOREM
+               WMMTX2[i][0] = m[0];
+#endif
+               if( i == imid ) midm[0] = m[0];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+//             mi = previousw[0];
+               mpi = 0;
+
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+
+                       wm = *prept;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+//                     g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty  * fgcp1[i-1];
+//                     g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                       }
+
+
+                       g = *prept + fpenalty * ogcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+#if STOREWM
+                       WMMTX[i][j] = *curpt;
+                       WMMTX2[i][j] = *mjpt;
+#endif
+
+                       if( i == imid ) //muda
+                       {       
+                               jumpbackj[j] = *mpjpt; // muda atode matomeru
+                               jumpbacki[j] = mpi; // muda atode matomeru
+//                             fprintf( stderr, "jumpbackj[%d] in forward dp is %d\n", j, *mpjpt );
+//                             fprintf( stderr, "jumpbacki[%d] in forward dp is %d\n", j, mpi );
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                               midn[j] = mi;
+                       }
+
+//                     fprintf( stderr, "m[%d] = %f\n", j, m[j] );
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+#if STOREWM
+               WMMTX2[i][lgth2] = m[lgth2-1];
+#endif
+
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+//             initverticalw[i] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+//             currentw[j] += fpenalty;
+       }
+
+#if STOREWM
+       for( i=0; i<lgth1-1; i++ )
+       {
+               WMMTX[i][lgth2-1] += fpenalty * ( fgcp1[lgth1-1] + ogcp1[i+1] );
+               fprintf( stderr, "fgcp1[lgth1-1] + ogcp1[i+1] = %f\n", fgcp1[lgth1-1] + ogcp1[i+1] );
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               WMMTX[lgth1-1][j] += fpenalty * ( fgcp2[lgth2-1] + ogcp2[j+1] );
+               fprintf( stderr, "fgcp2[lgth2-1] + ogcp2[j+1] = %f\n", fgcp2[lgth2-1] + ogcp2[j+1] );
+       }
+#endif
+
+
+
+
+
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j] + fpenalty * fgcp2[lgth2-2];
+//             m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+
+//     for( i=lgth1-2; i>=imid; i-- )
+       firstm = -9999999.9;
+       firstmp = lgth1-1;
+       for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+//             m[lgth2] = fpenalty * fgcp1[i];
+//             WMMTX2[i][lgth2] += m[lgth2];
+//             fprintf( stderr, "m[] = %f\n", m[lgth2] );
+
+               mi = previousw[lgth2-1] + fpenalty * fgcp2[lgth2-2];
+//             mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       ijpi = i+1;
+                       ijpj = j+1;
+
+                       g = mi + fpenalty * ogcp2[j+1];
+//                     g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpj = mpi;
+                               ijpi = i+1;
+                       }
+
+                       g = *prept + fpenalty * fgcp2[j];
+//                     g = *prept;
+                       if( g >= mi )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d - renewed! mpi = %d\n", i, j, j+1 );
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty * ogcp1[i+1];
+//                     g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               ijpi = *mpjpt;
+                               ijpj = j+1;
+                       }
+
+//                     if( i == imid )fprintf( stderr, "i,j=%d,%d \n", i, j );
+                       g = *prept + fpenalty * fgcp1[i];
+//                     g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == jumpi || i == imid - 1 )
+                       {
+                               jumpforwi[j] = ijpi; //muda
+                               jumpforwj[j] = ijpj; //muda
+//                             fprintf( stderr, "jumpfori[%d] = %d\n", j, ijpi );
+//                             fprintf( stderr, "jumpforj[%d] = %d\n", j, ijpj );
+                       }
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+//                             midm[j+1] += *mjpt + fpenalty; //??????
+                               midm[j+1] += *mjpt; //??????
+                       }
+                       if( i == imid - 1 )
+                       {
+//                             midn[j] += mi + fpenalty;  //????
+                               midn[j] += mi;  //????
+                       }
+#if STOREWM
+                       WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       WMMTX2[i][j+1] += *mjpt;
+#endif
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+                       mpjpt--;
+                       curpt--;
+               }
+//             fprintf( stderr, "adding *mjpt (=%f) to WMMTX2[%d][%d]\n", *mjpt, i, j+1 );
+               g = *prept + fpenalty * fgcp1[i];
+               if( firstm < g ) 
+               {
+                       firstm = g;
+                       firstmp = i + 1;
+               }
+#if STOREWM
+               WMMTX2[i][j+1] += firstm;
+#endif
+               if( i == imid ) midm[j+1] += firstm;
+
+               if( i == imid - 1 )     
+               {
+                       maxwm = midw[1];
+                       jmid = 0;
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       for( j=2; j<lgth2-1; j++ )
+                       {
+                               wm = midw[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+                       for( j=0; j<lgth2+1; j++ )
+                       {
+                               wm = midm[j];
+                               if( wm > maxwm )
+                               {
+                                       jmid = j;
+                                       maxwm = wm;
+                               }
+//                             if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+                       }
+
+//                     if( depth == 1 ) fprintf( stderr, "maxwm!! = %f\n", maxwm );
+
+
+//                     fprintf( stderr, "### imid=%d, jmid=%d\n", imid, jmid );
+                       wm = midw[jmid];
+                       jumpi = imid-1;
+                       jumpj = jmid-1;
+                       if( jmid > 0 && midn[jmid-1] > wm ) //060413
+                       {
+                               jumpi = imid-1;
+                               jumpj = jumpbacki[jmid];
+                               wm = midn[jmid-1];
+//                             fprintf( stderr, "rejump (n)\n" );
+                       }
+                       if( midm[jmid] > wm )
+                       {
+                               jumpi = jumpbackj[jmid];
+                               jumpj = jmid-1;
+                               wm = midm[jmid];
+//                             fprintf( stderr, "rejump (m) jumpi=%d\n", jumpi );
+                       }
+
+
+//                     fprintf( stderr, "--> imid=%d, jmid=%d\n", imid, jmid );
+//                     fprintf( stderr, "--> jumpi=%d, jumpj=%d\n", jumpi, jumpj );
+#if STOREWM
+                       fprintf( stderr, "imid = %d\n", imid );
+                       fprintf( stderr, "midn = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midn[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midw = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midw[j] );
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "midm = \n" );
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stderr, "% 7.1f ", midm[j] );
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+//                     fprintf( stderr, "maxwm = %f\n", maxwm );
+               }
+               if( i == jumpi ) //saki?
+               {
+//                     fprintf( stderr, "imid, jumpi = %d,%d\n", imid, jumpi );
+//                     fprintf( stderr, "jmid, jumpj = %d,%d\n", jmid, jumpj );
+                       if( jmid == 0 )
+                       {
+//                             fprintf( stderr, "CHUI2!\n" );
+                               jumpj = 0; jmid = 1;
+                               jumpi = firstmp - 1;
+                               imid = firstmp;
+                       }
+
+#if 0
+                       else if( jmid == lgth2 ) 
+                       {
+                               fprintf( stderr, "CHUI1!\n" );
+                               jumpi=0; jumpj=0;
+                               imid=jumpforwi[0]; jmid=lgth2-1;
+                       }
+#else // 060414
+                       else if( jmid >= lgth2 ) 
+                       {
+                               fprintf( stderr, "CHUI1!\n" );
+                               jumpi=imid-1; jmid=lgth2;
+                               jumpj = lgth2-1;
+                       }
+#endif
+                       else
+                       {
+                               imid = jumpforwi[jumpj];
+                               jmid = jumpforwj[jumpj];
+                       }
+#if 0
+                       fprintf( stderr, "jumpi -> %d\n", jumpi );
+                       fprintf( stderr, "jumpj -> %d\n", jumpj );
+                       fprintf( stderr, "imid -> %d\n", imid );
+                       fprintf( stderr, "jmid -> %d\n", jmid );
+#endif
+
+#if STOREWM
+                       break;
+#else
+                       break;
+#endif
+               }
+       }
+#if 0
+               jumpi=0; jumpj=0;
+               imid=lgth1-1; jmid=lgth2-1;
+       }
+#endif
+
+//     fprintf( stderr, "imid = %d, but jumpi = %d\n", imid, jumpi );
+//     fprintf( stderr, "jmid = %d, but jumpj = %d\n", jmid, jumpj );
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+
+#if STOREWM
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2+1; j++ )
+        {
+            fprintf( stderr, "% 7.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "jumpbacki = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbacki[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpbackj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpbackj[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwi = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwi[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforwj = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 7d ", jumpforwj[j] );
+       }
+       fprintf( stderr, "\n" );
+
+
+#endif
+
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+       FreeFloatVec( midn );
+
+       FreeIntVec( jumpbacki );
+       FreeIntVec( jumpbackj );
+       FreeIntVec( jumpforwi );
+       FreeIntVec( jumpforwj );
+       FreeIntVec( jumpdummi );
+       FreeIntVec( jumpdummj );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+#if STOREWM
+       FreeFloatMtx( WMMTX );
+       FreeFloatMtx( WMMTX2 );
+#endif
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+//     fprintf( stderr, "jumpi = %d\n", jumpi );
+       value = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+#if MEMSAVE
+       alnlen = strlen( aseq1[0] );
+       for( i=0; i<icyc; i++ ) aseq1[i] += alnlen;
+       for( i=0; i<jcyc; i++ ) aseq2[i] += alnlen;
+#else
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+//             fprintf( stderr, "penalizing (2) .. %f(%d), %f(%d)\n", ogcp2[jumpj+1], jumpj+1, fgcp2[jmid-1], jmid-1 );
+               value += fpenalty * ( ogcp2[jumpj+1] + fgcp2[jmid-1] );
+//             value += fpenalty;
+       }
+       len = strlen( mseq1[0] );
+       l = imid - jumpi - 1;
+//     fprintf( stderr, "l=%d\n", l );
+       if( l > 0 )
+       {
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "ogcp1[%d] = %f\n", i, ogcp1[i] );
+//             for( i=0; i<lgth1; i++ ) fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+
+
+//             fprintf( stderr, "penalizing (1) .. ogcp1[%d] = %f, fgcp1[%d] = %f\n", jumpi+1, ogcp1[jumpi+1], imid-1, fgcp1[imid-1] );
+               value += fpenalty * ( ogcp1[jumpi+1] + fgcp1[imid-1] );
+//             value += fpenalty;
+       }
+#if 0
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "after gapfill mseq1[%d]=%s\n", i, mseq1[i] );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "after gapfill mseq2[%d]=%s\n", i, mseq2[i] );
+#endif
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+
+       value += MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );       
+
+
+
+#if DEBUG
+       if( value - maxwm > 1 || maxwm - value > 1 )
+       {
+               fprintf( stderr, "WARNING value  = %f, but maxwm = %f penalty = %f\n", value, maxwm, fpenalty );
+               for( i=0; i<icyc; i++ )
+               {
+                       fprintf( stderr, ">1-%d\n%s\n", i, mseq1[i] );
+                       fprintf( stderr, "%s\n", aseq1[i] );
+               }
+               for( i=0; i<jcyc; i++ )
+               {
+                       fprintf( stderr, ">2-%d\n%s\n", i, mseq2[i] );
+                       fprintf( stderr, "%s\n", aseq2[i] );
+               }
+
+//             exit( 1 );
+       }
+       else
+       {
+               fprintf( stderr, "value = %.0f, maxwm = %.0f -> ok\n", value, maxwm );
+       }
+#endif
+
+#if MEMSAVE
+#else
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+#endif
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       free( gaps );
+#if MEMSAVE
+#else
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+#endif
+       
+       return( value );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm = 0.0;   /* int ?????? */
+       char **mseq1;
+       char **mseq2;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float **gapinfo;
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq1 = AllocateCharMtx( icyc, ll1+ll2 );
+       mseq2 = AllocateCharMtx( jcyc, ll1+ll2 );
+
+       gapinfo = AllocateFloatMtx( 4, 0 );
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 27 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 27 );
+
+       for( i=0; i<icyc; i++ ) 
+       {
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               seq2[j][lgth2] = 0;
+       }
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+
+#if 1
+
+       OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+#if 1
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+//             fprintf( stderr, "fgcp1[%d] = %f\n", i, fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+//             fprintf( stderr, "fgcp2[%d] = %f\n", i, fgcp2[i] );
+       }
+#else
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5;
+               fgcp1[i] = 0.5;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5;
+               fgcp2[i] = 0.5;
+       }
+#endif
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+       free( (void *)gapinfo );
+
+       FreeCharMtx( mseq1 );
+       FreeCharMtx( mseq2 );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/MSalignmm.c.work b/binaries/src/mafft/core/MSalignmm.c.work
new file mode 100644 (file)
index 0000000..8a5f74f
--- /dev/null
@@ -0,0 +1,1174 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+
+#define DPTANNI 1000
+
+
+static reccycle = 0;
+
+static void OpeningGapCount( float *ogcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       float totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = 0;
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += eff[j];
+                       }
+               }
+               totaleff+= eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               ogcp[i] /= totaleff;
+}
+
+static void FinalGapCount( float *fgcp, int clus, char **seq, double *eff )
+{
+       int i, j, gc, gb; 
+       int len = strlen( seq[0] );
+       float totaleff = 0.0;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len+1; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += eff[j];
+                       }
+               }
+               totaleff += eff[j];
+       }
+       for( i=0; i<len; i++ ) 
+               fgcp[i] /= totaleff;
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[j][l] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[j][l];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+               {
+                       scarr[l] += n_dis[k][l] * cpmx1[i1][k];
+               }
+       }
+#if 0 /* ¤³¤ì¤ò»È¤¦¤È¤\ad¤Ïfloatwork¤Î¥¢¥í¥±¡¼¥È¤òµÕ¤Ë¤¹¤ë */
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[j][k]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[j][k]] * cpmxpd[j][k];
+       } 
+#endif
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        short **ijp, int icyc, int jcyc,
+                                               int ist, int ien, int jst, int jen )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, klim;
+       char gap[] = "-";
+       float wm;
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+
+
+//     fprintf( stderr, "in Atracking, lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+
+//     if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+
+       iin = lgth1; jin = lgth2;
+       klim = lgth1+lgth2;
+       for( k=0; k<=klim; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ist+ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jst+jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ist+ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jst+jfi];
+               k++;
+               iin = ifi; jin = jfi;
+
+//             if( lgth2 == 1 ) fprintf( stderr, "in Atracking, mseq1 = %s, mseq2 = %s\n", mseq1[0], mseq2[0] );
+       }
+//     fprintf( stderr, "in Atracking (owari), mseq1 = %s\n", mseq1[0] );
+//     fprintf( stderr, "in Atracking (owari), mseq2 = %s\n", mseq2[0] );
+       return( 0.0 );
+}
+
+static float MSalignmm_tanni( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, float *gapinfo[4]  )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int ll1, ll2;
+       int lasti, lastj;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+#if 1
+       float *wtmp;
+       short *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       float mi, *m;
+       short **ijp;
+       int mpi, *mp;
+       float *w1, *w2;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+       short **shortmtx;
+       float dumfl;
+       int lgth1, lgth2;
+       float *ogcp1 = gapinfo[0];
+       float *fgcp1 = gapinfo[1];
+       float *ogcp2 = gapinfo[2];
+       float *fgcp2 = gapinfo[3];
+       static char **aseq1 = NULL;
+       static char **aseq2 = NULL;
+       static char **aseq1bk, **aseq2bk;
+
+//     char ttt1[10000], ttt2[10000];
+
+       if( !aseq1 )
+       {
+               aseq1 = AllocateCharMtx( njob, 0 );
+               aseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     strncpy( ttt1, seq1[0]+ist, lgth1 ); ttt1[lgth1] = 0;
+//     strncpy( ttt2, seq2[0]+jst, lgth2 ); ttt2[lgth2] = 0;
+
+//     fprintf( stderr, "in _tanni ist,ien = %d,%d, lgth1=%d\n", ist, ien, lgth1 );
+//     fprintf( stderr, "in _tanni jst,jen = %d,%d, lgth2=%d\n", jst, jen, lgth2 );
+//     fprintf( stderr, "ttt1 = %s\n", ttt1 );
+//     fprintf( stderr, "ttt2 = %s\n", ttt2 );
+
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       aseq1bk = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2bk = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+       for( i=0; i<icyc; i++ ) aseq1[i] = aseq1bk[i];
+       for( i=0; i<jcyc; i++ ) aseq2[i] = aseq2bk[i];
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+
+       shortmtx = AllocateShortMtx( ll1+1, ll2+1 );
+
+       ijp = shortmtx;
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty * ( ogcp1[0] + fgcp1[i-1] );
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty * ( ogcp2[0] + fgcp2[j-1] );
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + fpenalty * ogcp1[1]; mp[j] = 0;;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + fpenalty * ogcp2[1]; 
+               mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty * fgcp2[j-1];
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + fpenalty * ogcp2[j];
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fpenalty * fgcp1[i-1];
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + fpenalty * ogcp1[i];
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+       Atracking( currentw, lastverticalw, seq1, seq2, aseq1, aseq2, cpmx1+ist, cpmx2+jst, ijp, icyc, jcyc, ist, ien, jst, jen );
+
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "in _tanni, aseq1 = %s\n", aseq1[0] );
+//     fprintf( stderr, "in _tanni, mseq1 = %s\n", mseq1[0] );
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+       FreeShortMtx( shortmtx );
+
+       FreeCharMtx( aseq1bk );
+       FreeCharMtx( aseq2bk );
+
+       return( wm );
+}
+
+static float MSalignmm_rec( int icyc, int jcyc, double *eff1, double *eff2, char **seq1, char **seq2, float **cpmx1, float **cpmx2, int ist, int ien, int jst, int jen, int alloclen, char **mseq1, char **mseq2, int depth, float *gapinfo[4] )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       char **aseq1, **aseq2;
+       int ll1, ll2, l, len;
+       int lasti, lastj, imid, jmid;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_ex = (float)penalty_ex;
+       float *wtmp;
+//     short *ijppt;
+       int *mpjpt;
+//     short **ijp;
+       int *mp;
+       int mpi;
+       float *mjpt, *prept, *curpt;
+       float mi;
+       float *m;
+       float *w1, *w2;
+//     float *match;
+       float *initverticalw;    /* kufuu sureba iranai */
+       float *lastverticalw;    /* kufuu sureba iranai */
+       int **intwork;
+       float **floatwork;
+//     short **shortmtx;
+//     float **WMMTX;
+//     float **WMMTX2;
+       float *midw;
+       float *midm;
+       float dumfl;
+       int lgth1, lgth2;
+       float maxwm;
+       int *jumpforw;
+       int *jumpback;
+       int *jumpdumm; //muda
+       int *jumppt;
+       int jumpi;
+       int jumpj;
+       char *gaps;
+//     static char ttt1[50000];
+//     static char ttt2[50000];
+
+       depth++;
+       reccycle++;
+
+       lgth1 = ien-ist+1;
+       lgth2 = jen-jst+1;
+
+//     fprintf( stderr, "==== MSalign (depth=%d, reccycle=%d), ist=%d, ien=%d, jst=%d, jen=%d\n", depth, reccycle, ist, ien, jst, jen );
+//     strncpy( ttt1, seq1[0]+ist, lgth1 );
+//     strncpy( ttt2, seq2[0]+jst, lgth2 );
+//     fprintf( stderr, "seq1 = %s\n", ttt1 );
+//     fprintf( stderr, "seq2 = %s\n", ttt2 );
+       if( lgth2 <= 0 )
+       {
+//             fprintf( stderr, "==== jimei\n" );
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strncpy( mseq1[i], seq1[i]+ist, lgth1 );
+                       mseq1[i][lgth1] = 0;
+               }
+               for( i=0; i<jcyc; i++ ) 
+               {
+                       mseq2[i][0] = 0;
+                       for( j=0; j<lgth1; j++ )
+                               strcat( mseq2[i], "-" );
+               }
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+               return( (float)offset * lgth1 );
+       }
+
+       aseq1 = AllocateCharMtx( icyc, lgth1+lgth2+100 );
+       aseq2 = AllocateCharMtx( jcyc, lgth1+lgth2+100 );
+
+       if( lgth1 < DPTANNI )
+       {
+//             fprintf( stderr, "==== Going to _tanni\n" );
+
+               wm = MSalignmm_tanni( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ien, jst, jen, alloclen, aseq1, aseq2, gapinfo );  
+
+
+               for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+               for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//             fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//             fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+//             fprintf( stderr, "freeing aseq\n" );
+               FreeCharMtx( aseq1 );
+               FreeCharMtx( aseq2 );
+
+               return( wm );
+       }
+//     fprintf( stderr, "Trying to divide the mtx\n" );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+//     fprintf( stderr, "ll1,ll2=%d,%d\n", ll1, ll2 );
+
+       w1 = AllocateFloatVec( ll2+2 );
+       w2 = AllocateFloatVec( ll2+2 );
+//     match = AllocateFloatVec( ll2+2 );
+       midw = AllocateFloatVec( ll2+2 );
+       midm = AllocateFloatVec( ll2+2 );
+       jumpback = AllocateIntVec( ll2+2 );
+       jumpforw = AllocateIntVec( ll2+2 );
+       jumpdumm = AllocateIntVec( ll2+2 );
+
+       initverticalw = AllocateFloatVec( ll1+2 );
+       lastverticalw = AllocateFloatVec( ll1+2 );
+
+       m = AllocateFloatVec( ll2+2 );
+       mp = AllocateIntVec( ll2+2 );
+       gaps = AllocateCharVec( MAX( ll1, ll2 ) + 2 );
+
+       floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+       intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n" );
+#endif
+
+#if 0
+       WMMTX = AllocateFloatMtx( ll1, ll2 );
+       WMMTX2 = AllocateFloatMtx( ll1, ll2 );
+#endif
+#if 0
+       shortmtx = AllocateShortMtx( ll1, ll2 );
+
+#if DEBUG
+       fprintf( stderr, "succeeded\n\n" );
+#endif
+
+       ijp = shortmtx;
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, 0, lgth1, floatwork, intwork, 1 );
+
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, 0, lgth2, floatwork, intwork, 1 );
+
+//     WMMTX[0][0] = initverticalw[0];
+       for( i=1; i<lgth1+1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+//             WMMTX[i][0] = initverticalw[i];
+       }
+       for( j=1; j<lgth2+1; j++ )
+       {
+               currentw[j] += fpenalty;
+//             WMMTX[0][j] = currentw[j];
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1];
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       imid = lgth1 / 2;
+
+       lasti = lgth1+1;
+//     for( i=1; i<lasti; i++ )
+       for( i=1; i<=imid; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+
+               mi = previousw[0]; 
+               mpi = 0;
+
+//             ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               if( i == imid ) jumppt = jumpback+1;
+               else            jumppt = jumpdumm+1;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *jumppt = 0; // muda atode saishukai dake matomeru
+//                     *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *jumppt = +mpi; // muda atode matomeru
+//                             *ijppt = -( j - mpi );
+                       }
+                       g = *prept;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt (f)= %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijppt = +( i - *mpjpt );
+                               *jumppt = -*mpjpt; // muda atode matomeru
+                       }
+                       g = *prept;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+
+//                     WMMTX[i][j] = *curpt;
+//                     WMMTX2[i][j] = *mjpt;
+
+                       if( i == imid ) //muda
+                       {       
+                               midw[j] = *curpt;
+                               midm[j] = *mjpt;
+                       }
+
+//                     ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+                       jumppt++;
+
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+#if 0  // ue
+               if( i == imid )
+               {
+                       for( j=0; j<lgth2; j++ ) midw[j] = currentw[j];
+                       for( j=0; j<lgth2; j++ ) midm[j] = m[j];
+               }
+#endif
+       }
+//     for( j=0; j<lgth2; j++ ) midw[j] = WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midm[j] = WMMTX2[imid][j];
+
+#if 0
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "WMMTX2 = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "\n" );
+#endif
+
+// gyakudp
+
+       match_calc( initverticalw, cpmx2+jst, cpmx1+ist, lgth2-1, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1+ist, cpmx2+jst, lgth1-1, lgth2, floatwork, intwork, 1 );
+
+       for( i=0; i<lgth1-1; i++ )
+       {
+               initverticalw[i] += fpenalty;
+//             WMMTX[i][lgth2-1] += fpenalty;
+       }
+       for( j=0; j<lgth2-1; j++ )
+       {
+               currentw[j] += fpenalty;
+//             WMMTX[lgth1-1][j] += fpenalty;
+       }
+
+       for( j=lgth2-1; j>0; --j )
+       {
+               m[j-1] = currentw[j];
+               mp[j] = lgth1-1;
+       }
+
+//     for( j=0; j<lgth2; j++ ) m[j] = 0.0;
+       // m[lgth2-1] ha irunoka?
+
+       for( i=lgth1-2; i>=imid; i-- )
+//     for( i=lgth1-2; i>-1; i-- )
+       {
+               wtmp = previousw;
+               previousw = currentw;
+               currentw = wtmp;
+               previousw[lgth2-1] = initverticalw[i+1];
+//             match_calc( currentw, seq1, seq2, i, lgth2 );
+               match_calc( currentw, cpmx1+ist, cpmx2+jst, i, lgth2, floatwork, intwork, 0 );
+
+               currentw[lgth2-1] = initverticalw[i];
+
+               mi = previousw[lgth2-1];
+               mpi = lgth2 - 1;
+
+               mjpt = m + lgth2 - 2;
+               prept = previousw + lgth2 - 1;
+               curpt = currentw + lgth2 - 2;
+               mpjpt = mp + lgth2 - 2;
+               if( i == imid ) jumppt = jumpforw + lgth2 - 2;
+               else            jumppt = jumpdumm + lgth2 - 2;
+
+               for( j=lgth2-2; j>-1; j-- )
+               {
+                       wm = *prept;
+                       *jumppt = 0; //muda
+
+                       g = mi + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *jumppt = +mpi; //muda
+                       }
+
+                       g = *prept;
+                       if( g > mi )
+                       {
+                               mi = g;
+                               mpi = j + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+//                     fprintf( stderr, "i,j=%d,%d *mpjpt = %d\n", i, j, *mpjpt );
+                       g = *mjpt + fpenalty;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *jumppt = -*mpjpt; //muda
+                       }
+
+                       g = *prept;
+                       if( g > *mjpt )
+                       {
+//                             fprintf( stderr, "mjpt: %f->%f (%d,%d)\n", *mjpt, g, i, j );
+                               *mjpt = g;
+                               *mpjpt = i + 1;
+                       }
+
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+                       if( i == imid ) // muda
+                       {
+                               midw[j] += wm;
+                               midm[j+1] += *mjpt + fpenalty;
+                       }
+//                     WMMTX[i][j] += wm;
+//                     WMMTX2[i][j+1] += *mjpt + fpenalty;
+                       *curpt += wm;
+
+                       mjpt--;
+                       prept--;
+//                     mpjpt--;
+                       curpt--;
+                       jumppt--;
+               }
+       }
+
+//     for( j=0; j<lgth2; j++ ) midw[j] += currentw[j];
+//     for( j=0; j<lgth2; j++ ) midm[j] += m[j+1];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+//     for( j=0; j<lgth2; j++ ) midw[j] += WMMTX[imid][j];
+
+#if 0
+       fprintf( stderr, "WMMTX = \n" );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+       fprintf( stderr, "WMMTX2 = (p = %f)\n", fpenalty );
+    for( i=0; i<lgth1; i++ )
+    {
+        fprintf( stderr, "%d ", i );
+        for( j=0; j<lgth2; j++ )
+        {
+            fprintf( stderr, "% 10.2f ", WMMTX2[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+
+       fprintf( stderr, "midw = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10.2f ", midw[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "midm = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10.2f ", midm[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpback = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpback[j] );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "jumpforw = \n" );
+       for( j=0; j<lgth2; j++ )
+       {
+               fprintf( stderr, "% 10d ", jumpforw[j] );
+       }
+       fprintf( stderr, "\n" );
+#endif
+
+//     Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+#if 0 // irukamo
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+#endif
+
+
+       maxwm = -999999999.9;
+       jmid = -100;
+       for( j=0; j<lgth2; j++ )
+       {
+               wm = midw[j];
+               if( wm > maxwm )
+               {
+                       jmid = j;
+                       maxwm = wm;
+               }
+               wm = midm[j];
+               if( wm > maxwm )
+               {
+                       jmid = j;
+                       maxwm = wm;
+               }
+       }
+#if 0
+       fprintf( stderr, "jmid=%d, maxwm = %f\n", jmid, maxwm );
+       fprintf( stderr, "jumpforw[%d] = %d\n", jmid, jumpforw[jmid] );
+       fprintf( stderr, "jumpback[%d] = %d\n", jmid, jumpback[jmid] );
+
+       if( jumpback[jmid] == 0 )
+       {
+               jumpi = imid-1;
+               jumpj = jmid-1;
+       }
+       else if( jumpback[jmid] < 0 )
+       {
+               jumpi = - jumpback[jmid];
+               jumpj = jmid-1;
+       }
+       else
+       {
+               jumpi = imid-1;
+               jumpj = jumpback[jmid];
+       }
+
+       if( jumpforw[jmid] == 0 )
+       {
+               ;
+       }
+       else if( jumpforw[jmid] < 0 )
+       {
+               imid = - jumpforw[jmid];
+               fprintf( stderr, "XXXX imid = %d", imid );
+       }
+       else
+       {
+               fprintf( stderr, "OXOXO" );
+               jmid = jumpforw[jmid];
+       }
+#else
+       jumpi = imid-1;
+       jumpj = jmid-1;
+#endif
+
+#if 0
+       fprintf( stderr, "jumpi = %d, imid = %d\n", jumpi, imid );
+       fprintf( stderr, "jumpj = %d, jmid = %d\n", jumpj, jmid );
+
+       fprintf( stderr, "imid = %d\n", imid );
+       fprintf( stderr, "jmid = %d\n", jmid );
+#endif
+
+
+       FreeFloatVec( w1 );
+       FreeFloatVec( w2 );
+//     FreeFloatVec( match );
+       FreeFloatVec( initverticalw );
+       FreeFloatVec( lastverticalw );
+       FreeFloatVec( midw );
+       FreeFloatVec( midm );
+
+       FreeIntVec( jumpback );
+       FreeIntVec( jumpforw );
+       FreeIntVec( jumpdumm );
+       free( gaps );
+
+       FreeFloatVec( m );
+       FreeIntVec( mp );
+
+       FreeFloatMtx( floatwork );
+       FreeIntMtx( intwork );
+
+//     FreeShortMtx( shortmtx );
+//     FreeFloatMtx( WMMTX );
+//     FreeFloatMtx( WMMTX2 );
+
+//     fprintf( stderr, "==== calling myself (first)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist, ist+jumpi, jst, jst+jumpj, alloclen, aseq1, aseq2, depth, gapinfo );      
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(f) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(f) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+       len = strlen( mseq1[0] );
+//     fprintf( stderr, "len = %d\n", len );
+       l = jmid - jumpj - 1;
+#if 1
+       if( l > 0 )
+       {
+               fprintf( stderr, "l=%d\n", l );
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ ) 
+               {
+                       strcat( mseq1[i], gaps );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ )
+               {
+                       strncat( mseq2[j], seq2[j]+jst+jumpj+1, l );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+       l = imid - jumpi - 1;
+       if( l > 0 )
+       {
+               fprintf( stderr, "l=%d\n", l );
+               for( i=0; i<l; i++ ) gaps[i] = '-'; gaps[i] = 0;
+               for( i=0; i<icyc; i++ )
+               {
+                       strncat( mseq1[i], seq1[i]+ist+jumpi+1, l );
+                       mseq1[i][len+l] = 0;
+               }
+               for( j=0; j<jcyc; j++ ) 
+               {
+                       strcat( mseq2[j], gaps );
+                       mseq2[j][len+l] = 0;
+               }
+       }
+#endif
+//     fprintf( stderr, "after gapfill mseq1[0]=%s\n", mseq1[0] );
+//     fprintf( stderr, "after gapfill mseq2[0]=%s\n", mseq2[0] );
+
+//     fprintf( stderr, "==== calling myself (second)\n" );
+
+       MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, ist+imid, ien, jst+jmid, jen, alloclen, aseq1, aseq2, depth, gapinfo );        
+
+       for( i=0; i<icyc; i++ ) strcat( mseq1[i], aseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcat( mseq2[i], aseq2[i] );
+
+//     fprintf( stderr, "====(s) aseq1[0] (%d) = %s (%d-%d)\n", depth, aseq1[0], ist, ien );
+//     fprintf( stderr, "====(s) aseq2[0] (%d) = %s (%d-%d)\n", depth, aseq2[0], jst, jen );
+
+//     fprintf( stderr, "==== mseq1[0] (%d) = %s\n", depth, mseq1[0] );
+//     fprintf( stderr, "==== mseq2[0] (%d) = %s\n", depth, mseq2[0] );
+
+       FreeCharMtx( aseq1 );
+       FreeCharMtx( aseq2 );
+       
+       return( wm );
+}
+
+
+
+float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       int i, j;
+       int ll1, ll2;
+       int lgth1, lgth2;
+       float wm;   /* int ?????? */
+       static char **mseq1 = NULL;
+       static char **mseq2 = NULL;
+       char **mseq;
+       float *ogcp1;
+       float *ogcp2;
+       float *fgcp1;
+       float *fgcp2;
+       float **cpmx1;
+       float **cpmx2;
+       float *gapinfo[4];
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( mseq1 == NULL )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       ll1 = ( (int)(1.3*lgth1) ) + 100;
+       ll2 = ( (int)(1.3*lgth2) ) + 100;
+
+       mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+       ogcp1 = AllocateFloatVec( ll1+2 );
+       ogcp2 = AllocateFloatVec( ll2+2 );
+       fgcp1 = AllocateFloatVec( ll1+2 );
+       fgcp2 = AllocateFloatVec( ll2+2 );
+
+       cpmx1 = AllocateFloatMtx( ll1+2, 26 );
+       cpmx2 = AllocateFloatMtx( ll2+2, 26 );
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+       MScpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       MScpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+#if 1
+       OpeningGapCount( ogcp1, icyc, seq1, eff1 );
+       OpeningGapCount( ogcp2, jcyc, seq2, eff2 );
+       FinalGapCount( fgcp1, icyc, seq1, eff1 );
+       FinalGapCount( fgcp2, jcyc, seq2, eff2 );
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+       }
+
+       gapinfo[0] = ogcp1;
+       gapinfo[1] = fgcp1;
+       gapinfo[2] = ogcp2;
+       gapinfo[3] = fgcp2;
+#endif
+
+#if 0
+       fprintf( stdout, "in MSalignmm.c\n" );
+       for( i=0; i<icyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP1\n", i );
+               fprintf( stdout, "%s\n", seq1[i] );
+       }
+       for( i=0; i<jcyc; i++ )
+       {
+               fprintf( stdout, ">%d of GROUP2\n", i );
+               fprintf( stdout, "%s\n", seq2[i] );
+       }
+       fflush( stdout );
+#endif
+
+       wm = MSalignmm_rec( icyc, jcyc, eff1, eff2, seq1, seq2, cpmx1, cpmx2, 0, lgth1-1, 0, lgth2-1, alloclen, mseq1, mseq2, 0, gapinfo );
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( i=0; i<jcyc; i++ ) strcpy( seq2[i], mseq2[i] );
+
+
+       FreeFloatVec( ogcp1 );
+       FreeFloatVec( ogcp2 );
+       FreeFloatVec( fgcp1 );
+       FreeFloatVec( fgcp2 );
+       FreeFloatMtx( cpmx1 );
+       FreeFloatMtx( cpmx2 );
+
+       FreeCharMtx( mseq );
+
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/Makefile b/binaries/src/mafft/core/Makefile
new file mode 100644 (file)
index 0000000..b950069
--- /dev/null
@@ -0,0 +1,511 @@
+PREFIX = /usr/local
+LIBDIR = $(PREFIX)/libexec/mafft
+BINDIR = $(PREFIX)/bin
+MANDIR = $(PREFIX)/share/man/man1
+
+#MNO_CYGWIN = -mno-cygwin
+
+#ENABLE_MULTITHREAD = -Denablemultithread
+#Uncomment this to enable multithreading (linux only)
+
+CC = gcc
+CFLAGS = -O3
+#CFLAGS =  -O0  -pedantic -Wall -std=c99 -g -pg -DMALLOC_CHECK_=3
+
+MYCFLAGS = $(MNO_CYGWIN) $(ENABLE_MULTITHREAD) $(CFLAGS)
+
+ifeq ($(ENABLE_MULTITHREAD),-Denablemultithread)
+LIBS = -lm  -lpthread
+else
+LIBS = -lm
+endif
+
+INSTALL = install
+
+PROGS = dvtditr dndfast7 dndblast sextet5 mafft-distance pairlocalalign \
+               pair2hat3s multi2hat3s rnatest pairash \
+        splittbfast disttbfast tbfast mafft-profile f2cl mccaskillwrap contrafoldwrap countlen \
+               seq2regtable regtable2seq score getlag dndpre dndpre2 setcore replaceu restoreu
+SCRIPTS = mafft mafft-homologs.rb
+OBJREPLACEU = mtxutl.o io.o replaceu.o defs.o mltaln9.o
+OBJRESTOREU = mtxutl.o io.o restoreu.o defs.o mltaln9.o
+OBJREGTABLE2SEQ = mtxutl.o io.o regtable2seq.o defs.o mltaln9.o
+OBJSEQ2REGTABLE = mtxutl.o io.o seq2regtable.o defs.o
+OBJCOUNTLEN = mtxutl.o io.o countlen.o defs.o
+OBJF2CL = mtxutl.o io.o f2cl.o constants.o defs.o
+OBJMCCASKILLWRAP = mtxutl.o io.o mccaskillwrap.o constants.o defs.o mltaln9.o
+OBJCONTRAFOLDWRAP = mtxutl.o io.o contrafoldwrap.o constants.o defs.o mltaln9.o
+OBJMULTI2HAT3S = mtxutl.o io.o mltaln9.o tddis.o constants.o \
+                                multi2hat3s.o defs.o fft.o fftFunctions.o
+OBJPAIR2HAT3S = mtxutl.o io.o mltaln9.o tddis.o constants.o \
+                               pair2hat3s.o defs.o fft.o fftFunctions.o
+OBJRNATEST = mtxutl.o io.o mltaln9.o tddis.o constants.o Lalignmm.o \
+                        rna.o rnatest.o defs.o fft.o fftFunctions.o
+OBJPAIRASH = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                        Falign.o MSalignmm.o Galign11.o MSalign11.o suboptalign11.o genGalign11.o genalign11.o Lalign11.o SAalignmm.o \
+                        pairash.o defs.o fft.o fftFunctions.o
+OBJPAIRLOCALALIGN = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                           Falign.o MSalignmm.o Galign11.o MSalign11.o suboptalign11.o genGalign11.o genalign11.o Lalign11.o SAalignmm.o \
+                                       pairlocalalign.o defs.o fft.o fftFunctions.o
+OBJDUMMY = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       disttbfast_dummy.o dummy.o defs.o fft.o fftFunctions.o
+OBJSPLITFROMALN = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       Lalign11.o splitfromaln.o defs.o fft.o fftFunctions.o
+OBJSPLITTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       Lalign11.o splittbfast.o defs.o fft.o fftFunctions.o
+OBJSPLITTBFAST2 = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       Lalign11.o splittbfast2.o defs.o fft.o fftFunctions.o
+OBJSPLITTBFASTP = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       Lalign11.o defs.o fft.o fftFunctions.o
+OBJDISTTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       disttbfast.o defs.o fft.o fftFunctions.o addfunctions.o
+OBJTBFAST = mtxutl.o io.o mltaln9.o tddis.o constants.o MSalignmm.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o \
+                       tbfast.o defs.o fft.o fftFunctions.o addfunctions.o
+OBJTBFAST2 = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o MSalignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o \
+                       tbfast2.o defs.o fft.o fftFunctions.o
+OBJSETCORE = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       setcore.o defs.o fft.o fftFunctions.o
+OBJTDITR = mtxutl.o io.o mltaln9.o tddis.o constants.o nj.o  partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                  Falign.o Falign_localhom.o Galign11.o fftFunctions.o fft.o  \
+                  tditeration.o tditr.o defs.o SAalignmm.o treeOperation.o
+OBJDVTDITR = mtxutl.o io.o mltaln9.o tddis.o constants.o nj.o  partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                       Falign.o Falign_localhom.o Galign11.o MSalignmm.o fftFunctions.o fft.o  \
+                       tditeration.o dvtditr.o defs.o SAalignmm.o treeOperation.o
+OBJGETLAG = mtxutl.o io.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+                   Falign.o Falign_localhom.o Galign11.o SAalignmm.o MSalignmm.o \
+                       getlag.o defs.o fft.o fftFunctions.o
+OBJGAPFILL = mtxutl.o io.o constants.o gapfill.o defs.o
+OBJDNDFAST5 = dndfast5.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJDNDBLAST = dndblast.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJDNDFAST7 = dndfast7.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJDNDFAST6 = dndfast6.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJDNDFAST4 = dndfast4.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJDNDFAST6 = dndfast6.o io.o constants.o mtxutl.o mltaln9.o tddis.o defs.o
+OBJSEXTET5 = io.o constants.o mtxutl.o mltaln9.o tddis.o sextet5.o defs.o
+OBJDISTANCE = io.o constants.o mtxutl.o mltaln9.o tddis.o mafft-distance.o defs.o
+OBJTRIPLET6 = io.o constants.o mtxutl.o mltaln9.o tddis.o triplet6.o defs.o
+OBJTRIPLET5 = io.o constants.o mtxutl.o mltaln9.o tddis.o triplet5.o defs.o
+OBJOCTET4 = io.o constants.o mtxutl.o mltaln9.o tddis.o octet4.o defs.o
+OBJDNDPRE = dndpre.o io.o constants.o mtxutl.o mltaln9.o defs.o
+OBJDNDPRESCORE = dndpre2.o io.o constants.o mtxutl.o mltaln9.o defs.o
+OBJGALN = io.o mtxutl.o mltaln9.o tddis.o constants.o partQalignmm.o partSalignmm.o MSalignmm.o Lalignmm.o rna.o Salignmm.o Ralignmm.o Qalignmm.o Halignmm.o \
+          SAalignmm.o Galign11.o Falign.o Falign_localhom.o fftFunctions.o fft.o mafft-profile.o defs.o
+OBJSCORE = io.o mtxutl.o mltaln9.o score.o constants.o defs.o
+
+HEADER = mltaln.h mtxutl.h
+FFTHEADER = fft.h
+
+MANPAGES = mafft.1 mafft-homologs.1
+
+
+
+all : $(PROGS) $(SCRIPTS)
+       cp $(SCRIPTS) ../scripts
+       chmod 755 ../scripts/*
+       cp $(PROGS) ../binaries
+       chmod 755 ../binaries/*
+       cp $(MANPAGES) ../binaries
+       @echo done.
+
+univscript: univscript.tmpl Makefile
+       sed "s:_PROGS:$(PROGS):" univscript.tmpl  > univscript
+
+mafft: mafft.tmpl
+       sed "s:_LIBDIR:$(LIBDIR):" mafft.tmpl  > mafft
+
+mafft-homologs.rb: mafft-homologs.tmpl
+#      cp mafft-homologs.tmpl mafft-homologs.rb
+       sed "s:_BINDIR:$(BINDIR):" mafft-homologs.tmpl  > mafft-homologs.rb
+
+mltaln.h : functions.h
+       touch mltaln.h
+
+tbfast : $(OBJTBFAST)
+       $(CC) -o $@ $(OBJTBFAST) $(MYCFLAGS) $(LIBS)
+
+tbfast2 : $(OBJTBFAST2)
+       $(CC) -o $@ $(OBJTBFAST2) $(MYCFLAGS) $(LIBS)
+
+disttbfast : $(OBJDISTTBFAST)
+       $(CC) -o $@ $(OBJDISTTBFAST) $(MYCFLAGS) $(LIBS)
+
+splittbfast : $(OBJSPLITTBFAST)
+       $(CC) -o $@ $(OBJSPLITTBFAST) $(MYCFLAGS) $(LIBS)
+
+splitfromaln : $(OBJSPLITFROMALN)
+       $(CC) -o $@ $(OBJSPLITFROMALN) $(MYCFLAGS) $(LIBS)
+
+splittbfast2 : $(OBJSPLITTBFAST2)
+       $(CC) -o $@ $(OBJSPLITTBFAST2) $(MYCFLAGS) $(LIBS)
+
+dummy : $(OBJDUMMY)
+       $(CC) -o $@ $(OBJDUMMY) $(MYCFLAGS) $(LIBS)
+
+setcore : $(OBJSETCORE)
+       $(CC) -o $@ $(OBJSETCORE) $(MYCFLAGS) $(LIBS)
+
+countlen : $(OBJCOUNTLEN)
+       $(CC) -o $@ $(OBJCOUNTLEN) $(MYCFLAGS) $(LIBS)
+
+seq2regtable : $(OBJSEQ2REGTABLE)
+       $(CC) -o $@ $(OBJSEQ2REGTABLE) $(MYCFLAGS) $(LIBS)
+
+regtable2seq : $(OBJREGTABLE2SEQ)
+       $(CC) -o $@ $(OBJREGTABLE2SEQ) $(MYCFLAGS) $(LIBS)
+
+replaceu : $(OBJREPLACEU)
+       $(CC) -o $@ $(OBJREPLACEU) $(MYCFLAGS) $(LIBS)
+
+restoreu : $(OBJRESTOREU)
+       $(CC) -o $@ $(OBJRESTOREU) $(MYCFLAGS) $(LIBS)
+
+f2cl : $(OBJF2CL)
+       $(CC) -o $@ $(OBJF2CL) $(MYCFLAGS) $(LIBS)
+
+mccaskillwrap : $(OBJMCCASKILLWRAP)
+       $(CC) -o $@ $(OBJMCCASKILLWRAP) $(MYCFLAGS) $(LIBS)
+
+contrafoldwrap : $(OBJCONTRAFOLDWRAP)
+       $(CC) -o $@ $(OBJCONTRAFOLDWRAP) $(MYCFLAGS) $(LIBS)
+
+pairlocalalign : $(OBJPAIRLOCALALIGN)
+       $(CC) -o $@ $(OBJPAIRLOCALALIGN) $(MYCFLAGS) $(LIBS)
+
+pairash : $(OBJPAIRASH)
+       $(CC) -o $@ $(OBJPAIRASH) $(MYCFLAGS) $(LIBS)
+
+rnatest : $(OBJRNATEST)
+       $(CC) -o $@ $(OBJRNATEST) $(MYCFLAGS) $(LIBS)
+
+pair2hat3s : $(OBJPAIR2HAT3S)
+       $(CC) -o $@ $(OBJPAIR2HAT3S) $(MYCFLAGS) $(LIBS)
+
+multi2hat3s : $(OBJMULTI2HAT3S)
+       $(CC) -o $@ $(OBJMULTI2HAT3S) $(MYCFLAGS) $(LIBS)
+
+getlag : $(OBJGETLAG)
+       $(CC) -o $@ $(OBJGETLAG) $(MYCFLAGS) $(LIBS)
+
+tditr : $(OBJTDITR)
+       $(CC) -o $@ $(OBJTDITR) $(MYCFLAGS) $(LIBS)
+
+dvtditr : $(OBJDVTDITR)
+       $(CC) -o $@ $(OBJDVTDITR) $(MYCFLAGS) $(LIBS)
+
+mafft-profile : $(OBJGALN)
+       $(CC) -o $@ $(OBJGALN) $(MYCFLAGS) $(LIBS)
+
+gapfill : $(OBJGAPFILL)
+       $(CC) -o $@ $(OBJGAPFILL) $(MYCFLAGS) $(LIBS)
+
+dndfast4 : $(OBJDNDFAST4)
+       $(CC) -o $@ $(OBJDNDFAST4) $(MYCFLAGS) $(LIBS)
+
+dndfast5 : $(OBJDNDFAST5)
+       $(CC) -o $@ $(OBJDNDFAST5) $(MYCFLAGS) $(LIBS)
+
+dndfast6 : $(OBJDNDFAST6)
+       $(CC) -o $@ $(OBJDNDFAST6) $(MYCFLAGS) $(LIBS)
+
+dndfast7 : $(OBJDNDFAST7)
+       $(CC) -o $@ $(OBJDNDFAST7) $(MYCFLAGS) $(LIBS)
+
+dndblast : $(OBJDNDBLAST)
+       $(CC) -o $@ $(OBJDNDBLAST) $(MYCFLAGS) $(LIBS)
+
+dndfast3 : $(OBJDNDFAST3)
+       $(CC) -o $@ $(OBJDNDFAST3) $(MYCFLAGS) $(LIBS)
+
+triplet : $(OBJTRIPLET)
+       $(CC) -o $@ $(OBJTRIPLET) $(MYCFLAGS) $(LIBS)
+
+triplet3 : $(OBJTRIPLET3)
+       $(CC) -o $@ $(OBJTRIPLET3) $(MYCFLAGS) $(LIBS)
+
+sextet3 : $(OBJSEXTET3)
+       $(CC) -o $@ $(OBJSEXTET3) $(MYCFLAGS) $(LIBS)
+
+sextet4 : $(OBJSEXTET4)
+       $(CC) -o $@ $(OBJSEXTET4) $(MYCFLAGS) $(LIBS)
+
+sextet5 : $(OBJSEXTET5)
+       $(CC) -o $@ $(OBJSEXTET5) $(MYCFLAGS) $(LIBS)
+
+mafft-distance : $(OBJDISTANCE)
+       $(CC) -o $@ $(OBJDISTANCE) $(MYCFLAGS) $(LIBS)
+
+triplet5 : $(OBJTRIPLET5)
+       $(CC) -o $@ $(OBJTRIPLET5) $(MYCFLAGS) $(LIBS)
+
+triplet6 : $(OBJTRIPLET6)
+       $(CC) -o $@ $(OBJTRIPLET6) $(MYCFLAGS) $(LIBS)
+
+octet4 : $(OBJOCTET4)
+       $(CC) -o $@ $(OBJOCTET4) $(MYCFLAGS) $(LIBS)
+
+dndpre : $(OBJDNDPRE)
+       $(CC) -o $@ $(OBJDNDPRE) $(MYCFLAGS) $(LIBS)
+
+dndpre2 : $(OBJDNDPRESCORE)
+       $(CC) -o $@ $(OBJDNDPRESCORE) $(MYCFLAGS) $(LIBS)
+
+score : $(OBJSCORE)
+       $(CC) -o $@ $(OBJSCORE) $(MYCFLAGS) $(LIBS)
+
+genMtx : $(OBJGENMTX)
+       $(CC) -o $@ $(OBJGENMTX) $(MYCFLAGS) $(LIBS)
+
+gapfill.o : gapfill.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c gapfill.c
+
+mltaln9.o : mltaln9.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c mltaln9.c
+
+tddis.o : tddis.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c tddis.c
+
+constants.o : constants.c miyata.h miyata5.h blosum.c DNA.h JTT.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c constants.c
+
+defs.o : defs.c 
+       $(CC) $(MYCFLAGS) -c defs.c
+
+#A+++alignmm.o : SA+++alignmm.c $(HEADER)
+#      $(CC) $(MYCFLAGS) -c SA+++alignmm.c -o A+++alignmm.o
+
+Salignmm.o : Salignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Salignmm.c 
+
+Halignmm.o : Halignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Halignmm.c 
+
+Ralignmm.o : Ralignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Ralignmm.c 
+
+Qalignmm.o : Qalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Qalignmm.c 
+
+MSalignmm.o : MSalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c MSalignmm.c 
+
+partSalignmm.o : partSalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c partSalignmm.c  
+
+partQalignmm.o : partQalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c partQalignmm.c  
+
+Lalign11.o : Lalign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Lalign11.c 
+
+genalign11.o : genalign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c genalign11.c 
+
+genGalign11.o : genGalign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c genGalign11.c 
+
+suboptalign11.o : suboptalign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c suboptalign11.c 
+
+Galign11.o : Galign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Galign11.c 
+
+MSalign11.o : MSalign11.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c MSalign11.c 
+
+SAalignmm.o : SAalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c SAalignmm.c -o SAalignmm.o
+
+Lalignmm.o : Lalignmm.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c Lalignmm.c 
+
+rna.o : rna.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c rna.c 
+
+disttbfast.o : disttbfast.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c disttbfast.c
+
+splitfromaln.o : splitfromaln.c $(HEADER) $(FFTHEADER) 
+       $(CC) $(MYCFLAGS) -c splitfromaln.c
+
+splittbfast.o : splittbfast.c $(HEADER) $(FFTHEADER) 
+       $(CC) $(MYCFLAGS) -c splittbfast.c
+
+splittbfast2.o : splittbfast2.c $(HEADER) $(FFTHEADER) 
+       $(CC) $(MYCFLAGS) -c splittbfast2.c
+
+disttbfast_dummy.o : disttbfast_dummy.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c disttbfast_dummy.c
+
+dummy.o : dummy.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c dummy.c
+
+tbfast.o : tbfast.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c tbfast.c
+
+tbfast2.o : tbfast2.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c tbfast2.c
+
+setcore.o : setcore.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c setcore.c
+
+getlag.o : getlag.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c getlag.c
+
+tditr.o : tditr.c $(HEADER)
+        $(CC) $(MYCFLAGS) -c tditr.c
+
+dvtditr.o : dvtditr.c $(HEADER)
+        $(CC) $(MYCFLAGS) -c dvtditr.c
+
+tditeration.o : tditeration.c $(HEADER)
+        $(CC) $(MYCFLAGS) -c tditeration.c
+
+mafft-profile.o : mafft-profile.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c mafft-profile.c
+
+dndfast4.o : dndfast4.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndfast4.c
+
+dndfast5.o : dndfast5.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndfast5.c
+
+dndfast6.o : dndfast6.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndfast6.c
+
+dndfast7.o : dndfast7.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndfast7.c
+
+dndblast.o : dndblast.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndblast.c
+
+dndfast3.o : dndfast3.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c dndfast3.c
+
+dndpre.o : dndpre.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c dndpre.c
+
+countlen.o : countlen.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c countlen.c
+
+seq2regtable.o : seq2regtable.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c seq2regtable.c
+
+regtable2seq.o : regtable2seq.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c regtable2seq.c
+
+f2cl.o : f2cl.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c f2cl.c
+
+replaceu.o : replaceu.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c replaceu.c
+
+restoreu.o : restoreu.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c restoreu.c
+
+mccaskillwrap.o : mccaskillwrap.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c mccaskillwrap.c
+
+contrafoldwrap.o : contrafoldwrap.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c contrafoldwrap.c
+
+pairlocalalign.o : pairlocalalign.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c pairlocalalign.c
+
+pairash.o : pairash.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c pairash.c
+
+rnatest.o : rnatest.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c rnatest.c
+
+multi2hat3s.o : multi2hat3s.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c multi2hat3s.c
+
+pair2hat3s.o : pair2hat3s.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c pair2hat3s.c
+
+dndpre2.o : dndpre2.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c dndpre2.c
+
+io.o : io.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c io.c
+
+nj.o : nj.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c nj.c
+
+treeOperation.o : treeOperation.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c treeOperation.c
+
+sextet5.o : sextet5.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c sextet5.c
+
+mafft-distance.o : mafft-distance.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c mafft-distance.c
+
+triplet5.o : triplet5.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c triplet5.c
+
+triplet6.o : triplet6.c $(HEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c triplet6.c
+
+fft.o : fft.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c fft.c 
+
+fftFunctions.o : fftFunctions.c $(HEADER) $(FFTHEADER)
+       $(CC) $(MYCFLAGS) -c fftFunctions.c
+
+Falign.o : Falign.c $(HEADER) $(FFTHEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c Falign.c
+
+Falign_localhom.o : Falign_localhom.c $(HEADER) $(FFTHEADER) $(MTXHEADER)
+       $(CC) $(MYCFLAGS) -c Falign_localhom.c
+
+mtxutl.o : mtxutl.c 
+       $(CC) $(MYCFLAGS) -c mtxutl.c
+
+addfunctions.o : addfunctions.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c addfunctions.c
+
+score.o : score.c $(HEADER)
+       $(CC) $(MYCFLAGS) -c score.c
+
+clean :
+       rm -f *.o *.a *.exe *~ $(PROGS)  $(SCRIPTS)
+#      rm -f ../binaries/* ../scripts/*
+
+install : all
+       mkdir -p $(LIBDIR)
+       chmod 755 $(LIBDIR)
+       mkdir -p $(BINDIR)
+       chmod 755 $(BINDIR)
+       chmod 755 $(SCRIPTS)
+       $(INSTALL) $(SCRIPTS)  $(BINDIR)
+       chmod 755 $(PROGS)
+       $(INSTALL) $(PROGS) $(LIBDIR)
+       $(INSTALL) -m 644 $(MANPAGES) $(LIBDIR)
+
+       ( cd $(BINDIR); \
+rm -f linsi ginsi einsi fftns fftnsi nwns nwnsi xinsi qinsi; \
+rm -f mafft-linsi mafft-ginsi mafft-einsi mafft-fftns mafft-fftnsi mafft-nwns mafft-nwnsi mafft-xinsi mafft-qinsi; \
+ln -s mafft linsi; ln -s mafft ginsi; ln -s mafft fftns; \
+ln -s mafft fftnsi; ln -s mafft nwns; ln -s mafft nwnsi; \
+ln -s mafft einsi; \
+ln -s mafft mafft-linsi; ln -s mafft mafft-ginsi; ln -s mafft mafft-fftns; \
+ln -s mafft mafft-fftnsi; ln -s mafft mafft-nwns; ln -s mafft mafft-nwnsi; \
+ln -s mafft mafft-einsi; ln -s mafft mafft-xinsi; ln -s mafft mafft-qinsi;\
+rm -f mafft-profile mafft-profile.exe; ln -s $(LIBDIR)/mafft-profile .; \
+rm -f mafft-distance mafft-distance.exe; ln -s $(LIBDIR)/mafft-distance . )
+
+       mkdir -p $(MANDIR)
+       chmod 755 $(MANDIR)
+       $(INSTALL) -m 644 $(MANPAGES) $(MANDIR)
+# remove incorrectly installed manpages by previous versions
+#      rm -f /usr/local/man/man1/mafft.1 /usr/local/man/man1/mafft-homologs.1 
diff --git a/binaries/src/mafft/core/Qalignmm.c b/binaries/src/mafft/core/Qalignmm.c
new file mode 100644 (file)
index 0000000..bc7167c
--- /dev/null
@@ -0,0 +1,2181 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 1
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+
+
+static TLS float **impmtx = NULL;
+static TLS int impalloclen = 0;
+#if 1 // tditeration to naiveQscore_imp de tsukawareru.
+float imp_match_out_scQ( int i1, int j1 )
+{
+//     fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold );
+//     fprintf( stderr, "val = %f\n", impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+}
+#endif
+
+static void imp_match_out_veadQ_gapmap( float *imp, int i1, int lgth2, int *gapmap2 )
+{
+#if FASTMATCHCALC
+       float *pt = impmtx[i1];
+       int *gapmappt = gapmap2;
+       while( lgth2-- )
+               *imp++ += pt[*gapmappt++];
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[gapmap2[j]];
+#endif
+}
+
+
+static void imp_match_out_vead_tateQ_gapmap( float *imp, int j1, int lgth1, int *gapmap1 )
+{
+#if FASTMATCHCALC
+       int *gapmappt = gapmap1;
+       while( lgth1-- )
+               *imp++ += impmtx[*gapmappt++][j1];
+#else
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[gapmap1[i]][j1];
+#endif
+}
+
+
+static void imp_match_out_veadQ( float *imp, int i1, int lgth2 )
+{
+#if FASTMATCHCALC 
+       float *pt = impmtx[i1];
+       while( lgth2-- )
+               *imp++ += *pt++;
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[j];
+#endif
+}
+static void imp_match_out_vead_tateQ( float *imp, int j1, int lgth1 )
+{
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[i][j1];
+}
+
+void imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
+{
+       foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
+}
+
+#if 1 // tbfast.c kara yobareru.
+void imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       float effij;
+       double effijx;
+       char *pt, *pt1, *pt2;
+       static TLS char *nocount1 = NULL;
+       static TLS char *nocount2 = NULL;
+       LocalHom *tmpptr;
+
+       if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx =  fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = (float)( eff1[i] * eff2[j] * effijx );
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = pt - seq1[i] - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = pt - seq1[i] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = pt - seq1[i] - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = pt - seq2[j] - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = pt - seq2[j] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = pt - seq2[j] - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+#if 1
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+                                               impmtx[k1][k2] += tmpptr->fimportance * effij;
+//                                             fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+//                                             fprintf( stderr, "%d (%c) - %d (%c)  - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+#else
+                               while( k1 <= end1 && k2 <= end2 )
+                               {
+                                       fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 );
+                                       if( !nocount1[k1] && !nocount2[k2] )
+                                       {
+                                               impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j]  * fastathreshold;
+                                               fprintf( stderr, "marked\n" );
+                                       }
+                                       else
+                                               fprintf( stderr, "no count\n" );
+                                       k1++; k2++;
+                               }
+#endif
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+#if 0
+       if( clus1 == 1 && clus2 == 6 )
+       {
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "seq1[0] =  %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] =  %s\n", seq2[0] );
+               fprintf( stderr, "impmtx = \n" );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", (double)k2 );
+               fprintf( stderr, "\n" );
+               for( k1=0; k1<lgth1; k1++ )
+               {
+                       fprintf( stderr, "%d ", k1 );
+                       for( k2=0; k2<3; k2++ )
+                               fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+                       fprintf( stderr, "\n" );
+               }
+               exit( 1 );
+       }
+#endif
+}
+#endif
+
+
+static void clearvec( float *match, int lgth )
+{
+       while( lgth-- ) *match++ = 0.0;
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+                               scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
+//                     scarr[l] *= consweight_multi;
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+// simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
+//             scarr[l] *= consweight_multi;
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom_gapmap( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int *gapmap1, int *gapmap2 )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+//     char gap[] = "-";
+       char *gap;
+       float wm;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin != lgth1 && jin != lgth2 ) // ??
+               {
+                       *impwmpt += imp_match_out_scQ( gapmap1[iin], gapmap2[jin] );
+//                     fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+}
+
+#if 0
+static void Atracking_localhom_gapmap_bk( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int *gapmap1, int *gapmap2 )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_scQ( gapmap1[iin], gapmap2[jin] );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = '-';
+               *--gaptable2 = '-';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       fprintf( stderr, "mseq1[0] = %s\n", mseq1[0] );
+       fprintf( stderr, "mseq2[0] = %s\n", mseq2[0] );
+
+
+       free( gt1bk );
+       free( gt2bk );
+}
+
+#endif
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_scQ( iin, jin );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+}
+
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+       return( 0.0 );
+}
+
+float Q__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+       fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex );
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *digf1;
+       static TLS float *digf2;
+       static TLS float *diaf1;
+       static TLS float *diaf2;
+       static TLS float *gapz1;
+       static TLS float *gapz2;
+       static TLS float *gapf1;
+       static TLS float *gapf2;
+       static TLS float *ogcp1g;
+       static TLS float *ogcp2g;
+       static TLS float *fgcp1g;
+       static TLS float *fgcp2g;
+       static TLS float *og_h_dg_n1_p;
+       static TLS float *og_h_dg_n2_p;
+       static TLS float *fg_h_dg_n1_p;
+       static TLS float *fg_h_dg_n2_p;
+       static TLS float *og_t_fg_h_dg_n1_p;
+       static TLS float *og_t_fg_h_dg_n2_p;
+       static TLS float *fg_t_og_h_dg_n1_p;
+       static TLS float *fg_t_og_h_dg_n2_p;
+       static TLS float *gapz_n1;
+       static TLS float *gapz_n2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float tmppenal;
+       float *fg_t_og_h_dg_n2_p_pt;
+       float *og_t_fg_h_dg_n2_p_pt;
+       float *og_h_dg_n2_p_pt;
+       float *fg_h_dg_n2_p_pt;
+       float *gapz_n2_pt0;
+       float *gapz_n2_pt1;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fg_t_og_h_dg_n1_p_va;
+       float og_t_fg_h_dg_n1_p_va;
+       float og_h_dg_n1_p_va;
+       float fg_h_dg_n1_p_va;
+       float gapz_n1_va0;
+       float gapz_n1_va1;
+       float fgcp1va;
+       float ogcp1va;
+       float kyokaipenal;
+#if 1
+       float fpenalty = (float)penalty;
+#else
+       float fpenalty;
+       if( RNAscoremtx != 'r' ) fpenalty = (float)penalty;
+       else fpenalty = (float)penalty * 10;
+#endif
+
+#if 0
+       fprintf( stderr, "####  seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "####  seq2[0] = %s\n", seq2[0] );
+#endif
+
+
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 0
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+#endif
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( digf1 );
+                       FreeFloatVec( digf2 );
+                       FreeFloatVec( diaf1 );
+                       FreeFloatVec( diaf2 );
+                       FreeFloatVec( gapz1 );
+                       FreeFloatVec( gapz2 );
+                       FreeFloatVec( gapf1 );
+                       FreeFloatVec( gapf2 );
+                       FreeFloatVec( ogcp1g );
+                       FreeFloatVec( ogcp2g );
+                       FreeFloatVec( fgcp1g );
+                       FreeFloatVec( fgcp2g );
+                       FreeFloatVec( og_h_dg_n1_p );
+                       FreeFloatVec( og_h_dg_n2_p );
+                       FreeFloatVec( fg_h_dg_n1_p );
+                       FreeFloatVec( fg_h_dg_n2_p );
+                       FreeFloatVec( og_t_fg_h_dg_n1_p );
+                       FreeFloatVec( og_t_fg_h_dg_n2_p );
+                       FreeFloatVec( fg_t_og_h_dg_n1_p );
+                       FreeFloatVec( fg_t_og_h_dg_n2_p );
+                       FreeFloatVec( gapz_n1 );
+                       FreeFloatVec( gapz_n2 );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               digf1 = AllocateFloatVec( ll1+2 );
+               digf2 = AllocateFloatVec( ll2+2 );
+               diaf1 = AllocateFloatVec( ll1+2 );
+               diaf2 = AllocateFloatVec( ll2+2 );
+               gapz1 = AllocateFloatVec( ll1+2 );
+               gapz2 = AllocateFloatVec( ll2+2 );
+               gapf1 = AllocateFloatVec( ll1+2 );
+               gapf2 = AllocateFloatVec( ll2+2 );
+               ogcp1g = AllocateFloatVec( ll1+2 );
+               ogcp2g = AllocateFloatVec( ll2+2 );
+               fgcp1g = AllocateFloatVec( ll1+2 );
+               fgcp2g = AllocateFloatVec( ll2+2 );
+               og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               gapz_n1 = AllocateFloatVec( ll1+2 );
+               gapz_n2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+#if 0
+       {
+               float t = 0.0;
+               for( i=0; i<icyc; i++ )
+                       t += eff1[i];
+       fprintf( stderr, "## totaleff = %f\n", t );
+       }
+#endif
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
+               getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
+               getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
+               getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
+               getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
+               getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       lastj = lgth2+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               gapz_n2[i] = (1.0-gapz2[i]);
+       }
+       lastj = lgth1+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               gapz_n1[i] = (1.0-gapz1[i]);
+       }
+#endif
+
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       if( RNAscoremtx != 'r' )
+               match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       else
+               clearvec( initverticalw, lgth1 );
+       if( localhom )
+               imp_match_out_vead_tateQ( initverticalw, 0, lgth1 ); // 060306
+
+       if( RNAscoremtx != 'r' )
+               match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       else
+               clearvec( currentw, lgth2 );
+       if( localhom )
+               imp_match_out_veadQ( currentw, 0, lgth2 ); // 060306
+
+
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+
+
+       kyokaipenal = 0.0;
+       if( outgap == 1 )
+       {
+               g = 0.0;
+
+               g += ogcp1g[0] * og_h_dg_n2_p[0];
+//             g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += ogcp2g[0] * og_h_dg_n1_p[0];
+//             g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += fgcp1g[0] * fg_h_dg_n2_p[0];
+//             g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               g += fgcp2g[0] * fg_h_dg_n1_p[0];
+//             g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               kyokaipenal = g;
+               initverticalw[0] += g;
+               currentw[0] += g;
+
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
+//                     tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+fgcp1g[0]-digf1[0]) ) * 0.5 * fpenalty; // mada
+                       initverticalw[i] += tmppenal;
+
+                       tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       initverticalw[i] += tmppenal;
+
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
+//                     tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+fgcp2g[0]-digf2[0]) ) * 0.5 * fpenalty; // mada
+                       currentw[j] += tmppenal;
+
+                       tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       currentw[j] += tmppenal;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       m[0] = 0.0; // iranai
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               mp[j] = 0;
+               m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               if( RNAscoremtx != 'r' )
+                       match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+               else
+                       clearvec( currentw, lgth2 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_veadQ( currentw, i, lgth2 );
+#else
+                       imp_match_out_veadQ( currentw, i, lgth2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mpi = 0;
+               mi = previousw[0] + 10000 * fpenalty;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
+               og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
+               og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
+               fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
+               gapz_n2_pt0 = gapz_n2 + 1;
+               gapz_n2_pt1 = gapz_n2 + 2;
+               fgcp2pt = fgcp2g + 1;
+               ogcp2pt = ogcp2g + 1;
+
+               fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
+               og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
+               og_h_dg_n1_p_va = og_h_dg_n1_p[i];
+               fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
+               gapz_n1_va0 = gapz_n1[i];
+               gapz_n1_va1 = gapz_n1[i+1];
+               fgcp1va = fgcp1g[i];
+               ogcp1va = ogcp1g[i];
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+
+                       g = ogcp1va * *og_h_dg_n2_p_pt;
+//                     g = ogcp1g[i] * og_h_dg_n2_p[j];
+//                     g = ogcp1g[i] * ( 1.0-ogcp2g[j]-digf2[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = *ogcp2pt * og_h_dg_n1_p_va;
+//                     g = ogcp2g[j] * og_h_dg_n1_p[i];
+//                     g = ogcp2g[j] * ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = fgcp1va * *fg_h_dg_n2_p_pt;
+//                     g = fgcp1g[i] * fg_h_dg_n2_p[j];
+//                     g = fgcp1g[i] * ( 1.0-fgcp2g[j]-digf2[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal3=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = *fgcp2pt * fg_h_dg_n1_p_va;
+//                     g = fgcp2g[j] * fg_h_dg_n1_p[i];
+//                     g = fgcp2g[j] * ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal4=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
+//                     tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       if( (g=mi+tmppenal) > wm )
+                       {
+//                             fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
+//                     tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*prept+tmppenal) >= mi )
+                       {
+//                             fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               mi = g;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+            mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
+//                     tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*mjpt+tmppenal) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
+//                     tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*prept+tmppenal) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+
+#if USE_PENALTY_EX
+            m[j] += fpenalty_ex;
+#endif
+
+
+
+
+
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fg_t_og_h_dg_n2_p_pt++;
+                       og_t_fg_h_dg_n2_p_pt++;
+                       og_h_dg_n2_p_pt++;
+                       fg_h_dg_n2_p_pt++;
+                       gapz_n2_pt0++;
+                       gapz_n2_pt1++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+
+       return( wm );
+}
+
+float Q__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *gapmap1, int *gapmap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+       fprintf( stderr, "fpenalty_ex = %f\n", fpenalty_ex );
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *digf1;
+       static TLS float *digf2;
+       static TLS float *diaf1;
+       static TLS float *diaf2;
+       static TLS float *gapz1;
+       static TLS float *gapz2;
+       static TLS float *gapf1;
+       static TLS float *gapf2;
+       static TLS float *ogcp1g;
+       static TLS float *ogcp2g;
+       static TLS float *fgcp1g;
+       static TLS float *fgcp2g;
+       static TLS float *og_h_dg_n1_p;
+       static TLS float *og_h_dg_n2_p;
+       static TLS float *fg_h_dg_n1_p;
+       static TLS float *fg_h_dg_n2_p;
+       static TLS float *og_t_fg_h_dg_n1_p;
+       static TLS float *og_t_fg_h_dg_n2_p;
+       static TLS float *fg_t_og_h_dg_n1_p;
+       static TLS float *fg_t_og_h_dg_n2_p;
+       static TLS float *gapz_n1;
+       static TLS float *gapz_n2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float tmppenal;
+       float *fg_t_og_h_dg_n2_p_pt;
+       float *og_t_fg_h_dg_n2_p_pt;
+       float *og_h_dg_n2_p_pt;
+       float *fg_h_dg_n2_p_pt;
+       float *gapz_n2_pt0;
+       float *gapz_n2_pt1;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fg_t_og_h_dg_n1_p_va;
+       float og_t_fg_h_dg_n1_p_va;
+       float og_h_dg_n1_p_va;
+       float fg_h_dg_n1_p_va;
+       float gapz_n1_va0;
+       float gapz_n1_va1;
+       float fgcp1va;
+       float ogcp1va;
+       float kyokaipenal;
+       float fpenalty = (float)penalty;
+
+#if 0
+       fprintf( stderr, "####  seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "####  seq2[0] = %s\n", seq2[0] );
+#endif
+
+
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 0
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+#endif
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( digf1 );
+                       FreeFloatVec( digf2 );
+                       FreeFloatVec( diaf1 );
+                       FreeFloatVec( diaf2 );
+                       FreeFloatVec( gapz1 );
+                       FreeFloatVec( gapz2 );
+                       FreeFloatVec( gapf1 );
+                       FreeFloatVec( gapf2 );
+                       FreeFloatVec( ogcp1g );
+                       FreeFloatVec( ogcp2g );
+                       FreeFloatVec( fgcp1g );
+                       FreeFloatVec( fgcp2g );
+                       FreeFloatVec( og_h_dg_n1_p );
+                       FreeFloatVec( og_h_dg_n2_p );
+                       FreeFloatVec( fg_h_dg_n1_p );
+                       FreeFloatVec( fg_h_dg_n2_p );
+                       FreeFloatVec( og_t_fg_h_dg_n1_p );
+                       FreeFloatVec( og_t_fg_h_dg_n2_p );
+                       FreeFloatVec( fg_t_og_h_dg_n1_p );
+                       FreeFloatVec( fg_t_og_h_dg_n2_p );
+                       FreeFloatVec( gapz_n1 );
+                       FreeFloatVec( gapz_n2 );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               digf1 = AllocateFloatVec( ll1+2 );
+               digf2 = AllocateFloatVec( ll2+2 );
+               diaf1 = AllocateFloatVec( ll1+2 );
+               diaf2 = AllocateFloatVec( ll2+2 );
+               gapz1 = AllocateFloatVec( ll1+2 );
+               gapz2 = AllocateFloatVec( ll2+2 );
+               gapf1 = AllocateFloatVec( ll1+2 );
+               gapf2 = AllocateFloatVec( ll2+2 );
+               ogcp1g = AllocateFloatVec( ll1+2 );
+               ogcp2g = AllocateFloatVec( ll2+2 );
+               fgcp1g = AllocateFloatVec( ll1+2 );
+               fgcp2g = AllocateFloatVec( ll2+2 );
+               og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               gapz_n1 = AllocateFloatVec( ll1+2 );
+               gapz_n2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+#if 0
+       {
+               float t = 0.0;
+               for( i=0; i<icyc; i++ )
+                       t += eff1[i];
+       fprintf( stderr, "## totaleff = %f\n", t );
+       }
+#endif
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
+               getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
+               getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
+               getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
+               getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
+               getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       lastj = lgth2+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               gapz_n2[i] = (1.0-gapz2[i]);
+       }
+       lastj = lgth1+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               gapz_n1[i] = (1.0-gapz1[i]);
+       }
+#endif
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       if( RNAscoremtx != 'r' )
+               match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       else
+               clearvec( initverticalw, lgth1 );
+       if( localhom )
+               imp_match_out_vead_tateQ_gapmap( initverticalw, gapmap2[0], lgth1, gapmap1 ); // 060306
+
+       if( RNAscoremtx != 'r' )
+               match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       else
+               clearvec( currentw, lgth2 );
+       if( localhom )
+               imp_match_out_veadQ_gapmap( currentw, gapmap1[0], lgth2, gapmap2 ); // 060306
+
+
+
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+
+
+       kyokaipenal = 0.0;
+       if( outgap == 1 )
+       {
+               g = 0.0;
+
+               g += ogcp1g[0] * og_h_dg_n2_p[0];
+//             g += ogcp1g[0] * ( 1.0-ogcp2g[0]-digf2[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += ogcp2g[0] * og_h_dg_n1_p[0];
+//             g += ogcp2g[0] * ( 1.0-ogcp1g[0]-digf1[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += fgcp1g[0] * fg_h_dg_n2_p[0];
+//             g += fgcp1g[0] * ( 1.0-fgcp2g[0]-digf2[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               g += fgcp2g[0] * fg_h_dg_n1_p[0];
+//             g += fgcp2g[0] * ( 1.0-fgcp1g[0]-digf1[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               kyokaipenal = g;
+               initverticalw[0] += g;
+               currentw[0] += g;
+
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
+//                     tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+fgcp1g[0]-digf1[0]) ) * 0.5 * fpenalty; // mada
+                       initverticalw[i] += tmppenal;
+
+                       tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       initverticalw[i] += tmppenal;
+
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
+//                     tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+fgcp2g[0]-digf2[0]) ) * 0.5 * fpenalty; // mada
+                       currentw[j] += tmppenal;
+
+                       tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       currentw[j] += tmppenal;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       m[0] = 0.0; // iranai
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               mp[j] = 0;
+               m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               if( RNAscoremtx != 'r' )
+                       match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+               else
+                       clearvec( currentw, lgth2 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_veadQ( currentw, i, lgth2 );
+#else
+                       imp_match_out_veadQ_gapmap( currentw, gapmap1[i], lgth2, gapmap2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mpi = 0;
+               mi = previousw[0] + 10000 * fpenalty;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
+               og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
+               og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
+               fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
+               gapz_n2_pt0 = gapz_n2 + 1;
+               gapz_n2_pt1 = gapz_n2 + 2;
+               fgcp2pt = fgcp2g + 1;
+               ogcp2pt = ogcp2g + 1;
+
+               fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
+               og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
+               og_h_dg_n1_p_va = og_h_dg_n1_p[i];
+               fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
+               gapz_n1_va0 = gapz_n1[i];
+               gapz_n1_va1 = gapz_n1[i+1];
+               fgcp1va = fgcp1g[i];
+               ogcp1va = ogcp1g[i];
+
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+
+                       g = ogcp1va * *og_h_dg_n2_p_pt;
+//                     g = ogcp1g[i] * og_h_dg_n2_p[j];
+//                     g = ogcp1g[i] * ( 1.0-ogcp2g[j]-digf2[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = *ogcp2pt * og_h_dg_n1_p_va;
+//                     g = ogcp2g[j] * og_h_dg_n1_p[i];
+//                     g = ogcp2g[j] * ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = fgcp1va * *fg_h_dg_n2_p_pt;
+//                     g = fgcp1g[i] * fg_h_dg_n2_p[j];
+//                     g = fgcp1g[i] * ( 1.0-fgcp2g[j]-digf2[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal3=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = *fgcp2pt * fg_h_dg_n1_p_va;
+//                     g = fgcp2g[j] * fg_h_dg_n1_p[i];
+//                     g = fgcp2g[j] * ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal4=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
+//                     tmppenal = gapz_n1[i+1] * fg_t_og_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       if( (g=mi+tmppenal) > wm )
+                       {
+//                             fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
+//                     tmppenal = gapz_n1[i] * og_t_fg_h_dg_n2_p[j];
+//                     tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*prept+tmppenal) >= mi )
+                       {
+//                             fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               mi = g;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+            mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
+//                     tmppenal = gapz_n2[j+1] * fg_t_og_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*mjpt+tmppenal) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
+//                     tmppenal = gapz_n2[j] * og_t_fg_h_dg_n1_p[i];
+//                     tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       if( (g=*prept+tmppenal) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+
+#if USE_PENALTY_EX
+            m[j] += fpenalty_ex;
+#endif
+
+
+
+
+
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fg_t_og_h_dg_n2_p_pt++;
+                       og_t_fg_h_dg_n2_p_pt++;
+                       og_h_dg_n2_p_pt++;
+                       fg_h_dg_n2_p_pt++;
+                       gapz_n2_pt0++;
+                       gapz_n2_pt1++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom_gapmap( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, gapmap1, gapmap2 );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/Ralignmm.c b/binaries/src/mafft/core/Ralignmm.c
new file mode 100644 (file)
index 0000000..6e5d3b8
--- /dev/null
@@ -0,0 +1,1213 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 1
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+
+static TLS float **impmtx = NULL;
+#if 1 // tditeration to naiveRscore_imp de tsukawareru.
+float imp_match_out_scR( int i1, int j1 )
+{
+//     fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold );
+//     fprintf( stderr, "val = %f\n", impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+}
+#endif
+
+static void imp_match_out_veadR( float *imp, int i1, int lgth2 )
+{
+#if FASTMATCHCALC 
+       float *pt = impmtx[i1];
+       while( lgth2-- )
+               *imp++ += *pt++;
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[j];
+#endif
+}
+static void imp_match_out_vead_tateR( float *imp, int j1, int lgth1 )
+{
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[i][j1];
+}
+
+#if 1 // tbfast.c kara yobareru.
+void imp_match_init_strictR( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       static TLS int impalloclen = 0;
+       float effij;
+       double effijx;
+       char *pt, *pt1, *pt2;
+       static TLS char *nocount1 = NULL;
+       static char *nocount2 = NULL;
+       LocalHom *tmpptr;
+
+       if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx =  fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = (float)( eff1[i] * eff2[j] * effijx );
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = pt - seq1[i] - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = pt - seq1[i] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = pt - seq1[i] - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = pt - seq2[j] - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = pt - seq2[j] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = pt - seq2[j] - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+#if 1
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+                                               impmtx[k1][k2] += tmpptr->fimportance * effij;
+//                                             fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+//                                             fprintf( stderr, "%d (%c) - %d (%c)  - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+#else
+                               while( k1 <= end1 && k2 <= end2 )
+                               {
+                                       fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 );
+                                       if( !nocount1[k1] && !nocount2[k2] )
+                                       {
+                                               impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j]  * fastathreshold;
+                                               fprintf( stderr, "marked\n" );
+                                       }
+                                       else
+                                               fprintf( stderr, "no count\n" );
+                                       k1++; k2++;
+                               }
+#endif
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+#if 0
+       if( clus1 == 1 && clus2 == 6 )
+       {
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "seq1[0] =  %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] =  %s\n", seq2[0] );
+               fprintf( stderr, "impmtx = \n" );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", (double)k2 );
+               fprintf( stderr, "\n" );
+               for( k1=0; k1<lgth1; k1++ )
+               {
+                       fprintf( stderr, "%d ", k1 );
+                       for( k2=0; k2<3; k2++ )
+                               fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+                       fprintf( stderr, "\n" );
+               }
+               exit( 1 );
+       }
+#endif
+}
+#endif
+
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+                               scarr[l] += n_dis[j][l] * cpmx1[j][i1];
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+// simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_scR( iin, jin );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+       return( 0.0 );
+}
+
+float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *digf1;
+       static TLS float *digf2;
+       static TLS float *diaf1;
+       static TLS float *diaf2;
+       static TLS float *gapz1;
+       static TLS float *gapz2;
+       static TLS float *gapf1;
+       static TLS float *gapf2;
+       static TLS float *ogcp1g;
+       static TLS float *ogcp2g;
+       static TLS float *fgcp1g;
+       static TLS float *fgcp2g;
+       static TLS float *ogcp1;
+       static TLS float *ogcp2;
+       static TLS float *fgcp1;
+       static TLS float *fgcp2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float fpenalty = (float)penalty;
+       float tmppenal;
+       float cumpenal;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fgcp1va;
+       float ogcp1va;
+       float kyokaipenal;
+
+
+
+#if 0
+       fprintf( stderr, "####  seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "####  seq2[0] = %s\n", seq2[0] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 0
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+#endif
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( digf1 );
+                       FreeFloatVec( digf2 );
+                       FreeFloatVec( diaf1 );
+                       FreeFloatVec( diaf2 );
+                       FreeFloatVec( gapz1 );
+                       FreeFloatVec( gapz2 );
+                       FreeFloatVec( gapf1 );
+                       FreeFloatVec( gapf2 );
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+                       FreeFloatVec( ogcp1g );
+                       FreeFloatVec( ogcp2g );
+                       FreeFloatVec( fgcp1g );
+                       FreeFloatVec( fgcp2g );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               digf1 = AllocateFloatVec( ll1+2 );
+               digf2 = AllocateFloatVec( ll2+2 );
+               diaf1 = AllocateFloatVec( ll1+2 );
+               diaf2 = AllocateFloatVec( ll2+2 );
+               gapz1 = AllocateFloatVec( ll1+2 );
+               gapz2 = AllocateFloatVec( ll2+2 );
+               gapf1 = AllocateFloatVec( ll1+2 );
+               gapf2 = AllocateFloatVec( ll2+2 );
+               ogcp1 = AllocateFloatVec( ll1+2 );
+               ogcp2 = AllocateFloatVec( ll2+2 );
+               fgcp1 = AllocateFloatVec( ll1+2 );
+               fgcp2 = AllocateFloatVec( ll2+2 );
+               ogcp1g = AllocateFloatVec( ll1+2 );
+               ogcp2g = AllocateFloatVec( ll2+2 );
+               fgcp1g = AllocateFloatVec( ll1+2 );
+               fgcp2g = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+#if 0
+       {
+               float t = 0.0;
+               for( i=0; i<icyc; i++ )
+                       t += eff1[i];
+       fprintf( stderr, "## totaleff = %f\n", t );
+       }
+#endif
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
+               getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
+               getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
+               getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
+               getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
+               getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead_tateR( initverticalw, 0, lgth1 ); // 060306
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_veadR( currentw, 0, lgth2 ); // 060306
+
+
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+
+
+       kyokaipenal = 0.0;
+       if( outgap == 1 )
+       {
+               g = 0.0;
+
+               g += ogcp1g[0] * ( 1.0-ogcp2g[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal1=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += ogcp2g[0] * ( 1.0-ogcp1g[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "init-match penal2=%f, %c-%c\n", g, seq1[0][0], seq2[0][0] );
+
+               g += fgcp1g[0] * ( 1.0-fgcp2g[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               g += fgcp2g[0] * ( 1.0-fgcp1g[0] ) * fpenalty * 0.5;
+//             if( g ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+
+               kyokaipenal = g;
+               initverticalw[0] += g;
+               currentw[0] += g;
+
+               cumpenal = 0.0;
+               for( i=1; i<lgth1+1; i++ )
+               {
+//                     initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+
+//     Q               tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+fgcp1g[0]-digf1[0]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz2[0])*(1.0-ogcp1g[0]+0.0) + gapz2[0]*(1.0-digf1[0] - diaf1[0]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-0.0)*(1.0-ogcp1g[0]+0.0) + 0.0*(1.0-0.0-0.0) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-0.0) * (1.0-diaf1[0]) + 0.0 ) * 0.5 * fpenalty; // 0.
+//                     tmppenal -= ( (1.0-gapf2[j-1]) * ogcp1g[i] + gapf2[j-1] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 1 = %f\n", i, 0, tmppenal );
+                       initverticalw[i] += tmppenal;
+
+//     Q               tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz2[1])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapz2[1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[0])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[0]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[0]) * (1.0-diaf1[i]) + gapf2[0] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j]) * fgcp1g[i] + gapf2[j] ) * 0.5 * fpenalty;
+                       initverticalw[i] += tmppenal;
+                       cumpenal += ( ogcp1g[i-0] + fgcp1g[i] ) * fpenalty * 0.5;
+                       initverticalw[i] += cumpenal - fgcp1g[i] * fpenalty * 0.5; // honto ha iru
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 2 = %f, cumpenal=%f, fgcp1g[i]=%f, ogcp1g[i]=%f\n", i, 0, tmppenal, cumpenal, fgcp1g[i], ogcp1g[i] );
+
+               }
+               cumpenal = 0.0;
+               for( j=1; j<lgth2+1; j++ )
+               {
+//                     currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+
+//                     tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+fgcp2g[0]-digf2[0]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[i-1])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapf1[i-1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz1[0])*(1.0-ogcp2g[0]+0.0) + gapz1[0]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-0.0)*(1.0-ogcp2g[0]+0.0) + 0.0*(1.0-0.0-0.0) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-0.0) * (1.0-diaf2[0]) + 0.0 ) * 0.5 * fpenalty; // 0.
+//                     tmppenal -= ( (1.0-gapf1[0]) * fgcp2g[j] + gapf1[0] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 3 = %f\n", 0, j, tmppenal );
+                       currentw[j] += tmppenal;
+
+//                     tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz1[1])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapz1[1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[0])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[0]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[0]) * (1.0-diaf2[j]) + gapf1[0] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[0]) * ogcp2g[j] + gapf1[i-1] ) * 0.5 * fpenalty;
+//                     fprintf( stderr, "0,0<-%d,%d, tmppenal 4 = %f\n", 0, j, tmppenal );
+                       currentw[j] += tmppenal;
+                       cumpenal += ( ogcp2g[j-0] + fgcp2g[j] ) * fpenalty * 0.5;
+                       currentw[j] += cumpenal - fgcp2g[j] * fpenalty * 0.5; // honto ha iru
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       m[0] = 0.0; // iranai
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               mp[j] = 0;
+               m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_veadR( currentw, i, lgth2 );
+#else
+                       imp_match_out_veadR( currentw, i, lgth2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mpi = 0;
+               mi = previousw[0] + 10000 * fpenalty;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fgcp2pt = fgcp2;
+               ogcp2pt = ogcp2 + 1;
+               fgcp1va = fgcp1[i-1];
+               ogcp1va = ogcp1[i];
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+
+                       g = ogcp1g[i] * ( 1.0-ogcp2g[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal1=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = ogcp2g[j] * ( 1.0-ogcp1g[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal2=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = fgcp1g[i] * ( 1.0-fgcp2g[j] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal3=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+                       g = fgcp2g[j] * ( 1.0-fgcp1g[i] ) * fpenalty * 0.5;
+//                     if( g && i==j ) fprintf( stderr, "match penal4=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm += g;
+
+#if 0
+                       g = fgcp2g[j] * ogcp1g[i] * fpenalty * 0.5;
+                       if( g ) fprintf( stderr, "match m-penal5=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm -= g;
+
+                       g = fgcp1g[i] * ogcp2g[j] * fpenalty * 0.5;
+                       if( g ) fprintf( stderr, "match m-penal6=%f, %c-%c\n", g, seq1[0][i], seq2[0][j] );
+                       wm -= g;
+#endif
+
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+//                     tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz1[i+1])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapz1[i+1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[i])*(1.0-fgcp2g[j]+ogcp2g[j]) + gapf1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[i])*(1.0-diaf2[j]) + gapf1[i] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[i])*fgcp2g[j] + gapf1[i] ) * 0.5 * fpenalty;
+//                     tmppenal = *fgcp2pt-fpenalty*0.5*gapf1[i];
+//                     tmppenal = *fgcp2pt;
+                       if( (g=mi+tmppenal) > wm )
+                       {
+//                             fprintf( stderr, "jump i start=%f (j=%d, fgcp2g[j]=%f, digf2[j]=%f, diaf2[j]=%f), %c-%c\n", g-mi, j, fgcp2g[j], digf2[j], diaf2[j], seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+//                     tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]-digf2[j]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz1[i])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapz1[i]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf1[i-1])*(1.0-ogcp2g[j]+fgcp2g[j]) + gapf1[i-1]*(1.0-digf2[j]-diaf2[j]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = *ogcp2pt-fpenalty*0.5*(gapf2[j-1]+gapf1[i-1]);
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[i-1])*(1.0-diaf2[j]) + gapf1[i-1] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf1[i-1])*ogcp2g[j] + gapf1[i-1] ) * 0.5 * fpenalty;
+//                     tmppenal = *prept+*ogcp2pt;
+                       if( (g=*prept+tmppenal) >= mi )
+                       {
+//                             fprintf( stderr, "jump i end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               mi = g;
+                               mpi = j-1;
+                       }
+                       else if( j != 1 )
+                       {
+                               mi += ( ogcp2g[j-0] + fgcp2g[j] ) * fpenalty * 0.5; // CHUUI honto ha iru
+//                             fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", '=', '=', seq2[0][j-1], seq2[0][j], ogcp2g[j-0] * fpenalty*0.5, fgcp2g[j] * fpenalty*0.5 );
+                       }
+#if USE_PENALTY_EX
+                               mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+//                     tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz2[j+1])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapz2[j+1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]+ogcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j])*(1.0-fgcp1g[i]) + gapf2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j])*(1.0-diaf1[i]) + gapf2[j] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j])*fgcp1g[i] + gapf2[j] ) * 0.5 * fpenalty;
+//                     tmppenal = fgcp1va-fpenalty*0.5*gapf2[j];
+//                     tmppenal = fgcp1va;
+                       if( (g=*mjpt+tmppenal) > wm )
+                       {
+//                             if( seq1[0][i] == 'Y' && seq2[0][j] == 'B' )
+//                                     fprintf( stderr, "jump j start=%f, %c-%c\n", g-*mjpt, seq1[0][i], seq2[0][j] );
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+//                     tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) ) * 0.5 * fpenalty; // mada
+                       tmppenal = ( (1.0-gapz2[j])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapz2[j]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]+fgcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ( (1.0-gapf2[j-1])*(1.0-ogcp1g[i]) + gapf2[j-1]*(1.0-digf1[i]-diaf1[i]) ) * 0.5 * fpenalty; // mada
+//                     tmppenal = ogcp1va-fpenalty*0.5*(gapf1[i-1]+gapf2[j-1]);
+//                     tmppenal = 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j-1]) * (1.0-diaf1[i]) + gapf2[j-1] ) * 0.5 * fpenalty;
+//                     tmppenal -= ( (1.0-gapf2[j-1]) * ogcp1g[i] + gapf2[j-1] ) * 0.5 * fpenalty;
+//                     tmppenal = 0.5 * fpenalty - ( (1.0-gapf2[j-1]) * (ogcp1g[i]) + gapf2[j-1] ) * ( 0.5 * fpenalty );
+//                     tmppenal = ogcp1va-fpenalty*0.5*gapf2[j-1];
+//                     tmppenal = ogcp1va;
+                       if( (g=*prept+tmppenal) >= *mjpt )
+                       {
+//                             if( seq1[0][i] == 'T' && seq2[0][j] == 'T' )
+//                                     fprintf( stderr, "jump j end=%f, %c-%c\n", g-*prept, seq1[0][i-1], seq2[0][j-1] );
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+                       else if( i != 1 )
+                       {
+                               m[j] += ( ogcp1g[i-0] + fgcp1g[i] ) * fpenalty * 0.5; // CHUUI honto ha iru
+//                             fprintf( stderr, "%c%c/%c%c exp, og=%f,fg=%f\n", seq1[0][i-1], seq1[0][i], '=', '=', ogcp1g[i-0] * fpenalty*0.5, fgcp1g[i] * fpenalty*0.5 );
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+       fprintf( stderr, "wm = %f\n", wm );
+
+
+       return( wm );
+}
+
+
diff --git a/binaries/src/mafft/core/SAalignmm.c b/binaries/src/mafft/core/SAalignmm.c
new file mode 100644 (file)
index 0000000..9fc05df
--- /dev/null
@@ -0,0 +1,378 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0;
+               for( k=0; cpmxpdn[k][j] > -1;  k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+}
+
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, k, l, iin, jin, ifi, jfi, lgth1, lgth2;
+//     char gap[] = "-";
+       char *gap;
+       float wm;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if DEBUG
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+
+float Aalign( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+       register int i, j;
+       int lasti;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float x;
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *currentw;
+       static TLS float *previousw;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+
+#if DEBUG
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 1 ); 
+               mseq2 = AllocateCharMtx( njob, 1 ); /* by J. Thompson */
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( currentw );
+                       FreeFloatVec( previousw );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.1*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.1*lgth2), orlgth2 ) + 100;
+
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+
+               currentw = AllocateFloatVec( ll2+2 );
+               previousw = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+               fprintf( stderr, "succeeded\n" );
+
+               orlgth1 = ll1;
+               orlgth2 = ll2;
+       }
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+               fprintf( stderr, "succeeded\n\n" );
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+       cpmx_calc( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc );
+       cpmx_calc( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc );
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+
+       if( outgap == 1 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += penalty * 0.5;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += penalty * 0.5;
+               }
+       }
+
+       for( j=0; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + penalty * 0.5; mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+       for( i=1; i<lasti; i++ )
+       {
+
+               floatncpy( previousw, currentw, lgth2+1 );
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0] + penalty * 0.5; mpi = 0;
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       wm = previousw[j-1];
+                       ijp[i][j] = 0;
+
+                       g = penalty * 0.5;
+                       x = mi + g;
+                       if( x > wm )
+                       {
+                               wm = x;
+                               ijp[i][j] = -( j - mpi );
+                       }
+                       g = penalty * 0.5;
+                       x = previousw[j-1] + g;
+                       if( mi <= x )
+                       {
+                               mi = x;
+                               mpi = j-1;
+                       }
+
+                       g = penalty * 0.5;
+                       x = m[j] + g;
+                       if( x > wm )
+                       {
+                               wm = x;
+                               ijp[i][j] = +( i - mp[j] );
+                       }
+                       g = penalty * 0.5;
+                       x = previousw[j-1] + g;
+                       if( m[j] <= x )
+                       {
+                               m[j] = x;
+                               mp[j] = i-1;
+                       }
+                       currentw[j] += wm;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+       return( wm );
+}
diff --git a/binaries/src/mafft/core/Salignmm.c b/binaries/src/mafft/core/Salignmm.c
new file mode 100644 (file)
index 0000000..06e402e
--- /dev/null
@@ -0,0 +1,1860 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 0
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+
+static TLS float **impmtx = NULL;
+static TLS int impalloclen = 0;
+float imp_match_out_sc( int i1, int j1 )
+{
+//     fprintf( stderr, "imp+match = %f\n", impmtx[i1][j1] * fastathreshold );
+//     fprintf( stderr, "val = %f\n", impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+}
+static void imp_match_out_vead_gapmap( float *imp, int i1, int lgth2, int *gapmap2 )
+{
+#if FASTMATCHCALC
+       float *pt = impmtx[i1];
+       int *gapmappt = gapmap2;
+       while( lgth2-- )
+               *imp++ += pt[*gapmappt++];
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[gapmap2[j]];
+#endif
+}
+
+
+static void imp_match_out_vead_tate_gapmap( float *imp, int j1, int lgth1, int *gapmap1 )
+{
+#if FASTMATCHCALC
+       int *gapmappt = gapmap1;
+       while( lgth1-- )
+               *imp++ += impmtx[*gapmappt++][j1];
+#else
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[gapmap1[i]][j1];
+#endif
+}
+
+static void imp_match_out_vead( float *imp, int i1, int lgth2 )
+{
+#if FASTMATCHCALC 
+       float *pt = impmtx[i1];
+       while( lgth2-- )
+               *imp++ += *pt++;
+#else
+       int j;
+       float *pt = impmtx[i1];
+       for( j=0; j<lgth2; j++ )
+               *imp++ += pt[j];
+#endif
+}
+static void imp_match_out_vead_tate( float *imp, int j1, int lgth1 )
+{
+       int i;
+       for( i=0; i<lgth1; i++ )
+               *imp++ += impmtx[i][j1];
+}
+
+void imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *pair )
+{
+       foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, pair );
+}
+
+
+void imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       float effij;
+       float effij_kozo;
+       double effijx;
+       char *pt, *pt1, *pt2;
+       static TLS char *nocount1 = NULL;
+       static TLS char *nocount2 = NULL;
+       LocalHom *tmpptr;
+
+       if( seq1 == NULL )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               impmtx = NULL;
+               if( nocount1 ) free( nocount1 );
+               nocount1 = NULL;
+               if( nocount2 ) free( nocount2 );
+               nocount2 = NULL;
+               
+               return;
+       }
+
+       if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx =  fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = (float)( eff1[i] * eff2[j] * effijx );
+                       effij_kozo = (float)( eff1_kozo[i] * eff2_kozo[j] * effijx );
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = pt - seq1[i] - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = pt - seq1[i] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = pt - seq1[i] - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = pt - seq2[j] - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = pt - seq2[j] - 0;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = pt - seq2[j] - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+#if 1
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+//                                             impmtx[k1][k2] += tmpptr->fimportance * effij;
+                                               if( tmpptr->korh == 'k' )
+                                                       impmtx[k1][k2] += tmpptr->fimportance * effij_kozo;
+                                               else
+                                                       impmtx[k1][k2] += tmpptr->fimportance * effij;
+                                                       
+//                                             fprintf( stderr, "#### impmtx[k1][k2] = %f, tmpptr->fimportance=%f, effij=%f\n", impmtx[k1][k2], tmpptr->fimportance, effij );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+//                                             fprintf( stderr, "%d (%c) - %d (%c)  - %f\n", k1, *pt1, k2, *pt2, tmpptr->fimportance * effij );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+#else
+                               while( k1 <= end1 && k2 <= end2 )
+                               {
+                                       fprintf( stderr, "k1,k2=%d,%d - ", k1, k2 );
+                                       if( !nocount1[k1] && !nocount2[k2] )
+                                       {
+                                               impmtx[k1][k2] += tmpptr->wimportance * eff1[i] * eff2[j]  * fastathreshold;
+                                               fprintf( stderr, "marked\n" );
+                                       }
+                                       else
+                                               fprintf( stderr, "no count\n" );
+                                       k1++; k2++;
+                               }
+#endif
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+
+#if 0
+       if( clus1 == 1 && clus2 == 1 )
+       {
+               fprintf( stderr, "writing impmtx\n" );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "seq1[0] =  %s\n", seq1[0] );
+               fprintf( stderr, "seq2[0] =  %s\n", seq2[0] );
+               fprintf( stderr, "impmtx = \n" );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", (double)k2 );
+               fprintf( stderr, "\n" );
+               for( k1=0; k1<lgth1; k1++ )
+               {
+                       fprintf( stderr, "%d ", k1 );
+                       for( k2=0; k2<30; k2++ )
+                               fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+                       fprintf( stderr, "\n" );
+               }
+//             exit( 1 );
+       }
+#endif
+}
+
+#if 0
+void imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom )
+{
+       int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       static TLS int impalloclen = 0;
+       char *pt;
+       int allgap;
+       static TLS char *nocount1 = NULL;
+       static TLS char *nocount2 = NULL;
+
+       if( impalloclen < lgth1 + 2 || impalloclen < lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0;
+       for( i=0; i<clus1; i++ )
+       {
+               fprintf( stderr, "i = %d, seq1 = %s\n", i, seq1[i] );
+               for( j=0; j<clus2; j++ )
+               {
+                       fprintf( stderr, "start1 = %d\n", localhom[i][j]->start1 );
+                       fprintf( stderr, "end1   = %d\n", localhom[i][j]->end1   );
+                       fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] );
+                       pt = seq1[i];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start1 ) break;
+                       }
+                       start1 = pt - seq1[i] - 1;
+
+                       while( *pt != 0 )
+                       {
+//                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] );
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end1 ) break;
+                       }
+                       end1 = pt - seq1[i] - 1;
+
+                       pt = seq2[j];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start2 ) break;
+                       }
+                       start2 = pt - seq2[j] - 1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end2 ) break;
+                       }
+                       end2 = pt - seq2[j] - 1;
+//                     fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                       k1 = start1;
+                       k2 = start2;
+                       fprintf( stderr, "step 0\n" );
+                       while( k1 <= end1 && k2 <= end2 )
+                       {
+#if 0
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#else
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#endif
+                       }
+
+                       dif = ( end1 - start1 ) - ( end2 - start2 );
+                       fprintf( stderr, "dif = %d\n", dif );
+                       if( dif > 0 )
+                       {
+                               do
+                               {
+                                       fprintf( stderr, "dif = %d\n", dif );
+                                       k1 = start1;
+                                       k2 = start2 - dif;
+                                       while( k1 <= end1 && k2 <= end2 )
+                                       {
+                                               if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif-- );
+                       }
+                       else
+                       {
+                               do
+                               {
+                                       k1 = start1 + dif;
+                                       k2 = start2;
+                                       while( k1 <= end1 )
+                                       {
+                                               if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif++ );
+                       }
+               }
+       }
+#if 0
+       fprintf( stderr, "impmtx = \n" );
+       for( k2=0; k2<lgth2; k2++ )
+               fprintf( stderr, "%6.3f ", (double)k2 );
+       fprintf( stderr, "\n" );
+       for( k1=0; k1<lgth1; k1++ )
+       {
+               fprintf( stderr, "%d", k1 );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", impmtx[k1][k2] );
+               fprintf( stderr, "\n" );
+       }
+#endif
+}
+#endif
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+//                             scarr[l] += n_dis[j][l] * cpmx1[j][i1];
+                               scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+// simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
+//                     scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_sc( iin, jin );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+}
+static void Atracking_localhom_gapmap( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int *gapmap1, int *gapmap2 )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin == lgth1 || jin == lgth2 )
+                       ;
+               else
+               {
+                       *impwmpt += imp_match_out_sc( gapmap1[iin], gapmap2[jin] );
+
+//             fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = '-';
+               *--gaptable2 = '-';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+}
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int tailgp )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+       float wm;
+       char *gaptable1, *gt1bk;
+       char *gaptable2, *gt2bk;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       gt1bk = AllocateCharVec( lgth1+lgth2+1 );
+       gt2bk = AllocateCharVec( lgth1+lgth2+1 );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( tailgp == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       gaptable1 = gt1bk + lgth1+lgth2;
+       *gaptable1 = 0;
+       gaptable2 = gt2bk + lgth1+lgth2;
+       *gaptable2 = 0;
+
+       iin = lgth1; jin = lgth2;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--gaptable1 = 'o';
+                       *--gaptable2 = '-';
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--gaptable1 = '-';
+                       *--gaptable2 = 'o';
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--gaptable1 = 'o';
+               *--gaptable2 = 'o';
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+       for( i=0; i<icyc; i++ ) gapireru( mseq1[i], seq1[i], gaptable1 );
+       for( j=0; j<jcyc; j++ ) gapireru( mseq2[j], seq2[j], gaptable2 );
+
+       free( gt1bk );
+       free( gt2bk );
+
+       return( 0.0 );
+}
+
+float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres, int headgp, int tailgp )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *ogcp1;
+       static TLS float *ogcp2;
+       static TLS float *fgcp1;
+       static TLS float *fgcp2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float fpenalty = (float)penalty;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fgcp1va;
+       float ogcp1va;
+
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 )
+               {
+//                     fprintf( stderr, "## Freeing local arrays in A__align\n" );
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+
+                       imp_match_init_strict( NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 );
+
+                       free( mseq1 );
+                       free( mseq2 );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+
+               }
+               else
+               {
+//                     fprintf( stderr, "## Not allocated\n" );
+               }
+               return( 0.0 );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 1
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalignmm): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+       if( lgth1 == 0 && lgth2 == 0 )
+               return( 0.0 );
+
+       if( lgth1 == 0 )
+       {
+               for( i=0; i<icyc; i++ )
+               {
+                       j = lgth2;
+                       seq1[i][j] = 0;
+                       while( j ) seq1[i][--j] = '-';
+//                     fprintf( stderr, "seq1[i] = %s\n", seq1[i] );
+               }
+               return( 0.0 );
+       }
+
+       if( lgth2 == 0 )
+       {
+               for( i=0; i<jcyc; i++ )
+               {
+                       j = lgth1;
+                       seq2[i][j] = 0;
+                       while( j ) seq2[i][--j] = '-';
+//                     fprintf( stderr, "seq2[i] = %s\n", seq2[i] );
+               }
+               return( 0.0 );
+       }
+#endif
+
+
+#if 0
+       fprintf( stderr, "####  eff in SA+++align\n" );
+       fprintf( stderr, "####  seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "####  strlen( seq1[0] ) = %d\n", strlen( seq1[0] ) );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+       fprintf( stderr, "####  seq2[0] = %s\n", seq2[0] );
+       fprintf( stderr, "####  strlen( seq2[0] ) = %d\n", strlen( seq2[0] ) );
+       for( i=0; i<jcyc; i++ ) fprintf( stderr, "eff2[%d] = %f\n", i, eff2[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               ogcp1 = AllocateFloatVec( ll1+2 );
+               ogcp2 = AllocateFloatVec( ll2+2 );
+               fgcp1 = AllocateFloatVec( ll1+2 );
+               fgcp2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 27 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+#if 0
+       {
+               float t = 0.0;
+               for( i=0; i<icyc; i++ )
+                       t += eff1[i];
+       fprintf( stderr, "## totaleff = %f\n", t );
+       }
+#endif
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
+               new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
+               new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap1 );
+               new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+       }
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
+       }
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead_tate( initverticalw, 0, lgth1 ); // 060306
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead( currentw, 0, lgth2 ); // 060306
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+       if( headgp == 1 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( tailgp ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+
+#ifdef enablemultithread
+//             fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+               if( chudanpt && *chudanpt != chudanref ) 
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! S\n" );
+                       *chudanres = 1;
+                       return( -1.0 );
+               }
+#endif
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_vead( currentw, i, lgth2 );
+#else
+                       imp_match_out_vead( currentw, i, lgth2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+
+               mi = previousw[0] + ogcp2[1]; mpi = 0;
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fgcp2pt = fgcp2;
+               ogcp2pt = ogcp2 + 1;
+               fgcp1va = fgcp1[i-1];
+               ogcp1va = ogcp1[i];
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+#ifdef xxxenablemultithread
+//                     fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+                       if( chudanpt && *chudanpt != chudanref ) 
+                       {
+//                             fprintf( stderr, "\n\n## CHUUDAN!!! S\n" );
+                               *chudanres = 1;
+                               return( -1.0 );
+                       }
+#endif
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+*fgcp2pt) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       if( (g=*prept+*ogcp2pt) >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+fgcp1va) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       if( (g=*prept+ogcp1va) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, tailgp );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+#if 0
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+#endif
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       return( wm );
+}
+
+float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj;     /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+//     float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *ogcp1;
+       static TLS float *ogcp2;
+       static TLS float *fgcp1;
+       static TLS float *fgcp2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fgcp1va;
+       float ogcp1va;
+
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 0
+       if( lgth1 == 0 || lgth2 == 0 )
+       {
+               fprintf( stderr, "WARNING (Aalign_gapmap): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+#endif
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               ogcp1 = AllocateFloatVec( ll1+2 );
+               ogcp2 = AllocateFloatVec( ll2+2 );
+               fgcp1 = AllocateFloatVec( ll1+2 );
+               fgcp2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 27, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] = mseq[i];
+               seq1[i][lgth1] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] = mseq[icyc+j];
+               seq2[j][lgth2] = 0;
+       }
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+       cpmx_calc_new( seq1, cpmx1, eff1, strlen( seq1[0] ), icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, strlen( seq2[0] ), jcyc );
+
+       st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1  );
+       st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+       st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+       st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] );
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] );
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] );
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] );
+       }
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead_tate_gapmap( initverticalw, gapmap2[0], lgth1, gapmap1 ); // 060306
+
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               imp_match_out_vead_gapmap( currentw, gapmap1[0], lgth2, gapmap2 ); // 060306
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+       if( 1 ) // tsuneni outgap=1
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;
+       }
+
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0;
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( 1 ) lasti = lgth1+1; else lasti = lgth1; // tsuneni outgap=1
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+#if  0
+                       imp_match_out_vead( currentw, i, lgth2 );
+#else
+                       imp_match_out_vead_gapmap( currentw, gapmap1[i], lgth2, gapmap2 );
+#endif
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+
+               mi = previousw[0] + ogcp2[1]; mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fgcp2pt = fgcp2;
+               ogcp2pt = ogcp2 + 1;
+               fgcp1va = fgcp1[i-1];
+               ogcp1va = ogcp1[i];
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + *fgcp2pt;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + *ogcp2pt;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1va;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + ogcp1va;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom_gapmap( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, gapmap1, gapmap2 );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, 1 );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/addfunctions.c b/binaries/src/mafft/core/addfunctions.c
new file mode 100644 (file)
index 0000000..1169581
--- /dev/null
@@ -0,0 +1,437 @@
+#include "mltaln.h"
+
+void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg ) // n1 ha allgap
+{
+       int i, newlen;
+       double *effarr0, *effarr2;
+       float dumfl;
+       double eff;
+       effarr0 = AllocateDoubleVec( n0 );
+       effarr2 = AllocateDoubleVec( n2 );
+
+       commongappick( n0, aln0 );
+       commongappick( n2, aln2 );
+
+
+       eff = 1.0 / (double)n0; for( i=0; i<n0; i++ ) effarr0[i] = eff;
+       eff = 1.0 / (double)n2; for( i=0; i<n2; i++ ) effarr2[i] = eff;
+
+       if( alg == 'M' )
+               MSalignmm( aln0, aln2, effarr0, effarr2, n0, n2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); //outgap=1??
+       else
+               A__align( aln0, aln2, effarr0, effarr2, n0, n2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 ); //outgap=1??
+
+       newlen = strlen( aln0[0] );
+
+       for( i=0; i<newlen; i++ ) aln1[0][i] = '-';
+       aln1[0][i] = 0;
+       for( i=1; i<n1; i++ ) strcpy( aln1[i], aln1[0] );
+
+
+       free( effarr0 );
+       free( effarr2 );
+}
+
+void eq2dash( char *s )
+{
+       while( *s )
+       {
+               if( *s == '=' ) *s = '-';
+               s++;
+       }
+}
+
+void findnewgaps( int n, char **seq, int *gaplen )
+{
+       int i, pos, len;
+       len = strlen( seq[0] ); 
+
+//     fprintf( stderr, "seq[0] = %s\n", seq[0] );
+       for( i=0; i<len; i++ ) gaplen[i] = 0;
+       
+       pos = 0;
+       for( i=0; i<len; i++ )
+       {
+               if( seq[0][i] == '=' ) 
+               {
+//                     fprintf( stderr, "Newgap! pos = %d\n", pos );
+                       gaplen[pos]++;
+               }
+               else
+                       pos++;
+       }
+}
+
+void findcommongaps( int n, char **seq, int *gaplen )
+{
+       int i, j, pos, len, len1;
+       len = strlen( seq[0] ); 
+       len1 = len+1;
+
+//     fprintf( stderr, "seq[0] = %s\n", seq[0] );
+       for( i=0; i<len1; i++ ) gaplen[i] = 0;
+       
+       pos = 0;
+       for( i=0; i<len; i++ )
+       {
+               for( j=0; j<n; j++ )
+                       if( seq[j][i] != '-' ) break;
+
+               if( j == n ) gaplen[pos]++;
+               else
+                       pos++;
+       }
+#if 0
+       for( i=0; i<pos; i++ )
+       {
+               fprintf( stderr, "vec[%d] = %d\n", i, gaplen[i] );
+       }
+#endif
+}
+
+void adjustgapmap( int newlen, int *gapmap, char *seq )
+{
+       int j;
+       int pos;
+       int newlen1 = newlen+1;
+       int *tmpmap;
+
+       tmpmap = AllocateIntVec( newlen+2 );
+       j = 0;
+       pos = 0;
+       while( *seq )
+       {
+//             fprintf( stderr, "j=%d *seq = %c\n", j, *seq );
+               if( *seq++ == '=' )
+                       tmpmap[j++] = 0;
+               else
+               {
+                       tmpmap[j++] = gapmap[pos++];
+               }
+       }
+       tmpmap[j++] = gapmap[pos];
+
+       for(j=0; j<newlen1; j++)
+               gapmap[j] = tmpmap[j];
+
+       free( tmpmap );
+}
+
+void insertnewgaps( int njob, int *alreadyaligned, char **seq, int *ex1, int *ex2, int *gaplen, int *gapmap, int alloclen, char alg )
+{
+       int *mar;
+       char *gaps;
+       char *cptr;
+       int i, j, k, len, rep, len0;
+       char **mseq2, **mseq0, **mseq1;
+       char **aseq;
+       int ngroup2, ngroup0, ngroup1;
+       int *list0, *list1, *list2;
+       int posin12, gapshift, newpos;
+
+       mar = calloc( njob, sizeof( int ) );
+       list0 = calloc( njob, sizeof( int ) );
+       list1 = calloc( njob, sizeof( int ) );
+       list2 = calloc( njob, sizeof( int ) );
+
+       for( i=0; i<njob; i++ ) mar[i] = 0;
+       for( i=0; i<njob; i++ ) 
+       {
+               if( alreadyaligned[i]==0 ) mar[i] = 3;
+       }
+       for( i=0; (k=ex1[i])>-1; i++ ) 
+       {
+               mar[k] = 1;
+//             fprintf( stderr, "excluding %d\n", ex1[i] );
+       }
+       for( i=0; (k=ex2[i])>-1; i++ ) 
+       {
+               mar[k] = 2;
+//             fprintf( stderr, "excluding %d\n", ex2[i] );
+       }
+
+       ngroup2 = ngroup1 = ngroup0 = 0;
+       for( i=0; i<njob; i++ )
+       {
+               if( mar[i] == 2 ) 
+               {
+                       list2[ngroup2] = i;
+                       ngroup2++;
+               }
+               if( mar[i] == 1 ) 
+               {
+                       list1[ngroup1] = i;
+                       ngroup1++;
+               }
+               if( mar[i] == 0 ) 
+               {
+                       list0[ngroup0] = i;
+                       ngroup0++;
+               }
+       }
+       list0[ngroup0] = list1[ngroup1] = list2[ngroup2] = -1;
+       if( ngroup0 == 0 )
+       {
+               fprintf( stderr, "Nothing to do\n" );
+               free( mar );
+               free( list0 );
+               free( list1 );
+               free( list2 );
+               return;
+       }
+
+       for( i=0; i<njob; i++ ) if( mar[i] == 0 ) break;
+       rep = i;
+       len = strlen( seq[rep] );
+       len0 = len+1;
+
+//
+//     if( i == njob )
+//     {
+////           fprintf( stderr, "Nothing to do\n" );
+//             free( mar );
+//             return;
+//     }
+
+       mseq2 = AllocateCharMtx( ngroup2, alloclen );
+       mseq1 = AllocateCharMtx( ngroup1, alloclen );
+       mseq0 = AllocateCharMtx( ngroup0, alloclen );
+       aseq = AllocateCharMtx( njob, alloclen );
+       gaps = calloc( alloclen, sizeof( char ) );
+
+       for( i=0; i<njob; i++ ) aseq[i][0] = 0;
+       posin12 = 0;
+       for( j=0; j<len0; j++ )
+       {
+               if( gaplen[j] )
+               {
+                       for( i=0; i<ngroup0; i++ ) mseq0[i][0] = 0;
+                       for( i=0; i<ngroup1; i++ ) mseq1[i][0] = 0;
+                       for( i=0; i<ngroup2; i++ ) mseq2[i][0] = 0;
+
+                       gapshift = gaplen[j];
+                       cptr = gaps;
+                       while( gapshift-- ) *cptr++ = '-';
+                       *cptr = 0;
+                       gapshift = gaplen[j];
+
+                       for( i=0; i<ngroup0; i++ ) strncat( mseq0[i], gaps, gapshift );
+                       for( i=0; i<ngroup1; i++ ) strncat( mseq1[i], seq[list1[i]]+posin12, gapshift );
+                       for( i=0; i<ngroup2; i++ ) strncat( mseq2[i], seq[list2[i]]+posin12, gapshift );
+                       posin12 += gapshift;
+
+                       gapshift = gapmap[posin12];
+//                     fprintf( stderr, "gapmap[%d] kouho = %d\n", posin12, gapmap[posin12] );
+
+
+                       for( i=0; i<ngroup0; i++ ) strncat( mseq0[i], seq[list0[i]]+j, gapshift );
+                       for( i=0; i<ngroup1; i++ ) strncat( mseq1[i], seq[list1[i]]+posin12, gapshift );
+                       for( i=0; i<ngroup2; i++ ) strncat( mseq2[i], seq[list2[i]]+posin12, gapshift );
+#if 0
+                       for( i=0; i<ngroup0; i++ ) fprintf( stderr, "### mseq0[%d] = %s\n", i, mseq0[i] );
+                       for( i=0; i<ngroup1; i++ ) fprintf( stderr, "### mseq1[%d] = %s\n", i, mseq1[i] );
+                       for( i=0; i<ngroup2; i++ ) fprintf( stderr, "### mseq2[%d] = %s\n", i, mseq2[i] );
+#endif
+
+                       if( gapshift ) profilealignment( ngroup0, ngroup1, ngroup2, mseq0, mseq1, mseq2, alloclen, alg );
+
+                       j += gapshift;
+                       posin12 += gapshift;
+
+                       for( i=0; i<ngroup0; i++ ) strcat( aseq[list0[i]], mseq0[i] );
+                       for( i=0; i<ngroup1; i++ ) strcat( aseq[list1[i]], mseq1[i] );
+                       for( i=0; i<ngroup2; i++ ) strcat( aseq[list2[i]], mseq2[i] );
+               }
+
+               newpos = strlen( aseq[rep] );
+               for( i=0; i<ngroup0; i++ ) aseq[list0[i]][newpos] = seq[list0[i]][j];
+               for( i=0; i<ngroup1; i++ ) aseq[list1[i]][newpos] = seq[list1[i]][posin12];
+               for( i=0; i<ngroup2; i++ ) aseq[list2[i]][newpos] = seq[list2[i]][posin12];
+               for( i=0; i<ngroup0; i++ ) aseq[list0[i]][newpos+1] = 0;
+               for( i=0; i<ngroup1; i++ ) aseq[list1[i]][newpos+1] = 0;
+               for( i=0; i<ngroup2; i++ ) aseq[list2[i]][newpos+1] = 0;
+
+               posin12++;
+       }
+
+//     for( i=0; i<njob; i++ ) if( mar[i] != 3 ) strcpy( seq[i], aseq[i] );
+       for( i=0; i<ngroup0; i++ ) strcpy( seq[list0[i]], aseq[list0[i]] );
+       for( i=0; i<ngroup1; i++ ) strcpy( seq[list1[i]], aseq[list1[i]] );
+       for( i=0; i<ngroup2; i++ ) strcpy( seq[list2[i]], aseq[list2[i]] );
+
+       free( mar );
+       free( gaps );
+       free( list0 );
+       free( list1 );
+       free( list2 );
+       FreeCharMtx( mseq2 );
+       FreeCharMtx( mseq0 );
+}
+
+
+void restorecommongaps( int njob, char **seq, int *ex1, int *ex2, int *gaplen, int alloclen )
+{
+       int *mar;
+       char *tmpseq;
+       char *cptr;
+       int *iptr;
+       int *tmpgaplen;
+       int i, j, k, len, rep, len1;
+
+       mar = calloc( njob, sizeof( int ) );
+       tmpseq = calloc( alloclen, sizeof( char ) );
+       tmpgaplen = calloc( alloclen, sizeof( int ) );
+//     tmpseq = calloc( alloclen+2, sizeof( char ) );
+//     tmpgaplen = calloc( alloclen+2, sizeof( int ) );
+
+
+       for( i=0; i<njob; i++ ) mar[i] = 0;
+       for( i=0; (k=ex1[i])>-1; i++ ) 
+       {
+               mar[k] = 1;
+//             fprintf( stderr, "excluding %d\n", ex1[i] );
+       }
+       for( i=0; (k=ex2[i])>-1; i++ ) 
+       {
+               mar[k] = 1;
+//             fprintf( stderr, "excluding %d\n", ex2[i] );
+       }
+
+       for( i=0; i<njob; i++ )
+               if( mar[i] ) break;
+
+       if( i == njob )
+       {
+//             fprintf( stderr, "Nothing to do\n" );
+               free( mar );
+               free( tmpseq );
+               free( tmpgaplen );
+               return;
+       }
+       rep = i;
+       len = strlen( seq[rep] );
+       len1 = len+1;
+
+
+       for( i=0; i<njob; i++ )
+       {
+               if( mar[i] == 0 ) continue;
+               cptr = tmpseq;
+               for( j=0; j<len1; j++ )
+               {
+                       for( k=0; k<gaplen[j]; k++ )
+                               *(cptr++) = '-';
+                       *(cptr++) = seq[i][j];
+               }
+               *cptr = 0;
+               strcpy( seq[i], tmpseq );
+       }
+
+       iptr = tmpgaplen;
+       for( j=0; j<len1; j++ )
+       {
+               *(iptr++) = gaplen[j];
+               for( k=0; k<gaplen[j]; k++ )
+                       *(iptr++) = 0;
+       }
+       *iptr = -1;
+
+       iptr = tmpgaplen;
+       while( *iptr != -1 ) *gaplen++ = *iptr++;
+
+       free( mar );
+       free( tmpseq );
+       free( tmpgaplen );
+}
+
+#if 0
+int samemember( int *mem, int *cand )
+{
+       int i, j;
+
+#if 0
+       fprintf( stderr, "mem = " );
+       for( i=0; mem[i]>-1; i++ )      fprintf( stderr, "%d ", mem[i] );
+       fprintf( stderr, "\n" );
+
+       fprintf( stderr, "cand = " );
+       for( i=0; cand[i]>-1; i++ )     fprintf( stderr, "%d ", cand[i] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=0, j=0; mem[i]>-1; )     
+       {
+               if( mem[i++] != cand[j++] ) return( 0 );
+       }
+
+       if( cand[j] == -1 )
+       {
+               return( 1 );
+       }
+       else
+       {
+               return( 0 );
+       }
+}
+#else
+int samemember( int *mem, int *cand )
+{
+       int i, j;
+       int nm, nc;
+#if 0
+       fprintf( stderr, "mem = " );
+       for( i=0; mem[i]>-1; i++ )      fprintf( stderr, "%d ", mem[i] );
+       fprintf( stderr, "\n" );
+
+       fprintf( stderr, "cand = " );
+       for( i=0; cand[i]>-1; i++ )     fprintf( stderr, "%d ", cand[i] );
+       fprintf( stderr, "\n" );
+#endif
+
+       nm = 0; for( i=0; mem[i]>-1; i++ ) nm++;
+       nc = 0; for( i=0; cand[i]>-1; i++ ) nc++;
+
+       if( nm != nc ) return( 0 );
+
+       for( i=0; mem[i]>-1; i++ )      
+       {
+               for( j=0; cand[j]>-1; j++ )
+                       if( mem[i] == cand[j] ) break;
+               if( cand[j] == -1 ) return( 0 );
+       }
+
+       if( mem[i] == -1 )
+       {
+               return( 1 );
+       }
+       else
+       {
+               return( 0 );
+       }
+}
+#endif
+
+
+int includemember( int *mem, int *cand ) // mem in cand 
+{
+       int i, j;
+
+#if 0
+       fprintf( stderr, "mem = " );
+       for( i=0; mem[i]>-1; i++ )      fprintf( stderr, "%d ", mem[i] );
+       fprintf( stderr, "\n" );
+
+       fprintf( stderr, "cand = " );
+       for( i=0; cand[i]>-1; i++ )     fprintf( stderr, "%d ", cand[i] );
+       fprintf( stderr, "\n" );
+#endif
+
+       for( i=0; mem[i]>-1; i++ )
+       {
+               for( j=0; cand[j]>-1; j++ )
+                       if( mem[i] == cand[j] ) break;
+               if( cand[j] == -1 ) return( 0 );
+       }
+//     fprintf( stderr, "INCLUDED! mem[0]=%d\n", mem[0] );
+       return( 1 );
+}
diff --git a/binaries/src/mafft/core/blosum.c b/binaries/src/mafft/core/blosum.c
new file mode 100644 (file)
index 0000000..62652e5
--- /dev/null
@@ -0,0 +1,266 @@
+#define DEFAULTGOP_B -1530
+#define DEFAULTGEP_B   -00 
+#define DEFAULTOFS_B  -123   /* +10 -- -50  teido ka ? */
+
+void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_grp )
+{
+       /*
+       char locaminod[26] = "GASTPLIMVDNEQFYWKRHCXXX.-U";
+       */
+//     char locaminod[] = "ARNDCQEGHILKMFPSTWYVBZX.-U";
+       char locaminod[] = "ARNDCQEGHILKMFPSTWYVBZX.-J";
+       char locgrpd[] = 
+       {
+               0, 3, 2, 2, 5, 2, 2, 0, 3, 1, 1, 3, 1, 4, 0, 0, 0, 4, 4, 1, 2, 2,
+               6, 6, 6, 1,
+       };
+       double freqd[20] = 
+       {
+           0.077,
+           0.051,
+           0.043,
+           0.052,
+           0.020,
+           0.041,
+           0.062,
+           0.074,
+           0.023,
+           0.052,
+           0.091,
+           0.059,
+           0.024,
+           0.040,
+           0.051,
+           0.069,
+           0.059,
+           0.014,
+           0.032,
+           0.066,
+       };
+
+       double tmpmtx30[] = 
+       {
+    4,
+   -1,     8,
+    0,    -2,     8,
+    0,    -1,     1,     9,
+   -3,    -2,    -1,    -3,    17,
+    1,     3,    -1,    -1,    -2,     8,
+    0,    -1,    -1,     1,     1,     2,     6,
+    0,    -2,     0,    -1,    -4,    -2,    -2,     8,
+   -2,    -1,    -1,    -2,    -5,     0,     0,    -3,    14,
+    0,    -3,     0,    -4,    -2,    -2,    -3,    -1,    -2,     6,
+   -1,    -2,    -2,    -1,     0,    -2,    -1,    -2,    -1,     2,     4,
+    0,     1,     0,     0,    -3,     0,     2,    -1,    -2,    -2,    -2,     4,
+    1,     0,     0,    -3,    -2,    -1,    -1,    -2,     2,     1,     2,     2,     6,
+   -2,    -1,    -1,    -5,    -3,    -3,    -4,    -3,    -3,     0,     2,    -1,    -2,    10,
+   -1,    -1,    -3,    -1,    -3,     0,     1,    -1,     1,    -3,    -3,     1,    -4,    -4,    11,
+    1,    -1,     0,     0,    -2,    -1,     0,     0,    -1,    -1,    -2,     0,    -2,    -1,    -1,     4,
+    1,    -3,     1,    -1,    -2,     0,    -2,    -2,    -2,     0,     0,    -1,     0,    -2,     0,     2,     5,
+   -5,     0,    -7,    -4,    -2,    -1,    -1,     1,    -5,    -3,    -2,    -2,    -3,     1,    -3,    -3,    -5,    20,
+   -4,     0,    -4,    -1,    -6,    -1,    -2,    -3,     0,    -1,     3,    -1,    -1,     3,    -2,    -2,    -1,     5,     9,
+    1,    -1,    -2,    -2,    -2,    -3,    -3,    -3,    -3,     4,     1,    -2,     0,     1,    -4,    -1,     1,    -3,     1,     5,
+    0,    -2,     4,     5,    -2,    -1,     0,     0,    -2,    -2,    -1,     0,    -2,    -3,    -2,     0,     0,    -5,    -3,    -2,     5,
+    0,     0,    -1,     0,     0,     4,     5,    -2,     0,    -3,    -1,     1,    -1,    -4,     0,    -1,    -1,    -1,    -2,    -3,     0,     4,
+    0,    -1,     0,    -1,    -2,     0,    -1,    -1,    -1,     0,     0,     0,     0,    -1,    -1,     0,     0,    -2,    -1,     0,    -1,     0,    -1,
+       };
+       
+       double tmpmtx45[] = 
+       {
+      5,
+     -2,      7,
+     -1,      0,      6,
+     -2,     -1,      2,      7,
+     -1,     -3,     -2,     -3,     12,
+     -1,      1,      0,      0,     -3,      6,
+     -1,      0,      0,      2,     -3,      2,      6,
+      0,     -2,      0,     -1,     -3,     -2,     -2,      7,
+     -2,      0,      1,      0,     -3,      1,      0,     -2,     10,
+     -1,     -3,     -2,     -4,     -3,     -2,     -3,     -4,     -3,      5,
+     -1,     -2,     -3,     -3,     -2,     -2,     -2,     -3,     -2,      2,      5,
+     -1,      3,      0,      0,     -3,      1,      1,     -2,     -1,     -3,     -3,      5,
+     -1,     -1,     -2,     -3,     -2,      0,     -2,     -2,      0,      2,      2,     -1,      6,
+     -2,     -2,     -2,     -4,     -2,     -4,     -3,     -3,     -2,      0,      1,     -3,      0,      8,
+     -1,     -2,     -2,     -1,     -4,     -1,      0,     -2,     -2,     -2,     -3,     -1,     -2,     -3,      9,
+      1,     -1,      1,      0,     -1,      0,      0,      0,     -1,     -2,     -3,     -1,     -2,     -2,     -1,      4,
+      0,     -1,      0,     -1,     -1,     -1,     -1,     -2,     -2,     -1,     -1,     -1,     -1,     -1,     -1,      2,      5,
+     -2,     -2,     -4,     -4,     -5,     -2,     -3,     -2,     -3,     -2,     -2,     -2,     -2,      1,     -3,     -4,     -3,     15,
+     -2,     -1,     -2,     -2,     -3,     -1,     -2,     -3,      2,      0,      0,     -1,      0,      3,     -3,     -2,     -1,      3,      8,
+      0,     -2,     -3,     -3,     -1,     -3,     -3,     -3,     -3,      3,      1,     -2,      1,      0,     -3,     -1,      0,     -3,     -1,      5,
+       };
+    double tmpmtx50[] = 
+    {
+       5,
+      -2,      7,
+      -1,     -1,      7,
+      -2,     -2,      2,      8,
+      -1,     -4,     -2,     -4,     13,
+      -1,      1,      0,      0,     -3,      7,
+      -1,      0,      0,      2,     -3,      2,      6,
+       0,     -3,      0,     -1,     -3,     -2,     -3,      8,
+      -2,      0,      1,     -1,     -3,      1,      0,     -2,     10,
+      -1,     -4,     -3,     -4,     -2,     -3,     -4,     -4,     -4,      5,
+      -2,     -3,     -4,     -4,     -2,     -2,     -3,     -4,     -3,      2,      5,
+      -1,      3,      0,     -1,     -3,      2,      1,     -2,      0,     -3,     -3,      6,
+      -1,     -2,     -2,     -4,     -2,      0,     -2,     -3,     -1,      2,      3,     -2,      7,
+      -3,     -3,     -4,     -5,     -2,     -4,     -3,     -4,     -1,      0,      1,     -4,      0,      8,
+      -1,     -3,     -2,     -1,     -4,     -1,     -1,     -2,     -2,     -3,     -4,     -1,     -3,     -4,     10,
+       1,     -1,      1,      0,     -1,      0,     -1,      0,     -1,     -3,     -3,      0,     -2,     -3,     -1,      5,
+       0,     -1,      0,     -1,     -1,     -1,     -1,     -2,     -2,     -1,     -1,     -1,     -1,     -2,     -1,      2,      5,
+      -3,     -3,     -4,     -5,     -5,     -1,     -3,     -3,     -3,     -3,     -2,     -3,     -1,      1,     -4,     -4,     -3,     15,
+      -2,     -1,     -2,     -3,     -3,     -1,     -2,     -3,      2,     -1,     -1,     -2,      0,      4,     -3,     -2,     -2,      2,      8,
+       0,     -3,     -3,     -4,     -1,     -3,     -3,     -4,     -4,      4,      1,     -3,      1,     -1,     -3,     -2,      0,     -3,     -1,      5,
+    };
+       double tmpmtx62[] = 
+       {
+      6,
+     -2,      8,
+     -2,     -1,      8,
+     -3,     -2,      2,      9,
+     -1,     -5,     -4,     -5,     13,
+     -1,      1,      0,      0,     -4,      8,
+     -1,      0,      0,      2,     -5,      3,      7,
+      0,     -3,     -1,     -2,     -4,     -3,     -3,      8,
+     -2,      0,      1,     -2,     -4,      1,      0,     -3,     11,
+     -2,     -4,     -5,     -5,     -2,     -4,     -5,     -6,     -5,      6,
+     -2,     -3,     -5,     -5,     -2,     -3,     -4,     -5,     -4,      2,      6,
+     -1,      3,      0,     -1,     -5,      2,      1,     -2,     -1,     -4,     -4,      7,
+     -1,     -2,     -3,     -5,     -2,     -1,     -3,     -4,     -2,      2,      3,     -2,      8,
+     -3,     -4,     -4,     -5,     -4,     -5,     -5,     -5,     -2,      0,      1,     -5,      0,      9,
+     -1,     -3,     -3,     -2,     -4,     -2,     -2,     -3,     -3,     -4,     -4,     -2,     -4,     -5,     11,
+      2,     -1,      1,      0,     -1,      0,      0,      0,     -1,     -4,     -4,      0,     -2,     -4,     -1,      6,
+      0,     -2,      0,     -2,     -1,     -1,     -1,     -2,     -3,     -1,     -2,     -1,     -1,     -3,     -2,      2,      7,
+     -4,     -4,     -6,     -6,     -3,     -3,     -4,     -4,     -4,     -4,     -2,     -4,     -2,      1,     -5,     -4,     -4,     16,
+     -3,     -3,     -3,     -5,     -4,     -2,     -3,     -5,      3,     -2,     -2,     -3,     -1,      4,     -4,     -3,     -2,      3,     10,
+      0,     -4,     -4,     -5,     -1,     -3,     -4,     -5,     -5,      4,      1,     -3,      1,     -1,     -4,     -2,      0,     -4,     -2,      6,
+       };
+       double tmpmtx80[] = 
+       {
+      7,
+     -3,      9,
+     -3,     -1,      9,
+     -3,     -3,      2,     10,
+     -1,     -6,     -5,     -7,     13,
+     -2,      1,      0,     -1,     -5,      9,
+     -2,     -1,     -1,      2,     -7,      3,      8,
+      0,     -4,     -1,     -3,     -6,     -4,     -4,      9,
+     -3,      0,      1,     -2,     -7,      1,      0,     -4,     12,
+     -3,     -5,     -6,     -7,     -2,     -5,     -6,     -7,     -6,      7,
+     -3,     -4,     -6,     -7,     -3,     -4,     -6,     -7,     -5,      2,      6,
+     -1,      3,      0,     -2,     -6,      2,      1,     -3,     -1,     -5,     -4,      8,
+     -2,     -3,     -4,     -6,     -3,     -1,     -4,     -5,     -4,      2,      3,     -3,      9,
+     -4,     -5,     -6,     -6,     -4,     -5,     -6,     -6,     -2,     -1,      0,     -5,      0,     10,
+     -1,     -3,     -4,     -3,     -6,     -3,     -2,     -5,     -4,     -5,     -5,     -2,     -4,     -6,     12,
+      2,     -2,      1,     -1,     -2,     -1,     -1,     -1,     -2,     -4,     -4,     -1,     -3,     -4,     -2,      7,
+      0,     -2,      0,     -2,     -2,     -1,     -2,     -3,     -3,     -2,     -3,     -1,     -1,     -4,     -3,      2,      8,
+     -5,     -5,     -7,     -8,     -5,     -4,     -6,     -6,     -4,     -5,     -4,     -6,     -3,      0,     -7,     -6,     -5,     16,
+     -4,     -4,     -4,     -6,     -5,     -3,     -5,     -6,      3,     -3,     -2,     -4,     -3,      4,     -6,     -3,     -3,      3,     11,
+     -1,     -4,     -5,     -6,     -2,     -4,     -4,     -6,     -5,      4,      1,     -4,      1,     -2,     -4,     -3,      0,     -5,     -3,      7,
+       };
+       double tmpmtx0[] = 
+       {
+     2.4,
+    -0.6,    4.7,
+    -0.3,    0.3,    3.8,
+    -0.3,   -0.3,    2.2,    4.7,
+     0.5,   -2.2,   -1.8,   -3.2,   11.5,
+    -0.2,    1.5,    0.7,    0.9,   -2.4,    2.7,
+     0.0,    0.4,    0.9,    2.7,   -3.0,    1.7,    3.6,
+     0.5,   -1.0,    0.4,    0.1,   -2.0,   -1.0,   -0.8,    6.6,
+    -0.8,    0.6,    1.2,    0.4,   -1.3,    1.2,    0.4,   -1.4,    6.0,
+    -0.8,   -2.4,   -2.8,   -3.8,   -1.1,   -1.9,   -2.7,   -4.5,   -2.2,    4.0,
+    -1.2,   -2.2,   -3.0,   -4.0,   -1.5,   -1.6,   -2.8,   -4.4,   -1.9,    2.8,    4.0,
+    -0.4,    2.7,    0.8,    0.5,   -2.8,    1.5,    1.2,   -1.1,    0.6,   -2.1,   -2.1,    3.2,
+    -0.7,   -1.7,   -2.2,   -3.0,   -0.9,   -1.0,   -2.0,   -3.5,   -1.3,    2.5,    2.8,   -1.4,    4.3,
+    -2.3,   -3.2,   -3.1,   -4.5,   -0.8,   -2.6,   -3.9,   -5.2,   -0.1,    1.0,    2.0,   -3.3,    1.6,    7.0,
+     0.3,   -0.9,   -0.9,   -0.7,   -3.1,   -0.2,   -0.5,   -1.6,   -1.1,   -2.6,   -2.3,   -0.6,   -2.4,   -3.8,    7.6,
+     1.1,   -0.2,    0.9,    0.5,    0.1,    0.2,    0.2,    0.4,   -0.2,   -1.8,   -2.1,    0.1,   -1.4,   -2.8,    0.4,    2.2,
+     0.6,   -0.2,    0.5,    0.0,   -0.5,    0.0,   -0.1,   -1.1,   -0.3,   -0.6,   -1.3,    0.1,   -0.6,   -2.2,    0.1,    1.5,    2.5,
+    -3.6,   -1.6,   -3.6,   -5.2,   -1.0,   -2.7,   -4.3,   -4.0,   -0.8,   -1.8,   -0.7,   -3.5,   -1.0,    3.6,   -5.0,   -3.3,   -3.5,   14.2,
+    -2.2,   -1.8,   -1.4,   -2.8,   -0.5,   -1.7,   -2.7,   -4.0,    2.2,   -0.7,    0.0,   -2.1,   -0.2,    5.1,   -3.1,   -1.9,   -1.9,    4.1,    7.8,
+     0.1,   -2.0,   -2.2,   -2.9,    0.0,   -1.5,   -1.9,   -3.3,   -2.0,    3.1,    1.8,   -1.7,    1.6,    0.1,   -1.8,   -1.0,    0.0,   -2.6,   -1.1,    3.4,
+       };
+
+       int i, j, count;
+       double av;
+       double *tmpmtx;
+
+       if( n == 30 ) tmpmtx = tmpmtx30;
+       else if( n == 45 ) tmpmtx = tmpmtx45;
+       else if( n == 50 ) tmpmtx = tmpmtx50;
+       else if( n == 62 ) tmpmtx = tmpmtx62;
+       else if( n == 80 ) tmpmtx = tmpmtx80;
+       else if( n == 0 ) tmpmtx = tmpmtx0;
+       else if( n == -1 ) tmpmtx = loadaamtx();
+       else
+       {
+               fprintf( stderr, "blosum %d ?\n", n );
+               exit( 1 );
+       }
+
+       count = 0;
+       for( i=0; i<20; i++ )
+       {
+               for( j=0; j<=i; j++ )
+               {
+                       matrix[i][j] = matrix[j][i] = (double)tmpmtx[count++];
+               }
+       }
+       if( n == -1 && tmpmtx[400] != -1.0 ) 
+       {
+               for( i=0; i<20; i++ ) freq[i] = tmpmtx[400+i];
+               av = 0.0;
+               for( i=0; i<20; i++ ) av += freq[i];
+               for( i=0; i<20; i++ ) freq[i] /= av;
+       }
+       else
+               for( i=0; i<20; i++ ) freq[i] = freqd[i];
+
+#if 0
+       av = 0.0;
+       for( i=0; i<20; i++ )
+               av += matrix[i][i];
+       av /= 20;
+       fprintf( stdout, "av = %f\n", av );
+
+       for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+               matrix[i][j] /= av;
+
+       av = wav = 0;
+       count = 0;
+       wcount = 0.0;
+       tmptmp = 0.0;
+       for( i=0; i<20; i++ )
+       {
+               fprintf( stdout, "freq[%d] = %f\n", i, freq[i] );
+               tmptmp += freq[i];
+               for( j=0; j<20; j++ )
+               {
+                       av += matrix[i][j];
+                       wav += freq[i] * freq[j] * matrix[i][j];
+                       count++;
+                       wcount += freq[i] * freq[j];
+               }
+       }
+
+       av /= count;
+       wav /= wcount;
+       fprintf( stdout, "av = %f\n", av );
+       fprintf( stdout, "wav = %f\n", wav );
+       fprintf( stdout, "wcount = %f\n", wcount );
+       fprintf( stdout, "tmptmp = %f\n", tmptmp );
+
+       for( i=0; i<20; i++ )
+       {
+               for( j=0; j<=i; j++ )
+               {
+                       fprintf( stderr, "## %d-%d, %f\n", i, j, matrix[i][j] );
+               }
+       }
+
+       exit( 1 );
+#endif
+
+    for( i=0; i<26; i++ ) amino[i] = locaminod[i];
+    for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i];
+}
diff --git a/binaries/src/mafft/core/blosum.h b/binaries/src/mafft/core/blosum.h
new file mode 100644 (file)
index 0000000..9b7c068
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+int locpenaltyd = -2400;
+int locoffsetd = -60;
+char locaminod[26] = "GASTPLIMVDNEQFYWKRHCXXX.-U";
+char locaminod[] = "ARNDCQEGHILKMFPSTWYVBZX.-U";
+char locgrpd[] = 
+{
+       0, 3, 2, 2, 5, 2, 2, 0, 3, 1, 1, 3, 1, 4, 0, 0, 0, 4, 4, 1, 2, 2,
+       6, 6, 6, 6,
+};
+*/
diff --git a/binaries/src/mafft/core/constants.c b/binaries/src/mafft/core/constants.c
new file mode 100644 (file)
index 0000000..efc06dc
--- /dev/null
@@ -0,0 +1,1037 @@
+#include "mltaln.h"
+#include "miyata.h"
+#include "miyata5.h"
+#include "DNA.h"
+
+#include "JTT.c"
+#include "blosum.c"
+
+#define DEBUG 0
+#define TEST 0
+
+#define NORMALIZE1 1
+
+static int shishagonyuu( double in )
+{
+       int out;
+       if     ( in >  0.0 ) out = ( (int)( in + 0.5 ) );
+       else if( in == 0.0 ) out = ( 0 );
+       else if( in <  0.0 ) out = ( (int)( in - 0.5 ) );
+       else                 out = 0;
+       return( out );
+}
+
+static void calcfreq_nuc( int nseq, char **seq, double *datafreq )
+{
+       int i, j, l;
+       int aan;
+       double total;
+       for( i=0; i<4; i++ )
+               datafreq[i] = 0.0;
+       total = 0.0;
+       for( i=0; i<nseq; i++ )
+       {
+               l = strlen( seq[i] );
+               for( j=0; j<l; j++ )
+               {
+                       aan = amino_n[(int)seq[i][j]];
+                       if( aan == 4 ) aan = 3;
+                       if( aan >= 0 && aan < 4 )
+                       {
+                               datafreq[aan] += 1.0;
+                               total += 1.0;
+                       }
+               }
+       }
+       for( i=0; i<4; i++ )
+               if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001;
+
+
+       total = 0.0; for( i=0; i<4; i++ ) total += datafreq[i];
+//     fprintf( stderr, "total = %f\n", total );
+       for( i=0; i<4; i++ ) datafreq[i] /= (double)total;
+
+#if 0
+       fprintf( stderr, "\ndatafreq = " );
+       for( i=0; i<4; i++ )
+               fprintf( stderr, "%10.5f ", datafreq[i] );
+       fprintf( stderr, "\n" );
+       exit( 1 );
+#endif
+}
+
+static void calcfreq( int nseq, char **seq, double *datafreq )
+{
+       int i, j, l;
+       int aan;
+       double total;
+       for( i=0; i<20; i++ )
+               datafreq[i] = 0.0;
+       total = 0.0;
+       for( i=0; i<nseq; i++ )
+       {
+               l = strlen( seq[i] );
+               for( j=0; j<l; j++ )
+               {
+                       aan = amino_n[(int)seq[i][j]];
+                       if( aan >= 0 && aan < 20 )
+                       {
+                               datafreq[aan] += 1.0;
+                               total += 1.0;
+                       }
+               }
+       }
+       for( i=0; i<20; i++ )
+               if( datafreq[i] < 0.0001 ) datafreq[i] = 0.0001;
+
+       fprintf( stderr, "datafreq = \n" );
+       for( i=0; i<20; i++ )
+               fprintf( stderr, "%f\n", datafreq[i] );
+
+       total = 0.0; for( i=0; i<20; i++ ) total += datafreq[i];
+       fprintf( stderr, "total = %f\n", total );
+       for( i=0; i<20; i++ ) datafreq[i] /= (double)total;
+}
+
+void constants( int nseq, char **seq )
+{
+       int i, j, x;
+//     double tmp;
+
+       if( dorp == 'd' )  /* DNA */
+       {
+               int k, m;
+               double average;
+               double **pamx = AllocateDoubleMtx( 11,11 );
+               double **pam1 = AllocateDoubleMtx( 4, 4 );
+               double *freq = AllocateDoubleVec( 4 );
+
+
+               scoremtx = -1;
+               if( RNAppenalty == NOTSPECIFIED ) RNAppenalty = DEFAULTRNAGOP_N;
+               if( RNAppenalty_ex == NOTSPECIFIED ) RNAppenalty_ex = DEFAULTRNAGEP_N;
+               if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_N;
+               if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_N;
+               if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_N;
+               if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_N;
+               if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_N;
+               if( RNApthr == NOTSPECIFIED ) RNApthr = DEFAULTRNATHR_N;
+               if( pamN == NOTSPECIFIED ) pamN = DEFAULTPAMN;
+               if( kimuraR == NOTSPECIFIED ) kimuraR = 2;
+
+               RNApenalty = (int)( 3 * 600.0 / 1000.0 * RNAppenalty + 0.5 );
+               RNApenalty_ex = (int)( 3 * 600.0 / 1000.0 * RNAppenalty_ex + 0.5 );
+//             fprintf( stderr, "DEFAULTRNAGOP_N = %d\n", DEFAULTRNAGOP_N );
+//             fprintf( stderr, "RNAppenalty = %d\n", RNAppenalty );
+//             fprintf( stderr, "RNApenalty = %d\n", RNApenalty );
+
+
+               RNAthr = (int)( 3 * 600.0 / 1000.0 * RNApthr + 0.5 );
+               penalty = (int)( 3 * 600.0 / 1000.0 * ppenalty + 0.5);
+               penalty_OP = (int)( 3 * 600.0 / 1000.0 * ppenalty_OP + 0.5);
+               penalty_ex = (int)( 3 * 600.0 / 1000.0 * ppenalty_ex + 0.5);
+               penalty_EX = (int)( 3 * 600.0 / 1000.0 * ppenalty_EX + 0.5);
+               offset = (int)( 3 * 600.0 / 1000.0 * poffset + 0.5);
+               offsetFFT = (int)( 3 * 600.0 / 1000.0 * (-0) + 0.5);
+               offsetLN = (int)( 3 * 600.0 / 1000.0 * 100 + 0.5);
+               penaltyLN = (int)( 3 * 600.0 / 1000.0 * -2000 + 0.5);
+               penalty_exLN = (int)( 3 * 600.0 / 1000.0 * -100 + 0.5);
+               sprintf( modelname, "%s%d (%d), %6.3f (%6.3f), %6.3f (%6.3f)", rnakozo?"RNA":"DNA", pamN, kimuraR,
+        -(double)ppenalty*0.001, -(double)ppenalty*0.003, -(double)poffset*0.001, -(double)poffset*0.003 );
+
+               if( kimuraR == 9999 ) 
+               {
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) 
+                               pamx[i][j] = (double)locn_disn[i][j];
+#if NORMALIZE1
+                       average = 0.0;
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) 
+                               average += pamx[i][j];
+                       average /= 16.0;
+       
+            if( disp )
+                               fprintf( stderr, "average = %f\n", average );
+       
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) 
+                               pamx[i][j] -= average;
+       
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] *= 600.0 / average;
+                       
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] -= offset; 
+#endif
+               }
+               else
+               {
+                               double f = 0.99;
+                               double s = (double)kimuraR / ( 2 + kimuraR ) * 0.01;
+                               double v = (double)1       / ( 2 + kimuraR ) * 0.01;
+                               pam1[0][0] = f; pam1[0][1] = s; pam1[0][2] = v; pam1[0][3] = v;
+                               pam1[1][0] = s; pam1[1][1] = f; pam1[1][2] = v; pam1[1][3] = v;
+                               pam1[2][0] = v; pam1[2][1] = v; pam1[2][2] = f; pam1[2][3] = s;
+                               pam1[3][0] = v; pam1[3][1] = v; pam1[3][2] = s; pam1[3][3] = f;
+       
+                               fprintf( stderr, "generating %dPAM scoring matrix for nucleotides ... ", pamN );
+       
+                       if( disp )
+                       {
+                               fprintf( stderr, " TPM \n" );
+                               for( i=0; i<4; i++ )
+                               {
+                               for( j=0; j<4; j++ )
+                                       fprintf( stderr, "%+#6.10f", pam1[i][j] );
+                               fprintf( stderr, "\n" );
+                               }
+                               fprintf( stderr, "\n" );
+                       }
+       
+       
+                               MtxuntDouble( pamx, 4 );
+                               for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 4 );
+                               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                                       pamx[i][j] /= 1.0 / 4.0;
+       
+                               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               {
+                                       if( pamx[i][j] == 0.0 ) 
+                                       {
+                                               fprintf( stderr, "WARNING: pamx[i][j] = 0.0 ?\n" );
+                                               pamx[i][j] = 0.00001; /* by J. Thompson */
+                                       }
+                                       pamx[i][j] = log10( pamx[i][j] ) * 1000.0;
+                               }
+       
+                       if( disp )
+                       {
+                               fprintf( stderr, " after log\n" );
+                               for( i=0; i<4; i++ )
+                               {
+                               for( j=0; j<4; j++ )
+                                       fprintf( stderr, "%+#6.10f", pamx[i][j] );
+                               fprintf( stderr, "\n" );
+                               }
+                               fprintf( stderr, "\n" );
+                       }
+
+
+// ?????
+                       for( i=0; i<26; i++ ) amino[i] = locaminon[i];
+                       for( i=0; i<0x80; i++ ) amino_n[i] = -1;
+                       for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i;
+                       if( fmodel == 1 )
+                               calcfreq_nuc( nseq, seq, freq );
+                       else
+                       {
+                               freq[0] = 0.25;
+                               freq[1] = 0.25;
+                               freq[2] = 0.25;
+                               freq[3] = 0.25;
+                       }
+//                     fprintf( stderr, "a, freq[0] = %f\n", freq[0] );
+//                     fprintf( stderr, "g, freq[1] = %f\n", freq[1] );
+//                     fprintf( stderr, "c, freq[2] = %f\n", freq[2] );
+//                     fprintf( stderr, "t, freq[3] = %f\n", freq[3] );
+
+                       
+                       average = 0.0;
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               average += pamx[i][j] * freq[i] * freq[j];
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] -= average;
+
+                       average = 0.0;
+                       for( i=0; i<4; i++ )
+                               average += pamx[i][i] * 1.0 / 4.0;
+
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] *= 600.0 / average;
+
+
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] -= offset;        /* extending gap cost */
+
+                       for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                               pamx[i][j] = shishagonyuu( pamx[i][j] );
+
+                       if( disp )
+                       {
+                       fprintf( stderr, " after shishagonyuu\n" );
+                       for( i=0; i<4; i++ )
+                       {
+                       for( j=0; j<4; j++ )
+                               fprintf( stderr, "%+#6.10f", pamx[i][j] );
+                       fprintf( stderr, "\n" );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+                       fprintf( stderr, "done\n" );
+               }
+       
+               for( i=0; i<5; i++ ) 
+               {
+                       pamx[4][i] = pamx[3][i];
+                       pamx[i][4] = pamx[i][3];
+               }       
+
+               for( i=5; i<10; i++ ) for( j=5; j<10; j++ )
+               {
+                       pamx[i][j] = pamx[i-5][j-5];
+               }
+       
+               if( disp )
+               {
+                       fprintf( stderr, " before dis\n" );
+               for( i=0; i<4; i++ )
+               {
+                       for( j=0; j<4; j++ )
+                       fprintf( stderr, "%+#6.10f", pamx[i][j] );
+                       fprintf( stderr, "\n" );
+               }
+               fprintf( stderr, "\n" );
+        }
+
+               if( disp )
+               {
+               fprintf( stderr, " score matrix  \n" );
+               for( i=0; i<4; i++ )
+               {
+                       for( j=0; j<4; j++ )
+                       fprintf( stderr, "%+#6.10f", pamx[i][j] );
+                       fprintf( stderr, "\n" );
+               }
+               fprintf( stderr, "\n" );
+        }
+
+               for( i=0; i<26; i++ ) amino[i] = locaminon[i];
+               for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpn[i];
+               for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0;
+               for( i=0; i<10; i++ ) for( j=0; j<10; j++ ) n_dis[i][j] = shishagonyuu( pamx[i][j] );
+        if( disp )
+        {
+            fprintf( stderr, " score matrix  \n" );
+            for( i=0; i<26; i++ )
+            {
+                for( j=0; j<26; j++ )
+                    fprintf( stderr, "%+6d", n_dis[i][j] );
+                fprintf( stderr, "\n" );
+            }
+            fprintf( stderr, "\n" );
+        }
+
+// RIBOSUM
+#if 1
+               average = 0.0;
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                       average += ribosum4[i][j] * freq[i] * freq[j];
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                       ribosum4[i][j] -= average;
+
+               average = 0.0;
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ ) for( k=0; k<4; k++ ) for( m=0; m<4; m++ )
+               {
+//                     if( i%4==0&&j%4==3 || i%4==3&&j%4==0 || i%4==1&&j%4==2 || i%4==2&&j%4==1 || i%4==1&&j%4==3 || i%4==3&&j%4==1 )
+//                     if( k%4==0&&m%4==3 || k%4==3&&m%4==0 || k%4==1&&m%4==2 || k%4==2&&m%4==1 || k%4==1&&m%4==3 || k%4==3&&m%4==1 )
+                               average += ribosum16[i*4+j][k*4+m] * freq[i] * freq[j] * freq[k] * freq[m];
+               }
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ )
+                       ribosum16[i][j] -= average;
+
+               average = 0.0;
+               for( i=0; i<4; i++ )
+                       average += ribosum4[i][i] * freq[i];
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                       ribosum4[i][j] *= 600.0 / average;
+
+               average = 0.0;
+               average += ribosum16[0*4+3][0*4+3] * freq[0] * freq[3]; // AU
+               average += ribosum16[3*4+0][3*4+0] * freq[3] * freq[0]; // UA
+               average += ribosum16[1*4+2][1*4+2] * freq[1] * freq[2]; // CG
+               average += ribosum16[2*4+1][2*4+1] * freq[2] * freq[1]; // GC
+               average += ribosum16[1*4+3][1*4+3] * freq[1] * freq[3]; // GU
+               average += ribosum16[3*4+1][3*4+1] * freq[3] * freq[1]; // UG
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ )
+                       ribosum16[i][j] *= 600.0 / average;
+
+
+#if 1
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                       ribosum4[i][j] -= offset;        /* extending gap cost ?????*/
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ )
+                       ribosum16[i][j] -= offset;        /* extending gap cost ?????*/
+#endif
+
+               for( i=0; i<4; i++ ) for( j=0; j<4; j++ )
+                       ribosum4[i][j] = shishagonyuu( ribosum4[i][j] );
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ )
+                       ribosum16[i][j] = shishagonyuu( ribosum16[i][j] );
+
+               if( disp )
+               {
+               fprintf( stderr, "ribosum after shishagonyuu\n" );
+                       for( i=0; i<4; i++ )
+                       {
+                       for( j=0; j<4; j++ )
+                               fprintf( stderr, "%+#6.10f", ribosum4[i][j] );
+                       fprintf( stderr, "\n" );
+                       }
+                       fprintf( stderr, "\n" );
+               fprintf( stderr, "ribosum16 after shishagonyuu\n" );
+                       for( i=0; i<16; i++ )
+                       {
+                       for( j=0; j<16; j++ )
+                               fprintf( stderr, "%+#7.0f", ribosum16[i][j] );
+                       fprintf( stderr, "\n" );
+                       }
+                       fprintf( stderr, "\n" );
+       }
+               fprintf( stderr, "done\n" );
+
+#if 1
+               for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru
+               for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop
+                       for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = ribosum4[i][j]; // loop-loop
+//                     for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop
+
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+4][j+4] = ribosum16[i][j]; // stem5-stem5
+               for( i=0; i<16; i++ ) for( j=0; j<16; j++ ) ribosumdis[i+20][j+20] = ribosum16[i][j]; // stem5-stem5
+#else // do not use ribosum
+               for( i=0; i<37; i++ ) for( j=0; j<37; j++ ) ribosumdis[i][j] = 0.0; //iru
+               for( m=0; m<9; m++ ) for( i=0; i<4; i++ ) // loop
+                       for( k=0; k<9; k++ ) for( j=0; j<4; j++ ) ribosumdis[m*4+i][k*4+j] = n_dis[i][j]; // loop-loop
+#endif
+
+               if( disp )
+               {
+               fprintf( stderr, "ribosumdis\n" );
+                       for( i=0; i<37; i++ )
+                       {
+                       for( j=0; j<37; j++ )
+                               fprintf( stderr, "%+5d", ribosumdis[i][j] );
+                       fprintf( stderr, "\n" );
+                       }
+                       fprintf( stderr, "\n" );
+       }
+               fprintf( stderr, "done\n" );
+#endif
+
+               FreeDoubleMtx( pam1 );
+               FreeDoubleMtx( pamx );
+               free( freq );
+
+       }
+       else if( dorp == 'p' && scoremtx == 1 )  /* Blosum */
+       {
+               double *freq;
+               double *freq1;
+               double *datafreq;
+               double average;
+//             double tmp;
+               double **n_distmp;
+
+               n_distmp = AllocateDoubleMtx( 20, 20 );
+               datafreq = AllocateDoubleVec( 20 );
+               freq = AllocateDoubleVec( 20 );
+
+               if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_B;
+               if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_B;
+               if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_B;
+               if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_B;
+               if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_B;
+               if( pamN == NOTSPECIFIED ) pamN = 0;
+               if( kimuraR == NOTSPECIFIED ) kimuraR = 1;
+               penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 );
+               penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 );
+               penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 );
+               penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 );
+               offset = (int)( 600.0 / 1000.0 * poffset + 0.5 );
+               offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5);
+               offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5);
+               penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5);
+               penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5);
+
+               BLOSUMmtx( nblosum, n_distmp, freq, amino, amino_grp );
+               if( nblosum == -1 )
+                       sprintf( modelname, "User-defined, %6.3f, %+6.3f, %+6.3f", -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 );
+               else
+                       sprintf( modelname, "BLOSUM%d, %6.3f, %+6.3f, %+6.3f", nblosum, -(double)ppenalty/1000, -(double)poffset/1000, -(double)ppenalty_ex/1000 );
+#if 0
+               for( i=0; i<26; i++ ) amino[i] = locaminod[i];
+               for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpd[i];
+               for( i=0; i<0x80; i++ ) amino_n[i] = 0;
+               for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i;
+#endif
+               for( i=0; i<0x80; i++ )amino_n[i] = -1;
+               for( i=0; i<26; i++) amino_n[(int)amino[i]] = i;
+               if( fmodel == 1 )
+               {
+                       calcfreq( nseq, seq, datafreq );
+                       freq1 = datafreq;
+               }
+               else
+                       freq1 = freq;
+#if TEST
+               fprintf( stderr, "raw scoreing matrix : \n" );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stdout, "%6.2f", n_distmp[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+               if( fmodel == -1 )
+                       average = 0.0;
+               else
+               {
+                       for( i=0; i<20; i++ )
+#if TEST 
+                               fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] );
+#endif
+                       average = 0.0;
+                       for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+                               average += n_distmp[i][j] * freq1[i] * freq1[j];
+               }
+#if TEST
+               fprintf( stdout, "####### average2  = %f\n", average );
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       n_distmp[i][j] -= average;
+#if TEST
+               fprintf( stdout, "average2 = %f\n", average );
+               fprintf( stdout, "after average substruction : \n" );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stdout, "%6.2f", n_distmp[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+               
+               average = 0.0;
+               for( i=0; i<20; i++ ) 
+                       average += n_distmp[i][i] * freq1[i];
+#if TEST
+               fprintf( stdout, "####### average1  = %f\n", average );
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       n_distmp[i][j] *= 600.0 / average;
+#if TEST
+        fprintf( stdout, "after average division : \n" );
+        for( i=0; i<20; i++ )
+        {
+            for( j=0; j<=i; j++ )
+            {
+                fprintf( stdout, "%7.1f", n_distmp[i][j] );
+            }
+            fprintf( stdout, "\n" );
+        }
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       n_distmp[i][j] -= offset;  
+#if TEST
+               fprintf( stdout, "after offset substruction (offset = %d): \n", offset );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<=i; j++ ) 
+                       {
+                               fprintf( stdout, "%7.1f", n_distmp[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+#if 0
+/* Ãí°Õ ¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª */
+                       penalty -= offset;
+#endif
+
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       n_distmp[i][j] = shishagonyuu( n_distmp[i][j] );
+
+        if( disp )
+        {
+            fprintf( stdout, " scoring matrix  \n" );
+            for( i=0; i<20; i++ )
+            {
+                               fprintf( stdout, "%c    ", amino[i] );
+                for( j=0; j<20; j++ )
+                    fprintf( stdout, "%5.0f", n_distmp[i][j] );
+                fprintf( stdout, "\n" );
+            }
+                       fprintf( stdout, "     " );
+            for( i=0; i<20; i++ )
+                               fprintf( stdout, "    %c", amino[i] );
+
+                       average = 0.0;
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+                               average += n_distmp[i][j] * freq1[i] * freq1[j];
+                       fprintf( stdout, "average = %f\n", average );
+
+                       average = 0.0;
+               for( i=0; i<20; i++ )
+                               average += n_distmp[i][i] * freq1[i];
+                       fprintf( stdout, "itch average = %f\n", average );
+                       fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset );
+
+                       
+                       exit( 1 );
+        }
+
+               for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0;
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)n_distmp[i][j];
+
+               FreeDoubleMtx( n_distmp );
+               FreeDoubleVec( datafreq );
+               FreeDoubleVec( freq );
+
+               fprintf( stderr, "done.\n" );
+
+       }
+       else if( dorp == 'p' && scoremtx == 2 ) /* Miyata-Yasunaga */
+       {
+               fprintf( stderr, "Not supported\n" );
+               exit( 1 );
+               for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = locn_dism[i][j];
+               for( i=0; i<26; i++ ) if( i != 24 ) n_dis[i][24] = n_dis[24][i] = exgpm;
+               n_dis[24][24] = 0;
+               if( ppenalty == NOTSPECIFIED ) ppenalty = locpenaltym;
+               if( poffset == NOTSPECIFIED ) poffset = -20;
+               if( pamN == NOTSPECIFIED ) pamN = 0;
+               if( kimuraR == NOTSPECIFIED ) kimuraR = 1;
+
+               penalty = ppenalty;
+               offset = poffset;
+
+               sprintf( modelname, "Miyata-Yasunaga, %6.3f, %6.3f", -(double)ppenalty/1000, -(double)poffset/1000 );
+               for( i=0; i<26; i++ ) amino[i] = locaminom[i];
+               for( i=0; i<26; i++ ) amino_grp[(int)amino[i]] = locgrpm[i];
+#if DEBUG
+               fprintf( stdout, "scoreing matrix : \n" );
+               for( i=0; i<26; i++ )
+               {
+                       for( j=0; j<26; j++ ) 
+                       {
+                               fprintf( stdout, "%#5d", n_dis[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+       }
+       else         /* JTT */
+       {
+               double **rsr;
+               double **pam1;
+               double **pamx;
+               double *freq;
+               double *freq1;
+               double *mutab;
+               double *datafreq;
+               double average;
+               double tmp;
+               double delta;
+
+               rsr = AllocateDoubleMtx( 20, 20 );
+               pam1 = AllocateDoubleMtx( 20, 20 );
+               pamx = AllocateDoubleMtx( 20, 20 );
+               freq = AllocateDoubleVec( 20 );
+               mutab = AllocateDoubleVec( 20 );
+               datafreq = AllocateDoubleVec( 20 );
+
+               if( ppenalty == NOTSPECIFIED ) ppenalty = DEFAULTGOP_J;
+               if( ppenalty_OP == NOTSPECIFIED ) ppenalty_OP = DEFAULTGOP_J;
+               if( ppenalty_ex == NOTSPECIFIED ) ppenalty_ex = DEFAULTGEP_J;
+               if( ppenalty_EX == NOTSPECIFIED ) ppenalty_EX = DEFAULTGEP_J;
+               if( poffset == NOTSPECIFIED ) poffset = DEFAULTOFS_J;
+               if( pamN == NOTSPECIFIED )    pamN    = DEFAULTPAMN;
+               if( kimuraR == NOTSPECIFIED ) kimuraR = 1;
+
+               penalty = (int)( 600.0 / 1000.0 * ppenalty + 0.5 );
+               penalty_OP = (int)( 600.0 / 1000.0 * ppenalty_OP + 0.5 );
+               penalty_ex = (int)( 600.0 / 1000.0 * ppenalty_ex + 0.5 );
+               penalty_EX = (int)( 600.0 / 1000.0 * ppenalty_EX + 0.5 );
+               offset = (int)( 600.0 / 1000.0 * poffset + 0.5 );
+               offsetFFT = (int)( 600.0 / 1000.0 * (-0) + 0.5 );
+               offsetLN = (int)( 600.0 / 1000.0 * 100 + 0.5);
+               penaltyLN = (int)( 600.0 / 1000.0 * -2000 + 0.5);
+               penalty_exLN = (int)( 600.0 / 1000.0 * -100 + 0.5);
+
+               sprintf( modelname, "%s %dPAM, %6.3f, %6.3f", (TMorJTT==TM)?"Transmembrane":"JTT", pamN, -(double)ppenalty/1000, -(double)poffset/1000 );
+
+               JTTmtx( rsr, freq, amino, amino_grp, (int)(TMorJTT==TM) );
+
+#if TEST
+               fprintf( stdout, "rsr = \n" );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ )
+                       {
+                               fprintf( stdout, "%9.2f ", rsr[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+
+               for( i=0; i<0x80; i++ ) amino_n[i] = -1;
+               for( i=0; i<26; i++ ) amino_n[(int)amino[i]] = i;
+
+               if( fmodel == 1 )
+               {
+                       calcfreq( nseq, seq, datafreq );
+                       freq1 = datafreq;
+               }
+               else
+                       freq1 = freq;
+
+               fprintf( stderr, "generating %dPAM %s scoring matrix for amino acids ... ", pamN, (TMorJTT==TM)?"Transmembrane":"JTT" );
+
+               tmp = 0.0;
+               for( i=0; i<20; i++ )
+               {
+                       mutab[i] = 0.0;
+                       for( j=0; j<20; j++ )
+                               mutab[i] += rsr[i][j] * freq[j];
+                       tmp += mutab[i] * freq[i];
+               }
+#if TEST
+               fprintf( stdout, "mutability = \n" );
+               for( i=0; i<20; i++ )
+                       fprintf( stdout, "%5.3f\n", mutab[i] );
+
+               fprintf( stdout, "tmp = %f\n", tmp );
+#endif
+               delta = 0.01 / tmp;
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ )
+                       {
+                               if( i != j )
+                                       pam1[i][j] = delta * rsr[i][j] * freq[i];
+                               else
+                                       pam1[i][j] = 1.0 - delta * mutab[i];
+                       }
+               }
+
+               if( disp )
+               {
+                       fprintf( stdout, "pam1 = \n" );
+                       for( i=0; i<20; i++ )
+                       {
+                               for( j=0; j<20; j++ )
+                               {
+                                       fprintf( stdout, "%9.6f ", pam1[i][j] );
+                               }
+                               fprintf( stdout, "\n" );
+                       }
+               }
+
+               MtxuntDouble( pamx, 20 );
+               for( x=0; x < pamN; x++ ) MtxmltDouble( pamx, pam1, 20 );
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       pamx[i][j] /= freq[j];
+
+        for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+               {
+                       if( pamx[i][j] == 0.0 ) 
+                       {
+                               fprintf( stderr, "WARNING: pamx[%d][%d] = 0.0?\n", i, j );
+                               pamx[i][j] = 0.00001; /* by J. Thompson */
+                       }
+            pamx[i][j] = log10( pamx[i][j] ) * 1000.0;
+               }
+#if TEST
+               fprintf( stdout, "raw scoring matrix : \n" );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stdout, "%5.0f", pamx[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+        average = tmp = 0.0;
+        for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+               {
+           average += pamx[i][j] * freq1[i] * freq1[j];
+                  tmp += freq1[i] * freq1[j];
+               }
+               average /= tmp;
+               fprintf( stdout, "Zenbu average = %f, tmp = %f \n", average, tmp );
+        average = tmp = 0.0;
+        for( i=0; i<20; i++ ) for( j=i; j<20; j++ )
+               {
+           average += pamx[i][j] * freq1[i] * freq1[j];
+                  tmp += freq1[i] * freq1[j];
+               }
+               average /= tmp;
+               fprintf( stdout, "Zenbu average2 = %f, tmp = %f \n", average, tmp );
+               average = tmp = 0.0;
+               for( i=0; i<20; i++ )
+               {
+                       average += pamx[i][i] * freq1[i];
+                       tmp += freq1[i];
+               }
+               average /= tmp;
+               fprintf( stdout, "Itch average = %f, tmp = %f \n", average, tmp );
+#endif
+
+#if NORMALIZE1
+               if( fmodel == -1 )
+                       average = 0.0;
+               else
+               {
+#if TEST
+                       for( i=0; i<20; i++ )
+                               fprintf( stdout, "freq[%c] = %f, datafreq[%c] = %f, freq1[] = %f\n", amino[i], freq[i], amino[i], datafreq[i], freq1[i] );
+#endif
+                       average = 0.0;
+                       for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+                               average += pamx[i][j] * freq1[i] * freq1[j];
+               }
+#if TEST
+               fprintf( stdout, "####### average2  = %f\n", average );
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       pamx[i][j] -= average;
+#if TEST
+               fprintf( stdout, "average2 = %f\n", average );
+               fprintf( stdout, "after average substruction : \n" );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stdout, "%5.0f", pamx[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+               
+               average = 0.0;
+               for( i=0; i<20; i++ ) 
+                       average += pamx[i][i] * freq1[i];
+#if TEST
+               fprintf( stdout, "####### average1  = %f\n", average );
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       pamx[i][j] *= 600.0 / average;
+#if TEST
+        fprintf( stdout, "after average division : \n" );
+        for( i=0; i<20; i++ )
+        {
+            for( j=0; j<=i; j++ )
+            {
+                fprintf( stdout, "%5.0f", pamx[i][j] );
+            }
+            fprintf( stdout, "\n" );
+        }
+#endif
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       pamx[i][j] -= offset;  
+#if TEST
+               fprintf( stdout, "after offset substruction (offset = %d): \n", offset );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<=i; j++ ) 
+                       {
+                               fprintf( stdout, "%5.0f", pamx[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+#endif
+#if 0
+/* Ãí°Õ ¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª */
+                       penalty -= offset;
+#endif
+
+
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) 
+                       pamx[i][j] = shishagonyuu( pamx[i][j] );
+
+#else
+
+        average = 0.0;
+        for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+           average += pamx[i][j];
+        average /= 400.0;
+
+        for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+        {
+            pamx[i][j] -= average;
+            pamx[i][j] = shishagonyuu( pamx[i][j] );
+        }
+#endif
+        if( disp )
+        {
+            fprintf( stdout, " scoring matrix  \n" );
+            for( i=0; i<20; i++ )
+            {
+                               fprintf( stdout, "%c    ", amino[i] );
+                for( j=0; j<20; j++ )
+                    fprintf( stdout, "%5.0f", pamx[i][j] );
+                fprintf( stdout, "\n" );
+            }
+                       fprintf( stdout, "     " );
+            for( i=0; i<20; i++ )
+                               fprintf( stdout, "    %c", amino[i] );
+
+                       average = 0.0;
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ )
+                               average += pamx[i][j] * freq1[i] * freq1[j];
+                       fprintf( stdout, "average = %f\n", average );
+
+                       average = 0.0;
+               for( i=0; i<20; i++ )
+                               average += pamx[i][i] * freq1[i];
+                       fprintf( stdout, "itch average = %f\n", average );
+                       fprintf( stderr, "parameters: %d, %d, %d\n", penalty, penalty_ex, offset );
+
+                       
+                       exit( 1 );
+        }
+
+               for( i=0; i<26; i++ ) for( j=0; j<26; j++ ) n_dis[i][j] = 0;
+               for( i=0; i<20; i++ ) for( j=0; j<20; j++ ) n_dis[i][j] = (int)pamx[i][j];
+
+               fprintf( stderr, "done.\n" );
+               FreeDoubleMtx( rsr );
+               FreeDoubleMtx( pam1 );
+               FreeDoubleMtx( pamx );
+               FreeDoubleVec( freq );
+               FreeDoubleVec( mutab );
+               FreeDoubleVec( datafreq );
+       }
+       fprintf( stderr, "scoremtx = %d\n", scoremtx );
+
+#if DEBUG
+       fprintf( stderr, "scoremtx = %d\n", scoremtx );
+       fprintf( stderr, "amino[] = %s\n", amino );
+#endif
+
+       for( i=0; i<0x80; i++ )amino_n[i] = -1;
+       for( i=0; i<26; i++) amino_n[(int)amino[i]] = i;
+    for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis[i][j] = 0;
+    for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_disLN[i][j] = 0;
+    for( i=0; i<0x80; i++ ) for( j=0; j<0x80; j++ ) amino_dis_consweight_multi[i][j] = 0.0;
+    for( i=0; i<26; i++) for( j=0; j<26; j++ )
+       {
+        amino_dis[(int)amino[i]][(int)amino[j]] = n_dis[i][j];
+               n_dis_consweight_multi[i][j] = (float)n_dis[i][j] * consweight_multi;
+               amino_dis_consweight_multi[(int)amino[i]][(int)amino[j]] = (double)n_dis[i][j] * consweight_multi;
+       }
+
+       if( dorp == 'd' )  /* DNA */
+       {
+           for( i=0; i<5; i++) for( j=0; j<5; j++ )
+               amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN;
+           for( i=5; i<10; i++) for( j=5; j<10; j++ )
+               amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN;
+           for( i=0; i<5; i++) for( j=0; j<5; j++ )
+               n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT;
+           for( i=5; i<10; i++) for( j=5; j<10; j++ )
+               n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT;
+       }
+       else // protein
+       {
+           for( i=0; i<20; i++) for( j=0; j<20; j++ )
+               amino_disLN[(int)amino[i]][(int)amino[j]] = n_dis[i][j] + offset - offsetLN;
+           for( i=0; i<20; i++) for( j=0; j<20; j++ )
+               n_disFFT[i][j] = n_dis[i][j] + offset - offsetFFT;
+       }
+
+#if 0
+               fprintf( stderr, "amino_dis (offset = %d): \n", offset );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stderr, "%5d", amino_dis[(int)amino[i]][(int)amino[j]] );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+
+               fprintf( stderr, "amino_disLN (offsetLN = %d): \n", offsetLN );
+               for( i=0; i<20; i++ )
+               {
+                       for( j=0; j<20; j++ ) 
+                       {
+                               fprintf( stderr, "%5d", amino_disLN[(int)amino[i]][(int)amino[j]] );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+
+               fprintf( stderr, "n_dis (offset = %d): \n", offset );
+               for( i=0; i<26; i++ )
+               {
+                       for( j=0; j<26; j++ ) 
+                       {
+                               fprintf( stderr, "%5d", n_dis[i][j] );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+
+               fprintf( stderr, "n_disFFT (offsetFFT = %d): \n", offsetFFT );
+               for( i=0; i<26; i++ )
+               {
+                       for( j=0; j<26; j++ ) 
+                       {
+                               fprintf( stderr, "%5d", n_disFFT[i][j] );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+exit( 1 );
+#endif
+
+
+       ppid = 0;
+
+
+       if( fftThreshold == NOTSPECIFIED )
+       {
+               fftThreshold = FFT_THRESHOLD;
+       }
+       if( fftWinSize == NOTSPECIFIED )
+       {
+               if( dorp == 'd' ) 
+                       fftWinSize = FFT_WINSIZE_D;
+               else    
+                       fftWinSize = FFT_WINSIZE_P;
+       }
+
+
+       if( fftscore )
+       {
+               double av, sd;
+
+               for( i=0; i<20; i++ ) polarity[i] = polarity_[i];
+               for( av=0.0, i=0; i<20; i++ ) av += polarity[i];
+               av /= 20.0;
+               for( sd=0.0, i=0; i<20; i++ ) sd += ( polarity[i]-av ) * ( polarity[i]-av );
+               sd /= 20.0; sd = sqrt( sd );
+               for( i=0; i<20; i++ ) polarity[i] -= av;
+               for( i=0; i<20; i++ ) polarity[i] /= sd;
+       
+               for( i=0; i<20; i++ ) volume[i] = volume_[i];
+               for( av=0.0, i=0; i<20; i++ ) av += volume[i];
+               av /= 20.0;
+               for( sd=0.0, i=0; i<20; i++ ) sd += ( volume[i]-av ) * ( volume[i]-av );
+               sd /= 20.0; sd = sqrt( sd );
+               for( i=0; i<20; i++ ) volume[i] -= av;
+               for( i=0; i<20; i++ ) volume[i] /= sd;
+
+#if 0
+               for( i=0; i<20; i++ ) fprintf( stdout, "amino=%c, pol = %f<-%f, vol = %f<-%f\n", amino[i], polarity[i], polarity_[i], volume[i], volume_[i] );
+               for( i=0; i<20; i++ ) fprintf( stdout, "%c %+5.3f %+5.3f\n", amino[i], volume[i], polarity[i] );
+#endif
+       }
+}
diff --git a/binaries/src/mafft/core/contrafoldwrap.c b/binaries/src/mafft/core/contrafoldwrap.c
new file mode 100644 (file)
index 0000000..9de7f32
--- /dev/null
@@ -0,0 +1,312 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+static char *whereiscontrafold;
+
+void unknown_n( char *out, char *in )
+{
+       while( *in )
+       {
+               if( *in == 'a' || *in == 'A' )
+                       *out = 'A';
+               else if( *in == 't' || *in == 'T' || *in == 'u' || *in == 'U' )
+                       *out = 'U';
+               else if( *in == 'g' || *in == 'G' )
+                       *out = 'G';
+               else if( *in == 'c' || *in == 'C' )
+                       *out = 'C';
+               else if( *in == '-' )
+                       *out = '-';
+               else
+                       *out = 'N';
+
+               out++;
+               in++;
+       }
+       *out = 0;
+}
+
+void outcontrafold( FILE *fp, RNApair **pairprob, int length )
+{
+       int i;
+       RNApair *pt;
+       for( i=0; i<length; i++ ) for( pt=pairprob[i]; pt->bestpos!=-1; pt++ )
+       {
+               if( pt->bestpos > i ) 
+                       fprintf( fp, "%d %d %f\n", i, pt->bestpos, pt->bestscore );
+       }
+}
+
+#if 1
+static void readcontrafold( FILE *fp, RNApair **pairprob, int length )
+{
+       char gett[10000];
+       int *pairnum;
+       char *pt;
+       int i;
+       int left, right;
+       float prob;
+
+       pairnum = (int *)calloc( length, sizeof( int ) );
+       for( i=0; i<length; i++ ) pairnum[i] = 0;
+
+       while( 1 )
+       {
+               if( feof( fp ) ) break;
+               fgets( gett, 9999, fp );
+
+//             fprintf( stderr, "gett=%s\n", gett );
+
+               pt = gett;
+
+               sscanf( gett, "%d ", &left );
+               left--;
+
+//             fprintf( stderr, "left=%d\n", left );
+               pt = strchr( pt, ' ' ) + 1;
+//             fprintf( stderr, "pt=%s\n", pt );
+
+               while( (pt = strchr( pt, ' ' ) ) )
+               {
+                       pt++;
+//                     fprintf( stderr, "pt=%s\n", pt );
+                       sscanf( pt, "%d:%f", &right, &prob );
+                       right--;
+
+//                     fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+
+                       pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) );
+                       pairprob[left][pairnum[left]].bestscore = prob;
+                       pairprob[left][pairnum[left]].bestpos = right;
+                       pairnum[left]++;
+                       pairprob[left][pairnum[left]].bestscore = -1.0;
+                       pairprob[left][pairnum[left]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+
+                       pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) );
+                       pairprob[right][pairnum[right]].bestscore = prob;
+                       pairprob[right][pairnum[right]].bestpos = left;
+                       pairnum[right]++;
+                       pairprob[right][pairnum[right]].bestscore = -1.0;
+                       pairprob[right][pairnum[right]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", right, left, prob );
+               }
+       }
+       free( pairnum );
+}
+#endif
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+       inputfile = NULL;
+       dorp = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       whereiscontrafold = NULL;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'd':
+                                       whereiscontrafold = *++argv;
+                                       fprintf( stderr, "whereiscontrafold = %s\n", whereiscontrafold );
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+int main( int argc, char *argv[] )
+{
+       static char com[10000];
+       static int  *nlen;      
+       int left, right;
+       int res;
+       static char **name, **seq, **nogap;
+       static int **gapmap;
+       static int *order;
+       int i, j;
+       FILE *infp;
+       RNApair ***pairprob;
+       RNApair **alnpairprob;
+       RNApair *pairprobpt;
+       RNApair *pt;
+       int *alnpairnum;
+       float prob;
+       int adpos;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       if( !whereiscontrafold )
+               whereiscontrafold = "";
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( dorp != 'd' )
+       {
+               fprintf( stderr, "nuc only\n" );
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*2+1 );
+       nogap = AllocateCharMtx( njob, nlenmax*2+1 );
+       gapmap = AllocateIntMtx( njob, nlenmax*2+1 );
+       order = AllocateIntVec( njob );
+       name = AllocateCharMtx( njob, B+1 );
+    nlen = AllocateIntVec( njob );
+       pairprob = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       alnpairprob = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) );
+       alnpairnum = AllocateIntVec( nlenmax );
+
+       for( i=0; i<nlenmax; i++ ) alnpairnum[i] = 0;
+
+       readData_pointer( infp, name, nlen, seq );
+       fclose( infp );
+
+       for( i=0; i<njob; i++ )
+       {
+               pairprob[i] = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) );
+               for( j=0; j<nlenmax; j++ )
+               {
+                       pairprob[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+                       pairprob[i][j][0].bestpos = -1;
+                       pairprob[i][j][0].bestscore = -1.0;
+               }
+               unknown_n( nogap[i], seq[i] );
+               order[i] = i;
+       }
+       for( j=0; j<nlenmax; j++ )
+       {
+               alnpairprob[j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+               alnpairprob[j][0].bestpos = -1;
+               alnpairprob[j][0].bestscore = -1.0;
+       }
+
+
+       constants( njob, seq );
+
+       fprintf( stderr, "running contrafold\n" );
+       for( i=0; i<njob; i++ )
+       {
+               fprintf( stderr, "%d / %d\n", i+1, njob );
+               commongappick_record( 1, nogap+i, gapmap[i] );
+               infp = fopen( "_contrafoldin", "w" );
+               fprintf( infp, ">in\n%s\n", nogap[i] );
+               fclose( infp );
+#if 0 // contrafold v1
+               sprintf( com, "env PATH=%s contrafold predict _contrafoldin --posteriors 0.01 > _contrafoldout", whereiscontrafold );
+#else // contrafold v2
+               sprintf( com, "env PATH=%s contrafold predict _contrafoldin --posteriors 0.01   _contrafoldout", whereiscontrafold );
+#endif
+               res = system( com );
+               if( res )
+               {
+                       fprintf( stderr, "error in contrafold\n" );
+                       fprintf( stderr, "=================================================================\n" );
+                       fprintf( stderr, "=================================================================\n" );
+                       fprintf( stderr, "==\n" );
+                       fprintf( stderr, "== This version of MAFFT supports CONTRAfold v2.02.\n" );
+                       fprintf( stderr, "== If you have a lower version of CONTRAfold installed in the\n" );
+                       fprintf( stderr, "== %s directory,\n", whereiscontrafold );
+                       fprintf( stderr, "== please update it!\n" );
+                       fprintf( stderr, "==\n" );
+                       fprintf( stderr, "=================================================================\n" );
+                       fprintf( stderr, "=================================================================\n" );
+                       exit( 1 );
+               }
+
+
+               infp = fopen( "_contrafoldout", "r" );
+               readcontrafold( infp, pairprob[i], nlenmax );
+               fclose( infp );
+               fprintf( stdout, ">%d\n", i );
+               outcontrafold( stdout, pairprob[i], nlenmax );
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               for( j=0; j<nlen[i]; j++ ) for( pairprobpt=pairprob[i][j]; pairprobpt->bestpos!=-1; pairprobpt++ )
+               {
+                       left = gapmap[i][j];
+                       right = gapmap[i][pairprobpt->bestpos];
+                       prob = pairprobpt->bestscore;
+
+                       for( pt=alnpairprob[left]; pt->bestpos!=-1; pt++ )
+                               if( pt->bestpos == right ) break;
+
+                       if( pt->bestpos == -1 )
+                       {
+                               alnpairprob[left] = (RNApair *)realloc( alnpairprob[left], (alnpairnum[left]+2) * sizeof( RNApair ) );
+                               adpos = alnpairnum[left];
+                               alnpairnum[left]++;
+                               alnpairprob[left][adpos].bestscore = 0.0;
+                               alnpairprob[left][adpos].bestpos = right;
+                               alnpairprob[left][adpos+1].bestscore = -1.0;
+                               alnpairprob[left][adpos+1].bestpos = -1;
+                               pt = alnpairprob[left]+adpos;
+                       }
+                       else
+                               adpos = pt-alnpairprob[left];
+
+                       pt->bestscore += prob;
+                       if( pt->bestpos != right )
+                       {
+                               fprintf( stderr, "okashii!\n" );
+                               exit( 1 );
+                       }
+//                     fprintf( stderr, "adding %d-%d, %f\n", left, right, prob );
+               }
+       }
+       return( 0 );
+
+#if 0
+       fprintf( stdout, "result=\n" );
+
+       for( i=0; i<nlenmax; i++ ) for( pairprobpt=alnpairprob[i]; pairprobpt->bestpos!=-1; pairprobpt++ )
+       {
+               pairprobpt->bestscore /= (float)njob;
+               left = i;
+               right = pairprobpt->bestpos;
+               prob = pairprobpt->bestscore;
+               fprintf( stdout, "%d-%d, %f\n", left, right, prob );
+       }
+
+       return( 0 );
+#endif
+}
diff --git a/binaries/src/mafft/core/countlen.c b/binaries/src/mafft/core/countlen.c
new file mode 100644 (file)
index 0000000..3cb7030
--- /dev/null
@@ -0,0 +1,61 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+int main( int argc, char *argv[] )
+{
+       FILE *infp;
+       int nlenmin;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       dorp = NOTSPECIFIED;
+       getnumlen_nogap( infp, &nlenmin );
+
+       fprintf( stdout, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp );
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/defs.c b/binaries/src/mafft/core/defs.c
new file mode 100644 (file)
index 0000000..4136bc3
--- /dev/null
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include "dp.h"
+#include "mltaln.h"
+
+int TLS commonAlloc1 = 0;
+int TLS commonAlloc2 = 0;
+int TLS **commonIP = NULL;
+int TLS **commonJP = NULL;
+int nthread = 1;
+int randomseed = 0;
+int parallelizationstrategy = BAATARI1;
+
+
+char modelname[100];
+int njob, nlenmax;
+int amino_n[0x80];
+char amino_grp[0x80];
+int amino_dis[0x80][0x80];
+int amino_disLN[0x80][0x80];
+double amino_dis_consweight_multi[0x80][0x80];
+int n_dis[26][26];
+int n_disFFT[26][26];
+float n_dis_consweight_multi[26][26];
+char amino[26];
+double polarity[20];
+double volume[20];
+int ribosumdis[37][37];
+
+int ppid;
+double thrinter;
+double fastathreshold;
+int pslocal, ppslocal;
+int constraint;
+int divpairscore;
+int fmodel; // 1-> fmodel 0->default -1->raw
+int nblosum; // 45, 50, 62, 80
+int kobetsubunkatsu;
+int bunkatsu;
+int dorp;
+int niter;
+int contin;
+int calledByXced;
+int devide;
+int scmtd;
+int weight;
+int utree;
+int tbutree;
+int refine;
+int check;
+double cut;
+int cooling;
+int penalty, ppenalty, penaltyLN;
+int RNApenalty, RNAppenalty;
+int RNApenalty_ex, RNAppenalty_ex;
+int penalty_ex, ppenalty_ex, penalty_exLN;
+int penalty_EX, ppenalty_EX;
+int penalty_OP, ppenalty_OP;
+int RNAthr, RNApthr;
+int offset, poffset, offsetLN, offsetFFT;
+int scoremtx;
+int TMorJTT;
+char use_fft;
+char force_fft;
+int nevermemsave;
+int fftscore;
+int fftWinSize;
+int fftThreshold;
+int fftRepeatStop;
+int fftNoAnchStop;
+int divWinSize;
+int divThreshold;
+int disp;
+int outgap = 1;
+char alg;
+int cnst;
+int mix;
+int tbitr;
+int tbweight;
+int tbrweight;
+int disopt;
+int pamN;
+int checkC;
+float geta2;
+int treemethod;
+int kimuraR;
+char *swopt;
+int fftkeika;
+int score_check;
+int makedistmtx;
+char *inputfile;
+char *addfile;
+int addprofile = 1;
+int rnakozo;
+char rnaprediction;
+int scoreout = 0;
+int outnumber = 0;
+
+char *signalSM;
+FILE *prep_g;
+FILE *trap_g;
+char **seq_g;
+char **res_g;
+
+float consweight_multi = 1.0;
+float consweight_rna = 0.0;
+char RNAscoremtx = 'n';
+
+char *newgapstr = "-";
diff --git a/binaries/src/mafft/core/disttbfast.c b/binaries/src/mafft/core/disttbfast.c
new file mode 100644 (file)
index 0000000..c7c50fc
--- /dev/null
@@ -0,0 +1,1799 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+#define END_OF_VEC -1
+
+static int nadd;
+static int treein;
+static int topin;
+static int treeout;
+static int noalign;
+static int distout;
+static float lenfaca, lenfacb, lenfacc, lenfacd;
+#if 0
+#define PLENFACA 0.0123
+#define PLENFACB 10252
+#define PLENFACC 10822
+#define PLENFACD 0.5
+#define DLENFACA 0.01
+#define DLENFACB 2445
+#define DLENFACC 2412
+#define DLENFACD 0.1
+#else
+#define PLENFACA 0.01
+#define PLENFACB 10000
+#define PLENFACC 10000
+#define PLENFACD 0.1
+#define DLENFACA 0.01
+#define DLENFACB 2500
+#define DLENFACC 2500
+#define DLENFACD 0.1
+#endif
+
+#ifdef enablemultithread
+typedef struct _treebasethread_arg
+{
+       int thread_no;
+       int njob;
+       int *nrunpt;
+       int *nlen;
+       int *jobpospt;
+       int ***topol;
+       Treedep *dep;
+       char **aseq;
+       double *effarr;
+       int *alloclenpt;
+       int *fftlog;
+       pthread_mutex_t *mutex;
+       pthread_cond_t *treecond;
+} treebasethread_arg_t;
+
+typedef struct _distancematrixthread_arg
+{
+       int thread_no;
+       int njob;
+       int *jobpospt;
+       int **pointt;
+       float **mtx;
+       pthread_mutex_t *mutex;
+} distancematrixthread_arg_t;
+#endif
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nthread = 1;
+       outnumber = 0;
+       topin = 0;
+       treein = 0;
+       treeout = 0;
+       distout = 0;
+       noalign = 0;
+       nevermemsave = 0;
+       inputfile = NULL;
+       nadd = 0;
+       addprofile = 1;
+       fftkeika = 0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       force_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'X';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = -1530;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = -123;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       TMorJTT = JTT;
+       scoreout = 0;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'I':
+                                       nadd = atoi( *++argv );
+                                       fprintf( stderr, "nadd = %d\n", nadd );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kappa = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+//                                     fprintf( stderr, "blosum %d / kimura 200 \n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt/kimura %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "tm %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'K':
+                                       addprofile = 0;
+                                       break;
+                               case 'y':
+                                       distout = 1;
+                                       break;
+                               case 't':
+                                       treeout = 1;
+                                       break;
+                               case 'T':
+                                       noalign = 1;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+#if 0
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+#endif
+                               case 'n' :
+                                       outnumber = 1;
+                                       break;
+                               case 's':
+                                       treemethod = 's';
+                                       break;
+                               case 'X':
+                                       treemethod = 'X'; // mix
+                                       break;
+                               case 'E':
+                                       treemethod = 'E'; // upg (average)
+                                       break;
+                               case 'q':
+                                       treemethod = 'q'; // minimum
+                                       break;
+#if 0
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'Q':
+                                       alg = 'Q';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'N':
+                                       nevermemsave = 1;
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'S':
+                                       scoreout = 1;
+                                       break;
+                               case 'B':
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'G':
+                                       use_fft = 1;
+                                       force_fft = 1;
+                                       break;
+                               case 'V':
+                                       topin = 1;
+                                       break;
+                               case 'U':
+                                       treein = 1;
+                                       break;
+                               case 'u':
+                                       weight = 0;
+                                       tbrweight = 0;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+#if 1
+                               case 'O':
+                                       outgap = 0;
+                                       break;
+#else
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#endif
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+}
+
+
+
+
+static int maxl;
+static int tsize;
+
+void seq_grp_nuc( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 4 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       if( grp - grpbk < 6 )
+       {
+//             fprintf( stderr, "\n\nWARNING: Too short.\nPlease also consider use mafft-ginsi, mafft-linsi or mafft-ginsi.\n\n\n" );
+//             exit( 1 );
+               *grpbk = -1;
+       }
+}
+
+void seq_grp( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 6 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       if( grp - grpbk < 6 )
+       {
+//             fprintf( stderr, "\n\nWARNING: Too short.\nPlease also consider use mafft-ginsi, mafft-linsi or mafft-ginsi.\n\n\n" );
+//             exit( 1 );
+               *grpbk = -1;
+       }
+}
+
+void makecompositiontable_p( short *table, int *pointt )
+{
+       int point;
+
+       while( ( point = *pointt++ ) != END_OF_VEC )
+               table[point]++;
+}
+
+int commonsextet_p( short *table, int *pointt )
+{
+       int value = 0;
+       short tmp;
+       int point;
+       static TLS short *memo = NULL;
+       static TLS int *ct = NULL;
+       static TLS int *cp;
+
+       if( table == NULL )
+       {
+               if( memo ) free( memo );
+               if( ct ) free( ct );
+               return( 0 );
+       }
+
+       if( *pointt == -1 )
+               return( 0 );
+
+       if( !memo )
+       {
+               memo = (short *)calloc( tsize, sizeof( short ) );
+               if( !memo ) ErrorExit( "Cannot allocate memo\n" );
+               ct = (int *)calloc( MIN( maxl, tsize )+1, sizeof( int ) );
+               if( !ct ) ErrorExit( "Cannot allocate memo\n" );
+       }
+
+       cp = ct;
+       while( ( point = *pointt++ ) != END_OF_VEC )
+       {
+               tmp = memo[point]++;
+               if( tmp < table[point] )
+                       value++;
+               if( tmp == 0 ) *cp++ = point;
+       }
+       *cp = END_OF_VEC;
+       
+       cp =  ct;
+       while( *cp != END_OF_VEC )
+               memo[*cp++] = 0;
+
+       return( value );
+}
+
+void makepointtable_nuc( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       if( *n == -1 )
+       {
+               *pointt = -1;
+               return;
+       }
+
+       p = n;
+       point  = *n++ *  1024;
+       point += *n++ *   256;
+       point += *n++ *    64;
+       point += *n++ *    16;
+       point += *n++ *     4;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 1024;
+               point *= 4;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+void makepointtable( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       if( *n == -1 )
+       {
+               *pointt = -1;
+               return;
+       }
+
+       p = n;
+       point  = *n++ *  7776;
+       point += *n++ *  1296;
+       point += *n++ *   216;
+       point += *n++ *    36;
+       point += *n++ *     6;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 7776;
+               point *= 6;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+#ifdef enablemultithread
+static void *distancematrixthread( void *arg )
+{
+       distancematrixthread_arg_t *targ = (distancematrixthread_arg_t *)arg;
+       int thread_no = targ->thread_no;
+       int njob = targ->njob;
+       int *jobpospt = targ->jobpospt;
+       int **pointt = targ->pointt;
+       float **mtx = targ->mtx;
+
+       short *table1;
+       int i, j;
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               i = *jobpospt;
+               if( i == njob )
+               {
+                       pthread_mutex_unlock( targ->mutex );
+                       commonsextet_p( NULL, NULL );
+                       return( NULL );
+               }
+               *jobpospt = i+1;
+               pthread_mutex_unlock( targ->mutex );
+
+               table1 = (short *)calloc( tsize, sizeof( short ) );
+               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+               if( i % 10 == 0 )
+               {
+                       fprintf( stderr, "\r% 5d / %d (thread %4d)", i+1, njob, thread_no );
+               }
+               makecompositiontable_p( table1, pointt[i] );
+
+               for( j=i; j<njob; j++ ) 
+               {
+                       mtx[i][j-i] = (float)commonsextet_p( table1, pointt[j] );
+               } 
+               free( table1 );
+       }
+}
+
+
+static void *treebasethread( void *arg )
+{
+       treebasethread_arg_t *targ = (treebasethread_arg_t *)arg;
+       int thread_no = targ->thread_no;
+       int *nrunpt = targ->nrunpt;
+       int njob = targ->njob;
+       int *nlen = targ->nlen;
+       int *jobpospt = targ->jobpospt;
+       int ***topol = targ->topol;
+       Treedep *dep = targ->dep;
+       char **aseq = targ->aseq;
+       double *effarr = targ->effarr;
+       int *alloclen = targ->alloclenpt;
+       int *fftlog = targ->fftlog;
+       
+       char **mseq1, **mseq2;
+       char **localcopy;
+       int i, j, l;
+       int len1, len2;
+       int clus1, clus2;
+       float pscore, tscore;
+       char *indication1, *indication2;
+       double *effarr1 = NULL;
+       double *effarr2 = NULL;
+       float dumfl = 0.0;
+       int ffttry;
+       int m1, m2;
+#if 0
+       int i, j;
+#endif
+
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       localcopy = calloc( njob, sizeof( char * ) );
+       effarr1 = AllocateDoubleVec( njob );
+       effarr2 = AllocateDoubleVec( njob );
+       indication1 = AllocateCharVec( 150 );
+       indication2 = AllocateCharVec( 150 );
+
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+//     for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               l = *jobpospt;
+               if( l == njob-1 )
+               {
+                       pthread_mutex_unlock( targ->mutex );
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonIP = NULL;
+                       Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL );
+                       free( mseq1 );
+                       free( mseq2 );
+                       free( localcopy );
+                       free( effarr1 );
+                       free( effarr2 );
+                       free( indication1 );
+                       free( indication2 );
+                       return( NULL );
+               }
+               *jobpospt = l+1;
+
+               if( dep[l].child0 != -1 )
+               {
+                       while( dep[dep[l].child0].done == 0 )
+                               pthread_cond_wait( targ->treecond, targ->mutex );
+               }
+               if( dep[l].child1 != -1 ) 
+               {
+                       while( dep[dep[l].child1].done == 0 )
+                               pthread_cond_wait( targ->treecond, targ->mutex );
+               }
+               while( *nrunpt >= nthread )
+                       pthread_cond_wait( targ->treecond, targ->mutex );
+               (*nrunpt)++;
+
+               m1 = topol[l][0][0];
+               m2 = topol[l][1][0];
+
+               len1 = strlen( aseq[m1] );
+               len2 = strlen( aseq[m2] );
+               if( *alloclen <= len1 + len2 )
+               {
+                       fprintf( stderr, "\nReallocating.." );
+                       *alloclen = ( len1 + len2 ) + 1000;
+                       ReallocateCharMtx( aseq, njob, *alloclen + 10  ); 
+                       fprintf( stderr, "done. *alloclen = %d\n", *alloclen );
+               }
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+               {
+                       localcopy[j] = calloc( *alloclen, sizeof( char ) );
+                       strcpy( localcopy[j], aseq[j] );
+               }
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+               {
+                       localcopy[j] = calloc( *alloclen, sizeof( char ) );
+                       strcpy( localcopy[j], aseq[j] );
+               }
+               pthread_mutex_unlock( targ->mutex );
+
+#if 1 // CHUUI@@@@
+               clus1 = fastconjuction_noname( topol[l][0], localcopy, mseq1, effarr1, effarr, indication1 );
+               clus2 = fastconjuction_noname( topol[l][1], localcopy, mseq2, effarr2, effarr, indication2 );
+#else
+               clus1 = fastconjuction_noweight( topol[l][0], localcopy, mseq1, effarr1,  indication1 );
+               clus2 = fastconjuction_noweight( topol[l][1], localcopy, mseq2, effarr2,  indication2 );
+#endif
+
+
+#if 0
+    for( i=0; i<clus1; i++ ) 
+    {
+        if( strlen( mseq1[i] ) != len1 ) 
+        {
+            fprintf( stderr, "i = %d / %d\n", i, clus1 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); 
+            exit( 1 );
+        }
+    }
+    for( j=0; j<clus2; j++ )
+    {
+        if( strlen( mseq2[j] ) != len2 ) 
+        {
+            fprintf( stderr, "j = %d / %d\n", j, clus2 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); 
+            exit( 1 );
+        }
+    }
+#endif
+
+#if 0
+    for( i=0; i<clus1; i++ ) 
+    {
+        if( strlen( mseq1[i] ) != len1 ) 
+        {
+            fprintf( stderr, "i = %d / %d\n", i, clus1 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); 
+            exit( 1 );
+        }
+    }
+    for( j=0; j<clus2; j++ )
+    {
+        if( strlen( mseq2[j] ) != len2 ) 
+        {
+            fprintf( stderr, "j = %d / %d\n", j, clus2 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); 
+            exit( 1 );
+        }
+    }
+#endif
+
+
+//             fprintf( trap_g, "\nSTEP-%d\n", l );
+//             fprintf( trap_g, "group1 = %s\n", indication1 );
+//             fprintf( trap_g, "group2 = %s\n", indication2 );
+
+//             fprintf( stderr, "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 );
+               fprintf( stderr, "\rSTEP % 5d / %d (thread %4d)", l+1, njob-1, thread_no );
+
+#if 0
+               fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 );
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+#endif
+
+/*
+               fprintf( stderr, "before align all\n" );
+               display( aseq, njob );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+
+               if( !nevermemsave && ( alg != 'M' && ( len1 > 30000 || len2 > 30000  ) ) )
+               {
+                       fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 );
+                       alg = 'M';
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonAlloc1 = 0;
+                       commonAlloc2 = 0;
+               }
+
+//             if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 );
+               if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000);
+               else                                               ffttry = 0;
+//             ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000); // v6.708
+//             fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 );
+
+               if( force_fft || ( use_fft && ffttry ) )
+               {
+                       fprintf( stderr, "f" );
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "m" );
+                               pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 );
+                       }
+                       else
+                       {
+                               pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL );
+                       }
+               }
+               else
+               {
+                       fprintf( stderr, "d" );
+                       fftlog[m1] = 0;
+                       switch( alg )
+                       {
+                               case( 'a' ):
+                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen );
+                                       break;
+                               case( 'M' ):
+                                       fprintf( stderr, "m" );
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'Q' ):
+                                       if( clus1 == 1 && clus2 == 1 && 0 )
+                                       {
+//                                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                                       pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                                       }
+                                       else
+                                       {
+                                               pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       }
+                                       break;
+                               case( 'R' ):
+                                       pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'H' ):
+                                       pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'A' ):
+                                       if( clus1 == 1 && clus2 == 1 )
+                                       {
+//                                             fprintf( stderr, "%d-%d", clus1, clus2 );
+                                               pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                                       }
+                                       else
+                                       {
+//                                             fprintf( stderr, "%d-%d", clus1, clus2 );
+                                               pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       }
+                                       break;
+                               default:
+                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                       }
+               }
+#if SCOREOUT
+               fprintf( stderr, "score = %10.2f\n", pscore );
+#endif
+               tscore += pscore;
+               nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] );
+
+
+               if( disp ) display( localcopy, njob );
+
+               pthread_mutex_lock( targ->mutex );
+               dep[l].done = 1;
+               (*nrunpt)--;
+               pthread_cond_broadcast( targ->treecond );
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+                       strcpy( aseq[j], localcopy[j] );
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+                       strcpy( aseq[j], localcopy[j] );
+               pthread_mutex_unlock( targ->mutex );
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+                       free( localcopy[j] );
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+                       free( localcopy[j] );
+               free( topol[l][0] );
+               free( topol[l][1] );
+               free( topol[l] );
+
+
+//             fprintf( stderr, "\n" );
+       }
+#if SCOREOUT
+       fprintf( stderr, "totalscore = %10.2f\n\n", tscore );
+#endif
+}
+#endif
+
+static void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, double *effarr, int *alloclen )
+{
+       int l, len1, len2, i, m;
+       int len1nocommongap, len2nocommongap;
+       int clus1, clus2;
+       float pscore, tscore;
+       static char *indication1, *indication2;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       static int *fftlog; // fixed at 2006/07/26
+       float dumfl = 0.0;
+       int ffttry;
+       int m1, m2;
+       static int *gaplen;
+       static int *gapmap;
+       static int *alreadyaligned;
+#if 0
+       int i, j;
+#endif
+
+       if( effarr1 == NULL ) 
+       {
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+               fftlog = AllocateIntVec( njob );
+               gaplen = AllocateIntVec( *alloclen+10 );
+               gapmap = AllocateIntVec( *alloclen+10 );
+               alreadyaligned = AllocateIntVec( njob );
+       }
+       for( i=0; i<njob-nadd; i++ ) alreadyaligned[i] = 1;
+       for( i=njob-nadd; i<njob; i++ ) alreadyaligned[i] = 0;
+
+       for( l=0; l<njob; l++ ) fftlog[l] = 1;
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+//     for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       tscore = 0.0;
+       for( l=0; l<njob-1; l++ )
+       {
+               if( mergeoralign[l] == 'n' )
+               {
+//                     fprintf( stderr, "SKIP!\n" );
+                       free( topol[l][0] );
+                       free( topol[l][1] );
+                       free( topol[l] );
+                       continue;
+               }
+
+               m1 = topol[l][0][0];
+               m2 = topol[l][1][0];
+               len1 = strlen( aseq[m1] );
+               len2 = strlen( aseq[m2] );
+               if( *alloclen < len1 + len2 )
+               {
+                       fprintf( stderr, "\nReallocating.." );
+                       *alloclen = ( len1 + len2 ) + 1000;
+                       ReallocateCharMtx( aseq, njob, *alloclen + 10  ); 
+                       gaplen = realloc( gaplen, ( *alloclen + 10 ) * sizeof( int ) );
+                       if( gaplen == NULL )
+                       {
+                               fprintf( stderr, "Cannot realloc gaplen\n" );
+                               exit( 1 );
+                       }
+                       gapmap = realloc( gapmap, ( *alloclen + 10 ) * sizeof( int ) );
+                       if( gapmap == NULL )
+                       {
+                               fprintf( stderr, "Cannot realloc gapmap\n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "done. *alloclen = %d\n", *alloclen );
+               }
+
+#if 1 // CHUUI@@@@
+               clus1 = fastconjuction_noname( topol[l][0], aseq, mseq1, effarr1, effarr, indication1 );
+               clus2 = fastconjuction_noname( topol[l][1], aseq, mseq2, effarr2, effarr, indication2 );
+#else
+               clus1 = fastconjuction_noweight( topol[l][0], aseq, mseq1, effarr1,  indication1 );
+               clus2 = fastconjuction_noweight( topol[l][1], aseq, mseq2, effarr2,  indication2 );
+#endif
+               if( mergeoralign[l] == '1' || mergeoralign[l] == '2' )
+               {
+                       newgapstr = "=";
+               }
+               else
+                       newgapstr = "-";
+
+               len1nocommongap = len1;
+               len2nocommongap = len2;
+               if( mergeoralign[l] == '1' ) // nai
+               {
+                       findcommongaps( clus2, mseq2, gapmap );
+                       commongappick( clus2, mseq2 );
+                       len2nocommongap = strlen( mseq2[0] );
+               }
+               else if( mergeoralign[l] == '2' )
+               {
+                       findcommongaps( clus1, mseq1, gapmap );
+                       commongappick( clus1, mseq1 );
+                       len1nocommongap = strlen( mseq1[0] );
+               }
+
+#if 0
+    for( i=0; i<clus1; i++ ) 
+    {
+        if( strlen( mseq1[i] ) != len1 ) 
+        {
+            fprintf( stderr, "i = %d / %d\n", i, clus1 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); 
+            exit( 1 );
+        }
+    }
+    for( j=0; j<clus2; j++ )
+    {
+        if( strlen( mseq2[j] ) != len2 ) 
+        {
+            fprintf( stderr, "j = %d / %d\n", j, clus2 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after conjuction) !\n" ); 
+            exit( 1 );
+        }
+    }
+#endif
+
+
+#if 0
+    for( i=0; i<clus1; i++ ) 
+    {
+        if( strlen( mseq1[i] ) != len1 ) 
+        {
+            fprintf( stderr, "i = %d / %d\n", i, clus1 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); 
+            exit( 1 );
+        }
+    }
+    for( j=0; j<clus2; j++ )
+    {
+        if( strlen( mseq2[j] ) != len2 ) 
+        {
+            fprintf( stderr, "j = %d / %d\n", j, clus2 ); 
+            fprintf( stderr, "hairetsu ga kowareta (in treebase, after free topol) !\n" ); 
+            exit( 1 );
+        }
+    }
+#endif
+
+
+//             fprintf( trap_g, "\nSTEP-%d\n", l );
+//             fprintf( trap_g, "group1 = %s\n", indication1 );
+//             fprintf( trap_g, "group2 = %s\n", indication2 );
+
+//             fprintf( stderr, "\rSTEP % 5d / %d %d-%d", l+1, njob-1, clus1, clus2 );
+               fprintf( stderr, "\rSTEP % 5d / %d ", l+1, njob-1 );
+               fflush( stderr );
+
+#if 0
+               fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 );
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+#endif
+
+/*
+               fprintf( stderr, "before align all\n" );
+               display( aseq, njob );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+
+               if( !nevermemsave && ( alg != 'M' && ( len1 > 30000 || len2 > 30000  ) ) )
+               {
+                       fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 );
+                       alg = 'M';
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonAlloc1 = 0;
+                       commonAlloc2 = 0;
+               }
+
+//             if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 );
+               if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000);
+               else                                               ffttry = 0;
+//             ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000); // v6.708
+//             fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 );
+
+               if( force_fft || ( use_fft && ffttry ) )
+               {
+                       fprintf( stderr, "f" );
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "m" );
+                               pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 );
+                       }
+                       else
+                       {
+                               pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL );
+                       }
+               }
+               else
+               {
+                       fprintf( stderr, "d" );
+                       fftlog[m1] = 0;
+                       switch( alg )
+                       {
+                               case( 'a' ):
+                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen );
+                                       break;
+                               case( 'M' ):
+                                       fprintf( stderr, "m" );
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'Q' ):
+                                       if( clus1 == 1 && clus2 == 1 && 0 )
+                                       {
+//                                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                                       pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                                       }
+                                       else
+                                       {
+                                               pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       }
+                                       break;
+                               case( 'R' ):
+                                       pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'H' ):
+                                       pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'A' ):
+                                       if( clus1 == 1 && clus2 == 1 )
+                                       {
+//                                             fprintf( stderr, "%d-%d", clus1, clus2 );
+                                               pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                                       }
+                                       else
+                                       {
+//                                             fprintf( stderr, "%d-%d", clus1, clus2 );
+                                               pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       }
+                                       break;
+                               default:
+                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                       }
+               }
+#if SCOREOUT
+               fprintf( stderr, "score = %10.2f\n", pscore );
+#endif
+               tscore += pscore;
+               nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] );
+
+//             writePre( njob, name, nlen, aseq, 0 );
+
+               if( disp ) display( aseq, njob );
+//             fprintf( stderr, "\n" );
+
+               if( mergeoralign[l] == '1' ) // jissainiha nai. atarashii hairetsu ha saigo dakara.
+               {
+                       adjustgapmap( strlen( mseq2[0] )-len2nocommongap+len2, gapmap, mseq2[0] );
+                       restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen );
+                       findnewgaps( clus2, mseq2, gaplen );
+                       insertnewgaps( njob, alreadyaligned, aseq, topol[l][1], topol[l][0], gaplen, gapmap, *alloclen, alg );
+                       for( i=0; i<njob; i++ ) eq2dash( aseq[i] );
+                       for( i=0; (m=topol[l][0][i])>-1; i++ ) alreadyaligned[m] = 1;
+               }
+               if( mergeoralign[l] == '2' )
+               {
+                       adjustgapmap( strlen( mseq1[0] )-len1nocommongap+len1, gapmap, mseq1[0] );
+//                     fprintf( stderr, ">STEP1 mseq1[0] = \n%s\n", mseq1[0] );
+//                     fprintf( stderr, ">STEP1 mseq2[0] = \n%s\n", mseq2[0] );
+                       restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen );
+//                     fprintf( stderr, "STEP2 mseq1[0] = %s\n", mseq1[0] );
+//                     fprintf( stderr, "STEP2 mseq2[0] = %s\n", mseq2[0] );
+                       findnewgaps( clus1, mseq1, gaplen );
+                       insertnewgaps( njob, alreadyaligned, aseq, topol[l][0], topol[l][1], gaplen, gapmap, *alloclen, alg );
+//                     fprintf( stderr, "STEP3 mseq1[0] = %s\n", mseq1[0] );
+//                     fprintf( stderr, "STEP3 mseq2[0] = %s\n", mseq2[0] );
+                       for( i=0; i<njob; i++ ) eq2dash( aseq[i] );
+                       for( i=0; (m=topol[l][1][i])>-1; i++ ) alreadyaligned[m] = 1;
+               }
+
+               free( topol[l][0] );
+               free( topol[l][1] );
+               free( topol[l] );
+       }
+#if SCOREOUT
+       fprintf( stderr, "totalscore = %10.2f\n\n", tscore );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'X' )
+               fprintf( fp, "Tree = UPGMA (mix).\n" );
+       else if( treemethod == 'E' )
+               fprintf( fp, "Tree = UPGMA (average).\n" );
+       else if( treemethod == 'q' )
+               fprintf( fp, "Tree = Minimum linkage.\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  *nlen;      
+       static int  *nogaplen;  
+       static char **name, **seq;
+       static char **mseq1, **mseq2;
+       static char **bseq;
+       static double *eff;
+       int i, j;
+       static int ***topol;
+       static int *addmem;
+       static Treedep *dep;
+       static float **len;
+       FILE *infp;
+//     FILE *adfp;
+       char c;
+       int alloclen;
+       float longer, shorter;
+       float lenfac;
+       float bunbo;
+
+       FILE *orderfp, *hat2p;
+       int *grpseq;
+       char *tmpseq;
+       int  **pointt;
+       float **mtx = NULL; // by D. Mathog
+       static short *table1;
+       char b[B];
+       int ien;
+       double unweightedspscore;
+       int alignmentlength;
+       char *mergeoralign;
+       int foundthebranch;
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob > 20000 )
+       {
+               fprintf( stderr, "The number of sequences must be < %d\n", 20000 );
+               fprintf( stderr, "Please try the --parttree option for such large data.\n" );
+               exit( 1 );
+       }
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*1+1 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+
+       topol = AllocateIntCub( njob, 2, 0 );
+       len = AllocateFloatMtx( njob, 2 );
+       eff = AllocateDoubleVec( njob );
+       mergeoralign = AllocateCharVec( njob );
+
+       dep = (Treedep *)calloc( njob, sizeof( Treedep ) );
+
+       if( nadd ) addmem = AllocateIntVec( nadd+1 );
+
+#if 0
+       Read( name, nlen, seq );
+       readData( infp, name, nlen, seq );
+#else
+    name = AllocateCharMtx( njob, B+1 );
+    nlen = AllocateIntVec( njob ); 
+    nogaplen = AllocateIntVec( njob ); 
+       readData_pointer( infp, name, nlen, seq );
+       fclose( infp );
+#endif
+
+       constants( njob, seq );
+
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+
+       fprintf( stderr, "\n" );
+
+       if( !treein )
+       {
+               fprintf( stderr, "\n\nMaking a distance matrix ..\n" );
+               fflush( stderr );
+
+           tmpseq = AllocateCharVec( nlenmax+1 );
+               grpseq = AllocateIntVec( nlenmax+1 );
+               pointt = AllocateIntMtx( njob, nlenmax+1 );
+       mtx = AllocateFloatHalfMtx( njob ); 
+               if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
+               else              tsize = (int)pow( 6, 6 );
+
+               if( dorp == 'd' )
+               {
+                       lenfaca = DLENFACA;
+                       lenfacb = DLENFACB;
+                       lenfacc = DLENFACC;
+                       lenfacd = DLENFACD;
+               }
+               else    
+               {
+                       lenfaca = PLENFACA;
+                       lenfacb = PLENFACB;
+                       lenfacc = PLENFACC;
+                       lenfacd = PLENFACD;
+               }
+
+               maxl = 0;
+               for( i=0; i<njob; i++ ) 
+               {
+                       gappick0( tmpseq, seq[i] );
+                       nogaplen[i] = strlen( tmpseq );
+                       if( nogaplen[i] < 6 )
+                       {
+//                             fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nogaplen[i] );
+//                             fprintf( stderr, "Please use mafft-ginsi, mafft-linsi or mafft-ginsi\n\n\n" );
+//                             exit( 1 );
+                       }
+                       if( nogaplen[i] > maxl ) maxl = nogaplen[i];
+                       if( dorp == 'd' ) /* nuc */
+                       {
+                               seq_grp_nuc( grpseq, tmpseq );
+                               makepointtable_nuc( pointt[i], grpseq );
+                       }
+                       else                 /* amino */
+                       {
+                               seq_grp( grpseq, tmpseq );
+                               makepointtable( pointt[i], grpseq );
+                       }
+               }
+#ifdef enablemultithread
+               if( nthread > 0 )
+               {
+                       distancematrixthread_arg_t *targ; 
+                       int jobpos;
+                       pthread_t *handle;
+                       pthread_mutex_t mutex;
+
+                       jobpos = 0; 
+                       targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) ); 
+                       handle = calloc( nthread, sizeof( pthread_t ) ); 
+                       pthread_mutex_init( &mutex, NULL );
+
+                       for( i=0; i<nthread; i++ )
+                       {
+                               targ[i].thread_no = i;
+                               targ[i].njob = njob;
+                               targ[i].jobpospt = &jobpos;
+                               targ[i].pointt = pointt;
+                               targ[i].mtx = mtx;
+                               targ[i].mutex = &mutex;
+
+                               pthread_create( handle+i, NULL, distancematrixthread, (void *)(targ+i) );
+                       }
+               
+                       for( i=0; i<nthread; i++ )
+                       {
+                               pthread_join( handle[i], NULL );
+                       }
+                       pthread_mutex_destroy( &mutex );
+                       free( handle );
+                       free( targ );
+               }
+               else
+#endif
+               {
+                       for( i=0; i<njob; i++ )
+                       {
+                               table1 = (short *)calloc( tsize, sizeof( short ) );
+                               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+                               if( i % 10 == 0 )
+                               {
+                                       fprintf( stderr, "\r% 5d / %d", i+1, njob );
+                                       fflush( stderr );
+                               }
+                               makecompositiontable_p( table1, pointt[i] );
+               
+                               for( j=i; j<njob; j++ ) 
+                               {
+                                       mtx[i][j-i] = (float)commonsextet_p( table1, pointt[j] );
+                               } 
+                               free( table1 );
+                       }
+               }
+               fprintf( stderr, "\ndone.\n\n" );
+               fflush( stderr );
+               ien = njob-1;
+
+               for( i=0; i<ien; i++ )
+               {
+                       for( j=i+1; j<njob; j++ ) 
+                       {
+                               if( nogaplen[i] > nogaplen[j] )
+                               {
+                                       longer=(float)nogaplen[i];
+                                       shorter=(float)nogaplen[j];
+                               }
+                               else
+                               {
+                                       longer=(float)nogaplen[j];
+                                       shorter=(float)nogaplen[i];
+                               }
+//                             lenfac = 3.0 / ( LENFACA + LENFACB / ( longer + LENFACC ) + shorter / longer * LENFACD );
+                               lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca );
+//                             lenfac = 1.0;
+//                             fprintf( stderr, "lenfac = %f (%.0f,%.0f)\n", lenfac, longer, shorter );
+                               bunbo = MIN( mtx[i][0], mtx[j][0] );
+                               if( bunbo == 0.0 )
+                                       mtx[i][j-i] = 1.0;
+                               else
+                                       mtx[i][j-i] = ( 1.0 - mtx[i][j-i] / bunbo ) * lenfac;
+//                             fprintf( stdout, "##### mtx = %f, mtx[i][0]=%f, mtx[j][0]=%f, bunbo=%f\n", mtx[i][j-i], mtx[i][0], mtx[j][0], bunbo );
+                       }
+               }
+               if( disopt )
+               {
+                       for( i=0; i<njob; i++ ) 
+                       {
+                               sprintf( b, "=lgth = %04d", nogaplen[i] );
+                               strins( b, name[i] );
+                       }
+               }
+               free( grpseq );
+               free( tmpseq );
+               FreeIntMtx( pointt );
+
+#if 1 // writehat2 wo kakinaosu
+               if( distout )
+               {
+                       hat2p = fopen( "hat2", "w" );
+                       WriteFloatHat2_pointer_halfmtx( hat2p, njob, name, mtx );
+                       fclose( hat2p );
+               }
+#endif
+
+       }
+       else {
+#if 0 // readhat2 wo kakinaosu
+               fprintf( stderr, "Loading 'hat2' ... " );
+               prep = fopen( "hat2", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat2." );
+               readhat2_float( prep, njob, name, mtx ); // name chuui
+               fclose( prep );
+               fprintf( stderr, "done.\n" );
+#endif
+       }
+
+       if( treein )
+       {
+               fprintf( stderr, "Loading a tree ... " );
+               loadtree( njob, topol, len, name, nogaplen, dep );
+       }
+       else if( topin )
+       {
+               fprintf( stderr, "Loading a topology ... " );
+               loadtop( njob, mtx, topol, len );
+               FreeFloatHalfMtx( mtx, njob );
+       }
+       else if( treeout )
+       {
+               fprintf( stderr, "Constructing a UPGMA tree ... " );
+
+               fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( njob, mtx, topol, len, name, nogaplen, dep );
+//             veryfastsupg_float_realloc_nobk_halfmtx_treeout( njob, mtx, topol, len, name, nogaplen );
+
+
+               FreeFloatHalfMtx( mtx, njob );
+       }
+       else
+       {
+               fprintf( stderr, "Constructing a UPGMA tree ... " );
+               fixed_musclesupg_float_realloc_nobk_halfmtx( njob, mtx, topol, len, dep );
+               FreeFloatHalfMtx( mtx, njob );
+       }
+//     else 
+//             ErrorExit( "Incorrect tree\n" );
+       fprintf( stderr, "\ndone.\n\n" );
+       fflush( stderr );
+
+       orderfp = fopen( "order", "w" );
+       if( !orderfp )
+       {
+               fprintf( stderr, "Cannot open 'order'\n" );
+               exit( 1 );
+       }
+       for( i=0; (j=topol[njob-2][0][i])!=-1; i++ )
+       {
+               fprintf( orderfp, "%d\n", j );
+       }
+       for( i=0; (j=topol[njob-2][1][i])!=-1; i++ )
+       {
+               fprintf( orderfp, "%d\n", j );
+       }
+       fclose( orderfp );
+
+       if( ( treeout || distout )  && noalign ) 
+       {
+               writeData_pointer( stdout, njob, name, nlen, seq );
+               fprintf( stderr, "\n" );
+               SHOWVERSION;
+               return( 0 );
+       }
+       
+
+       if( tbrweight )
+       {
+               weight = 3; 
+#if 0
+               utree = 0; counteff( njob, topol, len, eff ); utree = 1;
+#else
+               counteff_simple_float( njob, topol, len, eff );
+#endif
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) eff[i] = 1.0;
+       }
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stdout, "eff[%d] = %20.16f\n", i, eff[i] );
+       exit( 1 );
+#endif
+
+
+       FreeFloatMtx( len );
+
+       bseq = AllocateCharMtx( njob, nlenmax*2+1 );
+       alloclen = nlenmax*2+1;
+
+
+       if( nadd )
+       {
+               alignmentlength = strlen( seq[0] );
+               for( i=0; i<njob-nadd; i++ )
+               {
+                       if( alignmentlength != strlen( seq[i] ) )
+                       {
+                               fprintf( stderr, "#################################################################################\n" );
+                               fprintf( stderr, "# ERROR!                                                                        #\n" );
+                               fprintf( stderr, "# The original%4d sequences must be aligned                                    #\n", njob-nadd );
+                               fprintf( stderr, "#################################################################################\n" );
+                               exit( 1 );
+                       }
+               }
+               if( addprofile )
+               {
+                       alignmentlength = strlen( seq[njob-nadd] );
+                       for( i=njob-nadd; i<njob; i++ )
+                       {
+                               if( alignmentlength != strlen( seq[i] ) )
+                               {
+                                       fprintf( stderr, "###############################################################################\n" );
+                                       fprintf( stderr, "# ERROR!                                                                      #\n" );
+                                       fprintf( stderr, "# The%4d additional sequences must be aligned                                #\n", nadd );
+                                       fprintf( stderr, "# Otherwise, try the '--add' option, instead of '--addprofile' option.        #\n" );
+                                       fprintf( stderr, "###############################################################################\n" );
+                                       exit( 1 );
+                               }
+                       }
+                       for( i=0; i<nadd; i++ ) addmem[i] = njob-nadd+i;
+                       addmem[nadd] = -1;
+                       foundthebranch = 0;
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               if( samemember( topol[i][0], addmem ) ) // jissainiha nai
+                               {
+                                       mergeoralign[i] = '1';
+                                       foundthebranch = 1;
+                               }
+                               else if( samemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = '2';
+                                       foundthebranch = 1;
+                               }
+                               else
+                               {
+                                       mergeoralign[i] = 'n';
+                               }
+                       }
+                       if( !foundthebranch )
+                       {
+                               fprintf( stderr, "###############################################################################\n" );
+                               fprintf( stderr, "# ERROR!                                                                      #\n" );
+                               fprintf( stderr, "# There is no appropriate position to add the%4d sequences in the guide tree.#\n", nadd );
+                               fprintf( stderr, "# Check whether the%4d sequences form a monophyletic cluster.                #\n", nadd );
+                               fprintf( stderr, "# If not, try the '--add' option, instead of the '--addprofile' option.       #\n" );
+                               fprintf( stderr, "############################################################################### \n" );
+                               exit( 1 );
+                       }
+                       commongappick( nadd, seq+njob-nadd );
+                       for( i=njob-nadd; i<njob; i++ ) strcpy( bseq[i], seq[i] );
+               }
+               else
+               {
+                       for( i=0; i<njob-1; i++ ) mergeoralign[i] = 'n';
+                       for( j=njob-nadd; j<njob; j++ )
+                       {
+                               addmem[0] = j;
+                               addmem[1] = -1;
+                               for( i=0; i<njob-1; i++ )
+                               {
+                                       if( samemember( topol[i][0], addmem ) ) // arieru
+                                       {
+//                                             fprintf( stderr, "HIT!\n" );
+                                               if( mergeoralign[i] != 'n' ) mergeoralign[i] = 'w';
+                                               else mergeoralign[i] = '1';
+                                       }
+                                       else if( samemember( topol[i][1], addmem ) )
+                                       {
+//                                             fprintf( stderr, "HIT!\n" );
+                                               if( mergeoralign[i] != 'n' ) mergeoralign[i] = 'w';
+                                               else mergeoralign[i] = '2';
+                                       }
+                               }
+                       }
+       
+                       for( i=0; i<nadd; i++ ) addmem[i] = njob-nadd+i;
+                       addmem[nadd] = -1;
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               if( includemember( topol[i][0], addmem ) && includemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = 'w';
+                               }
+                               else if( includemember( topol[i][0], addmem ) )
+                               {
+                                       mergeoralign[i] = '1';
+                               }
+                               else if( includemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = '2';
+                               }
+                       }
+#if 0
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               fprintf( stderr, "mem0 = " );
+                               for( j=0; topol[i][0][j]>-1; j++ )      fprintf( stderr, "%d ", topol[i][0][j] );
+                               fprintf( stderr, "\n" );
+                               fprintf( stderr, "mem1 = " );
+                               for( j=0; topol[i][1][j]>-1; j++ )      fprintf( stderr, "%d ", topol[i][1][j] );
+                               fprintf( stderr, "\n" );
+                               fprintf( stderr, "i=%d, mergeoralign[] = %c\n", i, mergeoralign[i] );
+                       }
+#endif
+                       for( i=njob-nadd; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+               }
+
+               commongappick( njob-nadd, seq );
+               for( i=0; i<njob-nadd; i++ ) strcpy( bseq[i], seq[i] );
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+               for( i=0; i<njob-1; i++ ) mergeoralign[i] = 'a';
+       }
+
+       fprintf( stderr, "Progressive alignment ... \n" );
+
+#ifdef enablemultithread
+       if( nthread > 0 && nadd == 0 )
+       {
+               treebasethread_arg_t *targ; 
+               int jobpos;
+               pthread_t *handle;
+               pthread_mutex_t mutex;
+               pthread_cond_t treecond;
+               int *fftlog;
+               int nrun;
+               int nthread_yoyu;
+
+               nthread_yoyu = nthread * 1;
+               nrun = 0;
+               jobpos = 0; 
+               targ = calloc( nthread_yoyu, sizeof( treebasethread_arg_t ) ); 
+               fftlog = AllocateIntVec( njob );
+               handle = calloc( nthread_yoyu, sizeof( pthread_t ) ); 
+               pthread_mutex_init( &mutex, NULL );
+               pthread_cond_init( &treecond, NULL );
+
+               for( i=0; i<njob; i++ ) dep[i].done = 0; 
+               for( i=0; i<njob; i++ ) fftlog[i] = 1; 
+
+               for( i=0; i<nthread_yoyu; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].njob = njob;
+                       targ[i].nrunpt = &nrun;
+                       targ[i].nlen = nlen;
+                       targ[i].jobpospt = &jobpos;
+                       targ[i].topol = topol;
+                       targ[i].dep = dep;
+                       targ[i].aseq = bseq;
+                       targ[i].effarr = eff;
+                       targ[i].alloclenpt = &alloclen;
+                       targ[i].fftlog = fftlog;
+                       targ[i].mutex = &mutex;
+                       targ[i].treecond = &treecond;
+
+                       pthread_create( handle+i, NULL, treebasethread, (void *)(targ+i) );
+               }
+               
+               for( i=0; i<nthread_yoyu; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+               pthread_mutex_destroy( &mutex );
+               pthread_cond_destroy( &treecond );
+               free( handle );
+               free( targ );
+               free( fftlog );
+       }
+       else
+#endif
+       {
+               treebase( nlen, bseq, nadd, mergeoralign, mseq1, mseq2, topol, eff, &alloclen );
+       }
+       fprintf( stderr, "\ndone.\n\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+       if( scoreout )
+       {
+               unweightedspscore = plainscore( njob, bseq );
+               fprintf( stderr, "\nSCORE %s = %.0f, ", "(treebase)", unweightedspscore );
+               fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( njob * strlen( bseq[0] ) ) );
+               fprintf( stderr, "\n\n" );
+       }
+
+       free( mergeoralign );
+//     writePre( njob, name, nlen, aseq, !contin );
+#if DEBUG
+       fprintf( stderr, "writing alignment to stdout\n" );
+#endif
+       writeData_pointer( stdout, njob, name, nlen, bseq );
+#if 0
+       writeData( stdout, njob, name, nlen, bseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
+
diff --git a/binaries/src/mafft/core/dndblast.c b/binaries/src/mafft/core/dndblast.c
new file mode 100644 (file)
index 0000000..7fd1aed
--- /dev/null
@@ -0,0 +1,396 @@
+#include "mltaln.h"
+#include <sys/types.h>
+#include <unistd.h>
+#define DEBUG 0
+#define TEST 0
+
+
+int howmanyx( char *s )
+{
+       int val = 0;
+       if( scoremtx == -1 )
+       {
+               do
+               {
+                       if( !strchr( "atgcuATGCU", *s ) ) val++;
+               } while( *++s );
+       }
+       else
+       {
+               do
+               {
+                       if( !strchr( "ARNDCQEGHILKMFPSTWYV", *s ) ) val++;
+               } while( *++s );
+       }
+       return( val );
+}
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+
+       inputfile = NULL;
+       disopt = 0;
+       divpairscore = 0;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'I':
+                                       disopt = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+
+       }
+    if( argc != 0 )
+    {
+        fprintf( stderr, "options: -i\n" );
+        exit( 1 );
+    }
+}
+
+int main( int argc, char *argv[] )
+{
+       int ktuple;
+       int i, j;
+       FILE *infp;
+       FILE *hat2p;
+       FILE *hat3p;
+       char **seq = NULL; // by D.Mathog
+       char **seq1;
+       static char name[M][B];
+       static char name1[M][B];
+       static int nlen1[M];
+       double **mtx;
+       double **mtx2;
+       static int nlen[M];
+       char b[B];
+       double max;
+       char com[1000];
+       int opt[M];
+       int res;
+       char *home;
+       char queryfile[B];
+       char datafile[B];
+       char fastafile[B];
+       char hat2file[B];
+       int pid = (int)getpid();
+       LocalHom **localhomtable, *tmpptr;
+#if 1
+       home = getenv( "HOME" );
+#else /* $HOME wo tsukau to fasta ni watasu hikisuu ga afureru */ 
+       home = NULL;
+#endif
+
+#if DEBUG
+       if( home ) fprintf( stderr, "home = %s\n", home );
+#endif
+       if( !home ) home = "";
+       sprintf( queryfile, "%s/tmp/query-%d", home, pid );
+       sprintf( datafile, "%s/tmp/data-%d", home, pid );
+       sprintf( fastafile, "%s/tmp/fasta-%d", home, pid );
+       sprintf( hat2file, "hat2-%d", pid );
+
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+#if 0
+       PreRead( infp, &njob, &nlenmax );
+#else
+       dorp = NOTSPECIFIED;
+       getnumlen( infp );
+#endif
+
+       if( dorp == 'd' )
+       {
+               scoremtx = -1;
+               pamN = NOTSPECIFIED;
+       }
+       else
+       {
+               nblosum = 62;
+               scoremtx = 1;
+       }
+       constants( njob, seq );
+
+       rewind( infp );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       seq1 = AllocateCharMtx( 2, nlenmax+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       mtx2 = AllocateDoubleMtx( njob, njob );
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++) 
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1;
+                       localhomtable[i][j].end2 = -1;
+                       localhomtable[i][j].opt = -1.0; 
+                       localhomtable[i][j].next = NULL; 
+
+               }
+    }
+
+#if 0
+       FRead( infp, name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+       
+       if( scoremtx == -1 ) ktuple = 6;
+       else                 ktuple = 1;
+
+       for( i=0; i<njob; i++ )
+       {
+               gappick0( seq1[0], seq[i] ); 
+               strcpy( seq[i], seq1[0] );
+       }
+       for( j=0; j<njob; j++ )
+       {
+               sprintf( name1[j], "+==========+%d                      ", j );
+               nlen1[j] = nlen[j];
+       }
+
+       for( i=0; i<njob; i++ ) 
+       {
+//             fprintf( stderr, "###  i = %d\n", i );
+
+               if( i % 10 == 0 )
+               {
+                       fprintf( stderr, "formatting .. " );
+                       hat2p = fopen( datafile, "w" );
+                       if( !hat2p ) ErrorExit( "Cannot open datafile." );
+                       WriteForFasta( hat2p, njob-i, name1+i, nlen1+i, seq+i );
+                       fclose( hat2p );
+               
+                       if( scoremtx == -1 )
+                               sprintf( com, "formatdb  -p f -i %s -o F", datafile );
+                       else
+                               sprintf( com, "formatdb  -i %s -o F", datafile );
+                       system( com );
+                       fprintf( stderr, "done.\n" );
+               }
+
+               hat2p = fopen( queryfile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open queryfile." );
+               WriteForFasta( hat2p, 1, name1+i, nlen+i, seq+i ); 
+               fclose( hat2p );
+
+
+               if( scoremtx == -1 )
+                       sprintf( com, "blastall -e 1e10 -p blastn -m 7  -i %s -d %s >  %s", queryfile, datafile, fastafile );
+               else
+                       sprintf( com, "blastall -G 10 -E 1 -e 1e10 -p blastp -m 7  -i %s -d %s >  %s", queryfile, datafile, fastafile );
+               res = system( com );
+               if( res ) ErrorExit( "error in fasta" );
+
+
+               hat2p = fopen( fastafile, "r" );
+               if( hat2p == NULL ) 
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               res = ReadBlastm7( hat2p, mtx[i], i, name1, localhomtable[i] );
+               fclose( hat2p );
+
+#if 0
+               for( j=0; j<njob; j++ )
+               {
+                       for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+//                             fprintf( stderr, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next );
+                       }
+               }
+#endif
+
+               if( res < njob-i+i%10 )
+               {
+                       fprintf( stderr, "WARNING: count (blast) = %d < %d\n", res, njob-i+i%10 );
+               }
+
+
+#if 0
+               {
+                       int ii, jj;
+                       if( i < njob-1 ) for( jj=i; jj<i+5; jj++ ) 
+                               fprintf( stdout, "mtx[%d][%d] = %f\n", i+1, jj+1, mtx[i][jj] );
+               }
+#endif
+               fprintf( stderr, "query : %4d / %d\n", i+1, njob );
+       }
+
+#if 1
+       fprintf( stderr, "##### writing hat3\n" );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ )
+       {
+//             fprintf( stderr, "mtx[%d][%d] = %f, mtx[%d][%d] = %f\n", i, j, mtx[i][j], j, i, mtx[j][i] );
+               if( i == j ) continue;
+               if( mtx[i][j] == mtx[j][i] && i > j ) continue;
+               if( mtx[j][i] > mtx[i][j] ) continue;
+               for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+               {
+                       if( tmpptr->opt == -1.0 ) continue;
+                       fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next );
+               }
+       }
+       fclose( hat3p );
+#endif
+
+       for( i=0; i<njob; i++ ) 
+       {
+//             fprintf( stderr, "###  i = %d\n", i );
+               hat2p = fopen( datafile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open datafile." );
+               WriteForFasta( hat2p, njob-i, name1+i, nlen1+i, seq+i );
+               fclose( hat2p );
+
+//             seq1[0] = seq[i];
+//             nlen1[0] = nlen[i];
+
+               hat2p = fopen( queryfile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open queryfile." );
+               WriteForFasta( hat2p, 1, name1+i, nlen+i, seq+i ); 
+               fclose( hat2p );
+
+
+               if( scoremtx == -1 )
+                       sprintf( com, "fasta34 -z3 -m10  -n -Q  -b%d -E%d -d%d %s %s %d > %s", M, M, 0, queryfile, datafile, ktuple, fastafile );
+               else
+                       sprintf( com, "fasta34 -z3 -m10  -Q  -b%d -E%d -d%d %s %s %d > %s", M, M, 0, queryfile, datafile, ktuple, fastafile );
+               res = system( com );
+               if( res ) ErrorExit( "error in fasta" );
+
+
+               hat2p = fopen( fastafile, "r" );
+               if( hat2p == NULL ) 
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               res = ReadFasta34noalign( hat2p, mtx[i], i, name1, localhomtable[i] );
+               fclose( hat2p );
+               if( res < njob - i )
+               {
+                       fprintf( stderr, "count (fasta34 -z 3) = %d\n", res );
+                       exit( 1 );
+               }
+
+
+               if( i == 0 )
+                       for( j=0; j<njob; j++ ) opt[j] = (int)mtx[0][j];
+
+
+#if 0
+               {
+                       int ii, jj;
+                       if( i < njob-1 ) for( jj=i; jj<i+5; jj++ ) 
+                               fprintf( stdout, "mtx[%d][%d] = %f\n", i+1, jj+1, mtx[i][jj] );
+               }
+#endif
+               fprintf( stderr, "query : %4d\r", i+1 );
+       }
+
+
+
+
+       for( i=0; i<njob; i++ )
+       {
+               max = mtx[i][i];
+               if( max == 0.0 )
+               {
+                       for( j=0; j<njob; j++ )
+                               mtx2[i][j] = 2.0;
+               }
+               else
+               {
+                       for( j=0; j<njob; j++ )
+                       {
+                               mtx2[i][j] = ( max - mtx[MIN(i,j)][MAX(i,j)] ) / max * 2.0;
+//                             fprintf( stdout, "max = %f, mtx[%d][%d] = %f -> %f\n", max, i+1, j+1, mtx[i][j], mtx2[i][j] );
+                       }
+               }
+       }
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
+       {
+//             fprintf( stdout, "mtx2[%d][%d] = %f, %f\n", i+1, j+1, mtx2[i][j], mtx2[j][i] );
+               mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
+       }
+
+#if 0
+       {
+               int ii, jj;
+               if( i < njob-1 ) for( jj=i+1; jj<njob; jj++ ) 
+                       fprintf( stderr, "mtx2[][] = %f\n", mtx2[i][jj] );
+       }
+#endif
+
+       for( i=0; i<njob; i++ ) name[i][0] = '=';
+
+       if( disopt )
+       {
+               strcpy( b, name[0] );
+               sprintf( name[0], "=query====lgth=%04d-%04d %.*s", nlen[0], howmanyx( seq[0] ), B-30, b );
+#if 0
+               strins(  b, name[0] );
+#endif
+               for( i=1; i<njob; i++ ) 
+               {       
+                       strcpy( b, name[i] );
+                       sprintf( name[i], "=opt=%04d=lgth=%04d-%04d %.*s", opt[i], nlen[i], howmanyx( seq[i] ), B-30, b );
+#if 0
+                       strins( b, name[i] );
+#endif
+               }
+       }
+
+       hat2p = fopen( hat2file, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( hat2p, njob, name, mtx2 );
+       fclose( hat2p );
+
+
+       sprintf( com, "/bin/rm %s %s %s", queryfile, datafile, fastafile );
+       system( com );
+
+#if 0
+       sprintf( com, ALNDIR "/supgsdl < %s", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in spgsdl" );
+#endif
+
+       sprintf( com, "mv %s hat2", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in mv" );
+
+       SHOWVERSION;
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/dndfast4.c b/binaries/src/mafft/core/dndfast4.c
new file mode 100644 (file)
index 0000000..1fb3ca7
--- /dev/null
@@ -0,0 +1,241 @@
+#include "mltaln.h"
+#include <sys/types.h>
+#include <unistd.h>
+#define DEBUG 0
+#define TEST 0
+
+
+int howmanyx( char *s )
+{
+       int val = 0;
+       if( scoremtx == -1 )
+       {
+               do
+               {
+                       if( !strchr( "atgcuATGCU", *s ) ) val++;
+               } while( *++s );
+       }
+       else
+       {
+               do
+               {
+                       if( !strchr( "ARNDCQEGHILKMFPSTWYV", *s ) ) val++;
+               } while( *++s );
+       }
+       return( val );
+}
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+
+       disopt = 0;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+        while ( c = *++argv[0] )
+            switch( c )
+            {
+                               case 'i':
+                                       disopt = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+    if( argc != 0 )
+    {
+        fprintf( stderr, "options: -i\n" );
+        exit( 1 );
+    }
+}
+
+int main( int argc, char *argv[] )
+{
+       int ktuple;
+       int i, j;
+       FILE *hat2p;
+       char **seq;
+       char **seq1;
+       static char name[M][B];
+       static char name1[M][B];
+       static int nlen1[M];
+       double **mtx;
+       double **mtx2;
+       static int nlen[M];
+       char b[B];
+       double max;
+       char com[B];
+       int opt[M];
+       int res;
+       char *home;
+       char queryfile[B];
+       char datafile[B];
+       char fastafile[B];
+       char hat2file[B];
+       int pid = (int)getpid();
+#if 0
+       home = getenv( "HOME" );
+#else /* $HOME wo tsukau to fasta ni watasu hikisuu ga afureru */ 
+       home = NULL;
+#endif
+
+#if DEBUG
+       if( home ) fprintf( stderr, "home = %s\n", home );
+#endif
+       if( !home ) home = "";
+       sprintf( queryfile, "%s/tmp/query-%d\0", home, pid );
+       sprintf( datafile, "%s/tmp/data-%d\0", home, pid );
+       sprintf( fastafile, "%s/tmp/fasta-%d\0", home, pid );
+       sprintf( hat2file, "hat2-%d\0", pid );
+
+       arguments( argc, argv );
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( stdin );
+#endif
+       rewind( stdin );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       seq1 = AllocateCharMtx( 2, nlenmax+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       mtx2 = AllocateDoubleMtx( njob, njob );
+
+#if 0
+       FRead( stdin, name, nlen, seq );
+#else
+       readData( stdin, name, nlen, seq );
+#endif
+       if( scoremtx == -1 ) ktuple = 6;
+       else                 ktuple = 1;
+
+       for( i=0; i<njob; i++ )
+       {
+               gappick0( seq1[0], seq[i] ); 
+               strcpy( seq[i], seq1[0] );
+       }
+       for( j=0; j<njob; j++ )
+       {
+               sprintf( name1[j], "+==========+%d                      \0", j );
+               nlen1[j] = nlen[j];
+       }
+       hat2p = fopen( datafile, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open datafile." );
+       WriteForFasta( hat2p, njob, name1, nlen1, seq );
+       fclose( hat2p );
+
+       for( i=0; i<njob; i++ ) 
+       {
+
+               hat2p = fopen( datafile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open datafile." );
+               WriteForFasta( hat2p, njob-i, name1+i, nlen1+i, seq+i );
+               fclose( hat2p );
+
+
+               seq1[0] = seq[i];
+               nlen1[0] = nlen[i];
+
+               hat2p = fopen( queryfile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open queryfile." );
+               WriteForFasta( hat2p, 1, name1+i, nlen1, seq1 ); 
+               fclose( hat2p );
+
+               if( scoremtx == -1 )
+                       sprintf( com, "fasta3 -n -Q -h -b%d -E%d -d%d %s %s %d > %s\0", M, M, 0, queryfile, datafile, ktuple, fastafile );
+               else
+                       sprintf( com, "fasta3 -Q -h -b%d -E%d -d%d %s %s %d > %s\0", M, M, 0, queryfile, datafile, ktuple, fastafile );
+               res = system( com );
+               if( res ) ErrorExit( "error in fasta" );
+
+               hat2p = fopen( fastafile, "r" );
+               if( hat2p == NULL ) 
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               ReadFasta3( hat2p, mtx[i], njob-i, name1 );
+
+               if( i == 0 )
+                       for( j=0; j<njob; j++ ) opt[j] = (int)mtx[0][j];
+
+               fclose( hat2p );
+
+#if 1
+               {
+                       int ii, jj;
+                       if( i < njob-1 ) for( jj=i; jj<i+5; jj++ ) 
+                               fprintf( stdout, "mtx[%d][%d] = %f\n", i+1, jj+1, mtx[i][jj] );
+               }
+#endif
+               fprintf( stderr, "query : %#4d\n", i+1 );
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               max = mtx[i][i];
+               if( max == 0.0 )
+               {
+                       for( j=0; j<njob; j++ )
+                               mtx2[i][j] = 2.0;
+               }
+               else
+               {
+                       for( j=0; j<njob; j++ )
+                       {
+                               mtx2[i][j] = ( max - mtx[MIN(i,j)][MAX(i,j)] ) / max * 2.0;
+//                             fprintf( stdout, "max = %f, mtx[%d][%d] = %f -> %f\n", max, i+1, j+1, mtx[i][j], mtx2[i][j] );
+                       }
+               }
+       }
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
+       {
+//             fprintf( stdout, "mtx2[%d][%d] = %f, %f\n", i+1, j+1, mtx2[i][j], mtx2[j][i] );
+               mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
+       }
+#if 0
+       {
+               int ii, jj;
+               if( i < njob-1 ) for( jj=i+1; jj<njob; jj++ ) 
+                       fprintf( stderr, "mtx2[][] = %f\n", mtx2[i][jj] );
+       }
+#endif
+
+       for( i=0; i<njob; i++ ) name[i][0] = '=';
+
+       if( disopt )
+       {
+               strcpy( b, name[0] );
+               sprintf( name[0], "=query====lgth=%#04d-%04d %.*s\0", nlen[0], howmanyx( seq[0] ), B-30, b );
+#if 0
+               strins(  b, name[0] );
+#endif
+               for( i=1; i<njob; i++ ) 
+               {       
+                       strcpy( b, name[i] );
+                       sprintf( name[i], "=opt=%#04d=lgth=%#04d-%04d %.*s\0", opt[i], nlen[i], howmanyx( seq[i] ), B-30, b );
+#if 0
+                       strins( b, name[i] );
+#endif
+               }
+       }
+
+       hat2p = fopen( hat2file, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( hat2p, njob, name, mtx2 );
+       fclose( hat2p );
+
+       sprintf( com, "/bin/rm %s %s %s", queryfile, datafile, fastafile );
+       system( com );
+
+#if 0
+       sprintf( com, ALNDIR "/supgsdl < %s\0", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in spgsdl" );
+#endif
+
+       sprintf( com, "mv %s hat2", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in mv" );
+
+       SHOWVERSION;
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/dndfast7.c b/binaries/src/mafft/core/dndfast7.c
new file mode 100644 (file)
index 0000000..fb758b2
--- /dev/null
@@ -0,0 +1,340 @@
+#include "mltaln.h"
+#include <sys/types.h>
+#include <unistd.h>
+#define DEBUG 0
+#define TEST 0
+
+
+int howmanyx( char *s )
+{
+       int val = 0;
+       if( scoremtx == -1 )
+       {
+               do
+               {
+                       if( !strchr( "atgcuATGCU", *s ) ) val++;
+               } while( *++s );
+       }
+       else
+       {
+               do
+               {
+                       if( !strchr( "ARNDCQEGHILKMFPSTWYV", *s ) ) val++;
+               } while( *++s );
+       }
+       return( val );
+}
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+
+       inputfile = NULL;
+       disopt = 0;
+       divpairscore = 0;
+       swopt = "";
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'I':
+                                       disopt = 1;
+                                       break;
+                               case 'A':
+                                       swopt = "-A";
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 )
+    {
+        fprintf( stderr, "options: -i\n" );
+        exit( 1 );
+    }
+}
+
+int main( int argc, char *argv[] )
+{
+       int ktuple;
+       int i, j;
+       FILE *hat2p;
+       FILE *hat3p;
+       FILE *infp;
+       char **seq = NULL; // by D.Mathog
+       char **seq1;
+       static char name[M][B];
+       static char name1[M][B];
+       static int nlen1[M];
+       double **mtx;
+       double **mtx2;
+       static int nlen[M];
+       char b[B];
+       double max;
+       char com[1000];
+       int opt[M];
+       int res;
+       char *home;
+       char *fastapath;
+       char queryfile[B];
+       char datafile[B];
+       char fastafile[B];
+       char hat2file[B];
+       int pid = (int)getpid();
+       LocalHom **localhomtable, *tmpptr;
+#if 0
+       home = getenv( "HOME" );
+#else /* $HOME wo tsukau to fasta ni watasu hikisuu ga afureru */ 
+       home = NULL;
+#endif
+       fastapath = getenv( "FASTA_4_MAFFT" );
+       if( !fastapath ) 
+               fastapath = "fasta34";
+
+#if DEBUG
+       if( home ) fprintf( stderr, "home = %s\n", home );
+#endif
+       if( !home ) home = "";
+       sprintf( queryfile, "%s/tmp/query-%d", home, pid );
+       sprintf( datafile, "%s/tmp/data-%d", home, pid );
+       sprintf( fastafile, "%s/tmp/fasta-%d", home, pid );
+       sprintf( hat2file, "hat2-%d", pid );
+
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       dorp = NOTSPECIFIED;
+       getnumlen( infp );
+#endif
+
+       if( dorp == 'd' )
+       {
+               scoremtx = -1;
+               pamN = NOTSPECIFIED;
+       }
+       else
+       {
+               nblosum = 62;
+               scoremtx = 1;
+       }
+       constants( njob, seq );
+
+       rewind( infp );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       seq1 = AllocateCharMtx( 2, nlenmax+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       mtx2 = AllocateDoubleMtx( njob, njob );
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++)
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1;
+                       localhomtable[i][j].end2 = -1;
+                       localhomtable[i][j].opt = -1.0;
+                       localhomtable[i][j].next = NULL;
+               }
+    }
+
+#if 0
+       FRead( infp, name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       if( scoremtx == -1 ) ktuple = 6;
+       else                 ktuple = 1;
+
+       for( i=0; i<njob; i++ )
+       {
+               gappick0( seq1[0], seq[i] ); 
+               strcpy( seq[i], seq1[0] );
+       }
+       for( j=0; j<njob; j++ )
+       {
+               sprintf( name1[j], "+==========+%d                      ", j );
+               nlen1[j] = nlen[j];
+       }
+       hat2p = fopen( datafile, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open datafile." );
+       WriteForFasta( hat2p, njob, name1, nlen1, seq );
+       fclose( hat2p );
+
+       for( i=0; i<njob; i++ ) 
+       {
+//             fprintf( stderr, "###  i = %d\n", i );
+               hat2p = fopen( datafile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open datafile." );
+               WriteForFasta( hat2p, njob-i, name1+i, nlen1+i, seq+i );
+               fclose( hat2p );
+
+               seq1[0] = seq[i];
+               nlen1[0] = nlen[i];
+
+               hat2p = fopen( queryfile, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open queryfile." );
+               WriteForFasta( hat2p, 1, name1+i, nlen1, seq1 ); 
+               fclose( hat2p );
+
+
+               if( scoremtx == -1 )
+                       sprintf( com, "%s %s -z3 -m10  -n -Q  -b%d -E%d -d%d %s %s %d > %s", fastapath, swopt, M, M, M, queryfile, datafile, ktuple, fastafile );
+               else
+                       sprintf( com, "%s %s -z3 -m10  -Q  -b%d -E%d -d%d %s %s %d > %s", fastapath, swopt, M, M, M, queryfile, datafile, ktuple, fastafile );
+               res = system( com );
+               if( res ) ErrorExit( "error in fasta" );
+
+
+
+               hat2p = fopen( fastafile, "r" );
+               if( hat2p == NULL ) 
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               if( scoremtx == -1 )
+                       res = ReadFasta34m10_nuc( hat2p, mtx[i], i, name1, localhomtable[i] );
+               else
+                       res = ReadFasta34m10( hat2p, mtx[i], i, name1, localhomtable[i] );
+               fclose( hat2p );
+
+               if( res < njob - i )
+               {
+                       fprintf( stderr, "count (fasta34 -z 3) = %d\n", res );
+                       exit( 1 );
+               }
+
+
+               if( i == 0 )
+                       for( j=0; j<njob; j++ ) opt[j] = (int)mtx[0][j];
+
+
+#if 0
+               {
+                       int ii, jj;
+                       if( i < njob-1 ) for( jj=i; jj<i+5; jj++ ) 
+                               fprintf( stdout, "mtx[%d][%d] = %f\n", i+1, jj+1, mtx[i][jj] );
+               }
+#endif
+               fprintf( stderr, "query : %4d / %5d\r", i+1, njob );
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               max = mtx[i][i];
+               if( max == 0.0 )
+               {
+                       for( j=0; j<njob; j++ )
+                               mtx2[i][j] = 2.0;
+               }
+               else
+               {
+                       for( j=0; j<njob; j++ )
+                       {
+//                             fprintf( stderr, "##### mtx[%d][%d] = %f\n", i, j, mtx[i][j] );
+                               mtx2[i][j] = ( max - mtx[MIN(i,j)][MAX(i,j)] ) / max * 2.0;
+//                             fprintf( stdout, "max = %f, mtx[%d][%d] = %f -> %f\n", max, i+1, j+1, mtx[i][j], mtx2[i][j] );
+                       }
+               }
+       }
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
+       {
+//             fprintf( stdout, "mtx2[%d][%d] = %f, %f\n", i+1, j+1, mtx2[i][j], mtx2[j][i] );
+               mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
+       }
+
+#if 0
+       {
+               int ii, jj;
+               if( i < njob-1 ) for( jj=i+1; jj<njob; jj++ ) 
+                       fprintf( stderr, "mtx2[][] = %f\n", mtx2[i][jj] );
+       }
+#endif
+
+       for( i=0; i<njob; i++ ) name[i][0] = '=';
+
+       if( disopt )
+       {
+               strcpy( b, name[0] );
+               sprintf( name[0], "=query====lgth=%04d-%04d %.*s", nlen[0], howmanyx( seq[0] ), B-30, b );
+#if 0
+               strins(  b, name[0] );
+#endif
+               for( i=1; i<njob; i++ ) 
+               {       
+                       strcpy( b, name[i] );
+                       sprintf( name[i], "=opt=%04d=lgth=%04d-%04d %.*s", opt[i], nlen[i], howmanyx( seq[i] ), B-30, b );
+#if 0
+                       strins( b, name[i] );
+#endif
+               }
+       }
+
+       hat2p = fopen( hat2file, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( hat2p, njob, name, mtx2 );
+       fclose( hat2p );
+
+#if 1
+       fprintf( stderr, "##### writing hat3\n" );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
+       {
+               for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+               {
+                       if( tmpptr->opt == -1.0 ) continue;
+                       fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next );
+               }
+       }
+       fclose( hat3p );
+#endif
+
+       sprintf( com, "/bin/rm %s %s %s", queryfile, datafile, fastafile );
+       system( com );
+
+#if 0
+       sprintf( com, ALNDIR "/supgsdl < %s", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in spgsdl" );
+#endif
+
+       sprintf( com, "mv %s hat2", hat2file );
+       res = system( com );
+       if( res ) ErrorExit( "error in mv" );
+
+       SHOWVERSION;
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/dndpre.c b/binaries/src/mafft/core/dndpre.c
new file mode 100644 (file)
index 0000000..c0be891
--- /dev/null
@@ -0,0 +1,277 @@
+#include "mltaln.h"
+
+#define TEST 0
+
+static int treeout = 0;
+
+#ifdef enablemultithread
+typedef struct _jobtable
+{
+    int i;  
+    int j;  
+} Jobtable;
+
+typedef struct _thread_arg
+{
+       int njob;
+       int thread_no;
+       float *selfscore;
+       double **mtx;
+       char **seq;
+       Jobtable *jobpospt;
+       pthread_mutex_t *mutex;
+} thread_arg_t;
+
+void *athread( void *arg )
+{
+       thread_arg_t *targ = (thread_arg_t *)arg;
+       int njob = targ->njob;
+       int thread_no = targ->thread_no;
+       float *selfscore = targ->selfscore;
+       double **mtx = targ->mtx;
+       char **seq = targ->seq;
+       Jobtable *jobpospt = targ->jobpospt;
+
+       int i, j;
+       float ssi, ssj, bunbo;
+       
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               j = jobpospt->j;
+               i = jobpospt->i;
+               j++;
+               if( j == njob )
+               {
+                       fprintf( stderr, "%4d/%4d (thread %4d), dndpre\r", i+1, njob, thread_no );
+                       i++;
+                       j = i + 1;
+                       if( i == njob-1 )
+                       {
+                               pthread_mutex_unlock( targ->mutex );
+                               return( NULL );
+                       }
+               }
+               jobpospt->j = j;
+               jobpospt->i = i;
+               pthread_mutex_unlock( targ->mutex );
+
+               ssi = selfscore[i];
+               ssj = selfscore[j];
+
+               bunbo = MIN( ssi, ssj );
+               if( bunbo == 0.0 )
+                       mtx[i][j] = 1.0;
+               else
+                       mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
+       }
+}
+
+#endif
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nthread = 1;
+       alg = 'X';
+       fmodel = 0;
+       treeout = 0;
+       scoremtx = 1;
+       nblosum = 62;
+       dorp = NOTSPECIFIED;
+       inputfile = NULL;
+       ppenalty = NOTSPECIFIED; //?
+       ppenalty_ex = NOTSPECIFIED; //?
+       poffset = NOTSPECIFIED; //?
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 't':
+                                       treeout = '1';
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+       {
+               fprintf( stderr, "options: Check source file !\n" );
+               exit( 1 );
+       }
+}
+
+int main( int argc, char **argv )
+{
+       int i, j;
+       char **seq;
+       static char **name;
+       static int nlen[M];
+       float *selfscore;
+       double **mtx;
+       FILE *fp;
+       FILE *infp;
+       float ssi, ssj, bunbo;
+
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( infp );
+#endif
+       rewind( infp );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       name = AllocateCharMtx( njob, B+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       selfscore = AllocateFloatVec( njob );
+
+#if 0
+       FRead( stdin, name, nlen, seq );
+#else
+       readData_pointer( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       constants( njob, seq );
+
+#if 0
+       for( i=0; i<njob-1; i++ ) 
+       {
+               fprintf( stderr, "%4d/%4d\r", i+1, njob );
+               for( j=i+1; j<njob; j++ ) 
+                       mtx[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+//                     fprintf( stderr, "i=%d,j=%d, l=%d &&&  %f\n", i, j, nlen[0], mtx[i][j] );
+       }
+#else // 061003
+       for( i=0; i<njob; i++ )
+       {
+               selfscore[i] = (float)naivepairscore11( seq[i], seq[i], penalty );
+
+       }
+#ifdef enablemultithread
+       if( nthread > 0 )
+       {
+               thread_arg_t *targ;
+               Jobtable jobpos;
+               pthread_t *handle;
+               pthread_mutex_t mutex;
+
+               jobpos.i = 0;
+               jobpos.j = 0;
+
+               targ = calloc( nthread, sizeof( thread_arg_t ) );
+               handle = calloc( nthread, sizeof( pthread_t ) );
+               pthread_mutex_init( &mutex, NULL );
+
+               for( i=0; i<nthread; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].njob = njob;
+                       targ[i].selfscore = selfscore;
+                       targ[i].mtx = mtx;
+                       targ[i].seq = seq;
+                       targ[i].jobpospt = &jobpos;
+                       targ[i].mutex = &mutex;
+
+                       pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
+               }
+
+               for( i=0; i<nthread; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+               pthread_mutex_destroy( &mutex );
+       }
+       else
+#endif
+       {
+               for( i=0; i<njob-1; i++ )
+               {
+                       ssi = selfscore[i];
+                       fprintf( stderr, "%4d/%4d\r", i+1, njob );
+                       for( j=i+1; j<njob; j++ )
+                       {
+                               ssj = selfscore[j];
+                               bunbo = MIN( ssi, ssj );
+                               if( bunbo == 0.0 )
+                                       mtx[i][j] = 1.0;
+                               else
+                                       mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
+//                                     mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] );
+//                             fprintf( stderr, "i=%d,j=%d, l=%d### %f, score = %d\n", i, j, nlen[0], mtx[i][j], naivepairscore11( seq[i], seq[j], penalty )  );
+                       }
+               }
+       }
+#endif
+       
+#if TEST
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+               fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
+#endif
+
+       fp = fopen( "hat2", "w" );
+       WriteHat2_pointer( fp, njob, name, mtx );
+       fclose( fp );
+#if 0
+       if( treeout )
+       {
+               int ***topol;
+               double **len;
+
+               topol = AllocateIntCub( njob, 2, njob );
+               len = AllocateDoubleMtx( njob, njob );
+               veryfastsupg_double_outtree( njob, mtx, topol, len );
+       }
+#endif
+       SHOWVERSION;
+       exit( 0 );
+/*
+       res = system( ALNDIR "/spgsdl < hat2"  );
+       if( res ) exit( 1 );
+       else exit( 0 );
+*/
+}
diff --git a/binaries/src/mafft/core/dndpre2.c b/binaries/src/mafft/core/dndpre2.c
new file mode 100644 (file)
index 0000000..e68a3c3
--- /dev/null
@@ -0,0 +1,176 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 1
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       scoremtx = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       fmodel = 1;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char name[M][B], **seq;
+       int i, j, alloclen, c;
+       double **mtx;
+       double *self;
+       double tmpdouble;
+       FILE *fp;
+
+       arguments( argc, argv );
+
+       getnumlen( stdin );
+       rewind( stdin );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       self = AllocateDoubleVec( njob );
+       alloclen = nlenmax*9;
+
+       readData( stdin, name, nlen, seq );
+       constants( njob, seq );
+
+
+
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+       for( i=0; i<njob; i++ ) 
+       {
+               self[i] = (double)substitution_nid( seq[i], seq[i] );
+//             fprintf( stdout, "self[%d] = %f\n", i, self[i] );
+       }
+
+       for( i=0; i<njob-1; i++ ) 
+               for( j=i+1; j<njob; j++ ) 
+               {
+                       tmpdouble = (double)substitution_score( seq[i], seq[j] );
+//                     fprintf( stdout, "tmpdouble = %f\n", tmpdouble );
+                       mtx[i][j] = ( 1.0 - tmpdouble / MIN( self[i], self[j] ) );
+                       if( mtx[i][j] < 0.95 )
+                               mtx[i][j] = - log( 1.0 - mtx[i][j] );
+                       else
+                               mtx[i][j] = 3.0;
+               }
+       
+#if TEST
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+               fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
+#endif
+
+       fp = fopen( "hat2", "w" );
+       WriteHat2( fp, njob, name, mtx );
+       fclose( fp );
+       exit( 0 );
+
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/dndpre_score.c b/binaries/src/mafft/core/dndpre_score.c
new file mode 100644 (file)
index 0000000..a911d0a
--- /dev/null
@@ -0,0 +1,54 @@
+#include "mltaln.h"
+
+#define TEST 0
+
+int main()
+{
+       int i, j;
+       char **seq;
+       static char name[M][B];
+       static int nlen[M];
+       double **mtx;
+       FILE *fp;
+       int res;
+
+       scoremtx = NOTSPECIFIED;
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( stdin );
+#endif
+       rewind( stdin );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+
+#if 0
+       FRead( stdin, name, nlen, seq );
+#else
+       readData( stdin, name, nlen, seq );
+#endif
+
+       for( i=0; i<njob-1; i++ ) 
+       {
+               fprintf( stderr, "%4d/%4d\r", i+1, njob );
+               for( j=i+1; j<njob; j++ ) 
+                       mtx[i][j] = (double)substitution_score( seq[i], seq[j] );
+       }
+       
+#if TEST
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+               fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
+#endif
+
+       fp = fopen( "hat2", "w" );
+       WriteHat2( fp, njob, name, mtx );
+       fclose( fp );
+       exit( 0 );
+/*
+       res = system( ALNDIR "/spgsdl < hat2"  );
+       if( res ) exit( 1 );
+       else exit( 0 );
+*/
+}
diff --git a/binaries/src/mafft/core/dp.h b/binaries/src/mafft/core/dp.h
new file mode 100644 (file)
index 0000000..3b27820
--- /dev/null
@@ -0,0 +1,10 @@
+#ifdef enablemultithread
+#define TLS __thread
+#else
+#define TLS 
+#endif
+
+extern TLS int commonAlloc1;
+extern TLS int commonAlloc2;
+extern TLS int **commonIP;
+extern TLS int **commonJP;
diff --git a/binaries/src/mafft/core/dvtditr.c b/binaries/src/mafft/core/dvtditr.c
new file mode 100644 (file)
index 0000000..54b44c6
--- /dev/null
@@ -0,0 +1,711 @@
+ /* Tree-dependent-iteration */
+ /* Devide to segments       */ 
+
+#include "mltaln.h"
+
+extern char **seq_g;
+extern char **res_g;
+
+static int intop;
+static int intree;
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+       char *argkey;
+
+       outnumber = 0;
+       nthread = 1;
+       randomseed = 0;
+       scoreout = 0;
+       parallelizationstrategy = BAATARI1;
+       intop = 0;
+       intree = 0;
+       inputfile = NULL;
+       rnakozo = 0;
+       rnaprediction = 'm';
+       nevermemsave = 0;
+       score_check = 1;
+       fftkeika = 1;
+       constraint = 0;
+       fmodel = 0;
+       kobetsubunkatsu = 1;
+       bunkatsu = 1;
+       nblosum = 62;
+       niter = 100;
+       calledByXced = 0;
+       devide = 1;
+       divWinSize = 20; /* 70 */
+       divThreshold = 65;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    scmtd = 5;
+       cooling = 1;
+    weight = 4;
+    utree = 1;
+    refine = 1;
+    check = 1;
+    cut = 0.0;
+       disp = 0;
+       outgap = 1;
+       use_fft = 0; // CHUUI dochira demo mafft.tmpl deha F
+       force_fft = 0;
+       alg = 'A';  /* chuui */
+       mix = 0;
+       checkC = 0;
+       tbitr = 0;
+       treemethod = 'X';
+       scoremtx = 1;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNAppenalty_ex = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+       TMorJTT = JTT;
+       consweight_multi = 1.0;
+       consweight_rna = 0.0;
+
+       while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+               while ( (c = *++argv[0]) )
+               {
+                       switch( c )
+                       {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'I':
+                                       niter = atoi( *++argv );
+                                       fprintf( stderr, "niter = %d\n", niter );
+                                       --argc;
+                                       goto nextoption;
+                               case 'e':
+                                       RNApthr = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'o':
+                                       RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kappa = %d\n", kimuraR );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d / kimura 200\n", nblosum );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt/kimura %d\n", pamN );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "tm %d\n", pamN );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'l':
+                                       fastathreshold = atof( *++argv );
+                                       constraint = 2;
+                                       --argc;
+                                       goto nextoption;
+                               case 'r':
+                                       consweight_rna = atof( *++argv );
+                                       rnakozo = 1;
+                                       --argc;
+                                       goto nextoption;
+                               case 'c':
+                                       consweight_multi = atof( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+                               case 't':
+                                       randomseed = atoi( *++argv );
+                                       fprintf( stderr, "randomseed = %d\n", randomseed );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'p':
+                                       argkey = *++argv;
+                                       if( !strcmp( argkey, "BESTFIRST" ) ) parallelizationstrategy = BESTFIRST;
+                                       else if( !strcmp( argkey, "BAATARI0" ) ) parallelizationstrategy = BAATARI0;
+                                       else if( !strcmp( argkey, "BAATARI1" ) ) parallelizationstrategy = BAATARI1;
+                                       else if( !strcmp( argkey, "BAATARI2" ) ) parallelizationstrategy = BAATARI2;
+                                       else
+                                       {
+                                               fprintf( stderr, "Unknown parallelization strategy, %s\n", argkey );
+                                               exit( 1 );
+                                       }
+//                                     exit( 1 );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'S' :
+                                       scoreout = 1;
+                                       break;
+                               case 's' :
+                                       RNAscoremtx = 'r';
+                                       break;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'N':
+                                       nevermemsave = 1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'Q':
+                                       alg = 'Q';
+                                       break;
+                               case 'R':
+                                       rnaprediction = 'r';
+                                       break;
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#if 0
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+#endif
+                               case 'T':
+                                       kobetsubunkatsu = 0;
+                                       break;
+                               case 'B':
+                                       bunkatsu = 0;
+                                       break;
+#if 0
+                               case 'c':
+                                       cooling = 1;
+                                       break;
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+                               case 's' :
+                                       treemethod = 's';
+                                       break;
+#endif
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+#if 0
+                               case 't':
+                                       weight = 4;
+                                       break;
+#endif
+                               case 'u':
+                                       weight = 0;
+                                       break;
+                               case 'U':
+                                       intree = 1;
+                                       break;
+                               case 'V':
+                                       intop = 1;
+                                       break;
+                               case 'J':
+                                       utree = 0;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+                               case 'Z':
+                                       score_check = 0;
+                                       break;
+                               case 'Y':
+                                       score_check = 2;
+                                       break;
+#if 0
+                               case 'n' :
+                                       treemethod = 'n';
+                                       break;
+#endif
+                               case 'n' :
+                                       outnumber = 1;
+                                       break;
+                               case 'X' :
+                                       treemethod = 'X';
+                                       break;
+                               case 'E' :
+                                       treemethod = 'E';
+                                       break;
+                               case 'q' :
+                                       treemethod = 'q';
+                                       break;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               default:
+                                       fprintf( stderr, "illegal option %c\n", c );
+                                       argc = 0;
+                                       break;
+                       }
+               }
+               nextoption:
+                       ;
+       }
+       if( argc == 1 )
+       {
+               cut = atof( (*argv) );
+               argc--;
+       }
+       if( argc != 0 ) 
+       {
+               fprintf( stderr, "options : Check source file!\n" );
+               exit( 1 );
+       }
+#if 0
+       if( alg == 'A' && weight == 0 ) 
+               ErrorExit( "ERROR : Algorithm A+ and un-weighted\n" ); 
+#endif
+}
+
+
+int main( int argc, char *argv[] )
+{
+    int identity;
+       static int nlen[M];
+       static char **name, **seq, **aseq, **bseq;
+       static Segment *segment = NULL;
+       static int anchors[MAXSEG];
+       int i, j;
+       int iseg, nseg;
+       int ***topol;
+       double **len;
+       double **eff;
+       FILE *prep;
+       FILE *infp;
+       int alloclen;
+       int returnvalue;
+       char c;
+       int ocut;
+       char **seq_g_bk;
+       LocalHom **localhomtable = NULL; // by D.Mathog
+       RNApair ***singlerna;
+       int nogaplen;
+       static char **nogap1seq;
+       static char *kozoarivec;
+       int nkozo;
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp ) 
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else    
+               infp = stdin;
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( infp );
+#endif
+       rewind( infp );
+
+       nkozo = 0;
+
+       if( njob < 2 ) 
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       ocut = cut;
+
+       segment = (Segment *)calloc( MAXSEG, sizeof( Segment ) );
+//     if( treemethod == 'X' || treemethod == 'E' || treemethod == 'q' )
+       topol = AllocateIntCub( njob, 2, njob );
+       len = AllocateDoubleMtx( njob, 2 );
+       eff = AllocateDoubleMtx( njob, njob );
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       name = AllocateCharMtx( njob, B+1 );
+       seq_g = AllocateCharMtx( njob, nlenmax*9+1 );
+       res_g = AllocateCharMtx( njob, nlenmax*9+1 );
+       aseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       nogap1seq = AllocateCharMtx( 1, nlenmax*1+1 );
+       alloclen = nlenmax * 9;
+       seq_g_bk = AllocateCharMtx( njob, 0 );
+       for( i=0; i<njob; i++ ) seq_g_bk[i] = seq_g[i];
+       kozoarivec = AllocateCharVec( njob );
+
+       if( constraint )
+       {
+               localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+               for( i=0; i<njob; i++)
+               {
+                       localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+                       for( j=0; j<njob; j++)
+                       {
+                               localhomtable[i][j].start1 = -1;
+                               localhomtable[i][j].end1 = -1;
+                               localhomtable[i][j].start2 = -1;
+                               localhomtable[i][j].end2 = -1;
+                               localhomtable[i][j].overlapaa = -1.0; 
+                               localhomtable[i][j].opt = -1.0;
+                               localhomtable[i][j].importance = -1.0; 
+                               localhomtable[i][j].next = NULL; 
+                               localhomtable[i][j].nokori = 0;
+                               localhomtable[i][j].extended = -1;
+                               localhomtable[i][j].last = localhomtable[i]+j;
+                               localhomtable[i][j].korh = 'h';
+                       }
+               }
+               fprintf( stderr, "Loading 'hat3' ... " );
+               fflush( stderr );
+               prep = fopen( "hat3", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat3." );
+               readlocalhomtable2( prep, njob, localhomtable, kozoarivec );
+               fclose( prep ); 
+//             for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ )
+//                     fprintf( stdout, "%d %d %d %d %d %d %d\n", i, j, localhomtable[i][j].opt, localhomtable[i][j].start1, localhomtable[i][j].end1, localhomtable[i][j].start2, localhomtable[i][j].end2 );
+               fprintf( stderr, "done.\n" );
+               fflush( stderr );
+#if 0
+               fprintf( stderr, "Extending localhom ... " );
+               extendlocalhom( njob, localhomtable );
+               fprintf( stderr, "done.\n" );
+#endif
+               nkozo = 0;
+               for( i=0; i<njob; i++ ) if( kozoarivec[i] ) nkozo++;
+       }
+
+
+//             if( nlenmax > 30000 )
+               if( nlenmax > 50000 ) // version >= 6.823
+               {
+#if 0
+                       if( constraint )
+                       {
+                               fprintf( stderr, "\nnlenmax=%d, nagasugi!\n", nlenmax ); 
+                               exit( 1 );
+                       }
+                       if( nevermemsave )
+                       {
+                               fprintf( stderr, "\nnevermemsave=1, nlenmax=%d, nagasugi!\n", nlenmax ); 
+                               exit( 1 );
+                       }
+#endif
+                       if( !constraint && !nevermemsave && alg != 'M' )
+                       {
+                               fprintf( stderr, "\nnlenmax=%d, Switching to the memsave mode\n", nlenmax ); 
+                               alg = 'M';
+                       }
+               }
+
+#if 0
+       Read( name, nlen, seq_g );
+#else
+       readData_pointer( infp, name, nlen, seq_g );
+#endif
+       fclose( infp );
+
+
+       for( i=0; i<njob; i++ )
+       {
+               res_g[i][0] = 0;
+       }
+
+       identity = 1;
+       for( i=0; i<njob; i++ ) 
+       {
+               identity *= ( nlen[i] == nlen[0] );
+       }
+       if( !identity ) 
+       {
+               fprintf( stderr, "Input pre-aligned data\n" );
+               exit( 1 );
+       }
+       constants( njob, seq_g );
+
+#if 0
+       fprintf( stderr, "penalty = %d\n", penalty ); 
+       fprintf( stderr, "penalty_ex = %d\n", penalty_ex ); 
+       fprintf( stderr, "offset = %d\n", offset ); 
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+#if 0
+       if( njob == 2 )
+       {
+               writePre( njob, name, nlen, seq_g, 1 );
+               SHOWVERSION;
+               return( 0 );
+       }
+#else
+       if( njob == 2 )
+       {
+               weight = 0;
+               niter = 1;
+       }
+#endif
+
+       c = seqcheck( seq_g );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+       commongappick( njob, seq_g );
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               singlerna = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               prep = fopen( "hat4", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat4 using mccaskill." );
+               fprintf( stderr, "Loading 'hat4' ... " );
+               fflush( stderr );
+               for( i=0; i<njob; i++ )
+               {
+                       gappick0( nogap1seq[0], seq_g[i] );
+                       nogaplen = strlen( nogap1seq[0] );
+                       singlerna[i] = (RNApair **)calloc( nogaplen, sizeof( RNApair * ) );
+                       for( j=0; j<nogaplen; j++ )
+                       {
+                               singlerna[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+                               singlerna[i][j][0].bestpos = -1;
+                               singlerna[i][j][0].bestscore = -1.0;
+                       }
+                       readmccaskill( prep, singlerna[i], nogaplen );
+               }
+               fclose( prep );
+               fprintf( stderr, "\ndone.\n" );
+               fflush( stderr );
+       }
+       else
+               singlerna = NULL;
+
+
+
+       if( utree )
+       {
+               prep = fopen( "hat2", "r" );
+               if( !prep ) ErrorExit( "Make hat2." );
+               readhat2_pointer( prep, njob, name, eff );
+               fclose( prep );
+#if DEBUG
+               for( i=0; i<njob-1; i++ ) 
+               {
+                       for( j=i+1; j<njob; j++ ) 
+                       {
+                               printf( " %f", eff[i][j] );
+                       }
+                       printf( "\n" );
+               }
+#endif
+               if( intree )
+                       veryfastsupg_double_loadtree( njob, eff, topol, len );
+               else if( intop ) // v6.528 deha if( intop ) dattanode intree ga mukou datta.
+                       veryfastsupg_double_loadtop( njob, eff, topol, len );
+               else if( treemethod == 'X' || treemethod == 'E' || treemethod == 'q' ) 
+//                     veryfastsupg_double_outtree( njob, eff, topol, len, name );
+                       fixed_musclesupg_double_treeout( njob, eff, topol, len, name );
+               else if( treemethod == 'n' ) 
+                       nj( njob, eff, topol, len );
+               else if( treemethod == 's' )
+                       spg( njob, eff, topol, len );
+               else if( treemethod == 'p' )
+                       upg2( njob, eff, topol, len );
+               else ErrorExit( "Incorrect treemethod.\n" );
+       }
+#if DEBUG
+       printf( "utree = %d\n", utree );
+#endif
+
+
+       fprintf( stderr, "\n" );
+       if( ( !utree && kobetsubunkatsu ) || constraint || !bunkatsu )
+       {
+               nseg = 0;
+               anchors[0] =0;
+               anchors[1] =strlen( seq_g[0] );
+               nseg += 2;
+       }
+       else
+       {
+               nseg = searchAnchors( njob, seq_g, segment );
+#if 0
+               fprintf( stderr, "### nseg = %d\n", nseg );
+               fprintf( stderr, "### seq_g[0] = %s\n", seq_g[0] );
+               fprintf( stderr, "### nlenmax = %d\n", nlenmax );
+               fprintf( stderr, "### len = %d\n", strlen( seq_g[0] ) );
+
+#endif
+
+               anchors[0] = 0;
+               for( i=0; i<nseg; i++ ) anchors[i+1] = segment[i].center;
+               anchors[nseg+1] = strlen( seq_g[0] );
+               nseg +=2;
+
+#if 0
+               for( i=0; i<nseg; i++ )
+                       fprintf( stderr, "anchor[%d] = %d\n", i, anchors[i] );
+#endif
+       }
+
+       for( i=0; i<njob; i++ ) res_g[i][0] = 0;
+
+       for( iseg=0; iseg<nseg-1; iseg++ )
+       {
+               int tmplen = anchors[iseg+1]-anchors[iseg];
+               int pos = strlen( res_g[0] );
+               for( j=0; j<njob; j++ )
+               {
+                       strncpy( seq[j], seq_g[j], tmplen );
+                       seq[j][tmplen]= 0;
+                       seq_g[j] += tmplen;     
+
+               }
+               fprintf( stderr, "Segment %3d/%3d %4d-%4d\n", iseg+1, nseg-1, pos+1, pos+1+tmplen );
+               fflush( stderr );
+               fprintf( trap_g, "Segment %3d/%3d %4d-%4d\n", iseg+1, nseg-1, pos+1, pos+1+tmplen );
+       
+               cut = ocut;
+               returnvalue = TreeDependentIteration( njob, name, nlen, seq, bseq, topol, len, alloclen, localhomtable, singlerna, nkozo, kozoarivec );
+
+               for( i=0; i<njob; i++ )
+                       strcat( res_g[i], bseq[i] );
+       }
+       FreeCharMtx( seq_g_bk );
+       FreeIntCub( topol );
+       FreeDoubleMtx( len );
+       FreeDoubleMtx( eff );
+       if( constraint ) FreeLocalHomTable( localhomtable, njob );
+
+#if 0
+       Write( stdout, njob, name, nlen, bseq );
+#endif
+
+       fprintf( stderr, "done\n" );
+       fprintf( trap_g, "done\n" );
+       fclose( trap_g );
+
+
+       devide = 0; 
+       writePre( njob, name, nlen, res_g, 1 );
+#if 0
+       writeData( stdout, njob, name, nlen, res_g, 1 );
+#endif
+
+
+       SHOWVERSION;
+       return( 0 );
+}
+
+#if 0
+signed int main( int argc, char *argv[] )
+{
+       int i, nlen[M];
+       char b[B];
+       char a[] = "=";
+       int value;
+
+       gets( b ); njob = atoi( b );
+
+/*
+       scoremtx = 0;
+       if( strstr( b, "ayhoff" ) ) scoremtx = 1;
+       else if( strstr( b, "dna" ) || strstr( b, "DNA" ) ) scoremtx = -1;
+       else if( strstr( b, "M-Y" ) || strstr( b, "iyata" ) ) scoremtx = 2;
+       else scoremtx = 0;
+*/
+       if( strstr( b, "constraint" ) ) cnst = 1;
+
+       nlenmax = 0;
+       i = 0;
+       while( i<njob )
+       {
+               gets( b );
+               if( !strncmp( b, a, 1 ) ) 
+               {
+                       gets( b ); nlen[i] = atoi( b );
+                       if( nlen[i] > nlenmax ) nlenmax = nlen[i];
+                       i++;
+               }
+       }
+       if( nlenmax > N || njob > M ) 
+       {
+               fprintf( stderr, "ERROR in main\n" );
+               exit( 1 );
+       }
+       /*
+       nlenmax = Na;
+       */
+       rewind( stdin );
+       value = main1( nlen, argc, argv );
+       exit( 0 );
+}
+#endif
diff --git a/binaries/src/mafft/core/f2cl.c b/binaries/src/mafft/core/f2cl.c
new file mode 100644 (file)
index 0000000..d8c9f2c
--- /dev/null
@@ -0,0 +1,273 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+
+static char *comment;
+static char *orderfile;
+static int format;
+static int namelen;
+
+static void fillspace( char *seq, int lenmax )
+{
+       int len = strlen( seq );
+       seq += len;
+       lenmax -= len;
+       while( lenmax-- ) *seq++ = ' ';
+       *seq = 0;
+}
+
+void setmark_clustal( int nlen, int nseq, char **seq, char *mark )
+{
+       int i, j, k;
+
+       char *strong[] = { 
+                                       "STA",
+                                       "NEQK",
+                                       "NHQK",
+                                       "NDEQ",
+                                       "QHRK",
+                                       "MILV",
+                                       "MILF",
+                                       "HY",
+                                       "FYW",
+                                 };
+       int nstrong = 9;
+       char *weaker[] = { 
+                                       "CSA",
+                                       "ATV",
+                                       "SAG",
+                                       "STNK",
+                                       "STPA",
+                                       "SGND",
+                                       "SNDEQK",
+                                       "NDEQHK",
+                                       "NEQHRK",
+                                       "FVLIM",
+                                       "HFY",
+                                 };
+       int nweaker = 11;
+
+       for( i=0; i<nlen; i++ )
+       {
+               mark[i] = ' ';
+               for( j=0; j<nseq; j++ )
+                       if( '-' == seq[j][i] ) break;
+               if( j != nseq ) 
+               {
+                       continue;
+               }
+               for( j=0; j<nseq; j++ )
+                       if( toupper( seq[0][i] ) != toupper( seq[j][i] ) ) break;
+               if( j == nseq ) 
+               {
+                       mark[i] = '*';
+                       continue;
+               }
+               for( k=0; k<nstrong; k++ )
+               {
+                       for( j=0; j<nseq; j++ )
+                       {
+                               if( !strchr( strong[k], toupper( seq[j][i] ) ) ) break;
+                       }
+                       if( j == nseq ) break;
+               }
+               if( k < nstrong )
+               {
+                       mark[i] = ':';
+                       continue;
+               }
+               for( k=0; k<nweaker; k++ )
+               {
+                       for( j=0; j<nseq; j++ )
+                       {
+                               if( !strchr( weaker[k], toupper( seq[j][i] ) ) ) break;
+                       }
+                       if( j == nseq ) break;
+               }
+               if( k < nweaker )
+               {
+                       mark[i] = '.';
+                       continue;
+               }
+       }
+       mark[nlen] = 0;
+}
+
+void setmark( int nlen, int nseq, char **seq, char *mark )
+{
+       int i, j;
+
+       for( i=0; i<nlen; i++ )
+       {
+               mark[i] = ' ';
+               for( j=0; j<nseq; j++ )
+                       if( '-' == seq[j][i] ) break;
+               if( j != nseq ) 
+               {
+                       continue;
+               }
+               for( j=0; j<nseq; j++ )
+                       if( seq[0][i] != seq[j][i] ) break;
+               if( j == nseq ) 
+               {
+                       mark[i] = '*';
+                       continue;
+               }
+               for( j=0; j<nseq; j++ )
+                       if( amino_grp[(int)seq[0][i]] != amino_grp[(int)seq[j][i]] ) break;
+               if( j == nseq ) 
+               {
+                       mark[i] = '.';
+                       continue;
+               }
+       }
+       mark[nlen] = 0;
+}
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+       namelen = 15;
+       scoremtx = 1;
+       nblosum = 62;
+       dorp = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       inputfile = NULL;
+       comment = NULL;
+       orderfile = NULL;
+       format = 'c';
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'c':
+                                       comment = *++argv;
+                                       fprintf( stderr, "comment = %s\n", comment );
+                                       --argc;
+                                       goto nextoption;
+                               case 'r':
+                                       orderfile = *++argv;
+                                       fprintf( stderr, "orderfile = %s\n", orderfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'n':
+                                       namelen = atoi( *++argv );
+                                       fprintf( stderr, "namelen = %d\n", namelen );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       format = 'f';
+                                       break;
+                               case 'y':
+                                       format = 'y';
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+int main( int argc, char *argv[] )
+{
+       static int  *nlen;      
+       static char **name, **seq, *mark;
+       static int *order;
+       int i;
+       FILE *infp;
+       FILE *orderfp;
+       char gett[B];
+       int nlenmin;
+
+       arguments( argc, argv );
+
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen_casepreserve( infp, &nlenmin );
+       rewind( infp );
+
+       seq = AllocateCharMtx( njob, nlenmax*2+1 );
+       mark = AllocateCharVec( nlenmax*2+1 );
+       order = AllocateIntVec( njob );
+       name = AllocateCharMtx( njob, B+1 );
+    nlen = AllocateIntVec( njob );
+
+
+       if( orderfile )
+       {
+               orderfp = fopen( orderfile, "r" );
+               if( !orderfile )
+               {
+                       fprintf( stderr, "Cannot open %s\n", orderfile );
+                       exit( 1 );
+               }
+               for( i=0; i<njob; i++ )
+               {
+                       fgets( gett, B-1, orderfp );
+                       order[i] = atoi( gett );
+               }
+               fclose( orderfp );
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) order[i] = i;
+       }
+
+       readData_pointer_casepreserve( infp, name, nlen, seq );
+       fclose( infp );
+
+       if( format == 'c' || format == 'y' ) for( i=0; i<njob; i++ ) fillspace( seq[i], nlenmax );
+       constants( njob, seq );
+
+//     initSignalSM();
+
+//     initFiles();
+
+
+
+//     setmark( nlenmax, njob, seq, mark );
+       setmark_clustal( nlenmax, njob, seq, mark );
+
+       if( format == 'f' )
+               writeData_reorder_pointer( stdout, njob, name, nlen, seq, order );
+       else if( format == 'c' )
+               clustalout_pointer( stdout, njob, nlenmax, seq, name, mark, comment, order, namelen );
+       else if( format == 'y' )
+               phylipout_pointer( stdout, njob, nlenmax, seq, name, order );
+       else
+               fprintf( stderr, "Unknown format\n" );
+
+//     SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/fft.c b/binaries/src/mafft/core/fft.c
new file mode 100644 (file)
index 0000000..c217cb7
--- /dev/null
@@ -0,0 +1,125 @@
+#include "mltaln.h"
+#include "mtxutl.h"
+
+/*
+  from "C gengo niyoru saishin algorithm jiten" ISBN4-87408-414-1 Haruhiko Okumura
+*/
+static void make_sintbl(int n, float sintbl[])
+{
+        int i, n2, n4, n8;
+        double c, s, dc, ds, t;
+
+        n2 = n / 2;  n4 = n / 4;  n8 = n / 8;
+        t = sin(PI / n);
+        dc = 2 * t * t;  ds = sqrt(dc * (2 - dc));
+        t = 2 * dc;  c = sintbl[n4] = 1;  s = sintbl[0] = 0;
+        for (i = 1; i < n8; i++) {
+                c -= dc;  dc += t * c;
+                s += ds;  ds -= t * s;
+                sintbl[i] = s;  sintbl[n4 - i] = c;
+        }
+        if (n8 != 0) sintbl[n8] = sqrt(0.5);
+        for (i = 0; i < n4; i++)
+                sintbl[n2 - i] = sintbl[i];
+        for (i = 0; i < n2 + n4; i++)
+                sintbl[i + n2] = - sintbl[i];
+}
+/*
+  {\tt fft()}.
+*/
+static void make_bitrev(int n, int bitrev[])
+{
+        int i, j, k, n2;
+
+        n2 = n / 2;  i = j = 0;
+        for ( ; ; ) {
+                bitrev[i] = j;
+                if (++i >= n) break;
+                k = n2;
+                while (k <= j) {  j -= k;  k /= 2;  }
+                j += k;
+        }
+}
+/*
+*/
+int fft(int n, Fukusosuu *x, int freeflag)
+{
+        static TLS int    last_n = 0;    /*  {\tt n} */
+        static TLS int   *bitrev = NULL; /*  */
+        static TLS float *sintbl = NULL; /*  */
+        int i, j, k, ik, h, d, k2, n4, inverse;
+        float t, s, c, dR, dI;
+
+               if (freeflag)
+               {
+                       if (bitrev) free(bitrev);
+                       if (sintbl) free(sintbl);
+                       return( 0 );
+               }
+
+        /*  */
+        if (n < 0) {
+                n = -n;  inverse = 1;  /*  */
+        } else inverse = 0;
+        n4 = n / 4;
+        if (n != last_n || n == 0) {
+                last_n = n;
+#if 0
+                if (sintbl != NULL) {
+                                       free(sintbl);
+                                       sintbl = NULL;
+                               }
+                if (bitrev != NULL) {
+                                       free(bitrev);
+                                       bitrev = NULL;
+                               }
+                if (n == 0) return 0;  /*  */
+                sintbl = (float *)malloc((n + n4) * sizeof(float));
+                bitrev = (int *)malloc(n * sizeof(int));
+#else /* by T. Nishiyama */
+                               sintbl = realloc(sintbl, (n + n4) * sizeof(float));
+                               bitrev = realloc(bitrev, n * sizeof(int));
+#endif
+                if (sintbl == NULL || bitrev == NULL) {
+                        fprintf(stderr, "\n");  return 1;
+                }
+                make_sintbl(n, sintbl);
+                make_bitrev(n, bitrev);
+        }
+        for (i = 0; i < n; i++) {    /*  */
+                j = bitrev[i];
+                if (i < j) {
+                        t = x[i].R;  x[i].R = x[j].R;  x[j].R = t;
+                        t = x[i].I;  x[i].I = x[j].I;  x[j].I = t;
+                }
+        }
+        for (k = 1; k < n; k = k2) {    /*  */
+#if 0
+                               fprintf( stderr, "%d / %d\n", k, n );
+#endif
+                h = 0;  k2 = k + k;  d = n / k2;
+                for (j = 0; j < k; j++) {
+#if 0
+                                       if( j % 1 == 0 )
+                                               fprintf( stderr, "%d / %d\r", j, k );
+#endif
+                        c = sintbl[h + n4];
+                        if (inverse) s = - sintbl[h];
+                        else         s =   sintbl[h];
+                        for (i = j; i < n; i += k2) {
+#if 0
+                                                               if( k>=4194000 ) fprintf( stderr, "in loop %d -  %d < %d, k2=%d\r", j, i, n, k2 );
+#endif
+                                ik = i + k;
+                                dR = s * x[ik].I + c * x[ik].R;
+                                dI = c * x[ik].I - s * x[ik].R;
+                                x[ik].R = x[i].R - dR;  x[i].R += dR;
+                                x[ik].I = x[i].I - dI;  x[i].I += dI;
+                        }
+                        h += d;
+                }
+        }
+        if (! inverse)    /* n */
+                for (i = 0; i < n; i++) {  x[i].R /= n;  x[i].I /= n;  }
+        return 0;  /*  */
+}
diff --git a/binaries/src/mafft/core/fft.h b/binaries/src/mafft/core/fft.h
new file mode 100644 (file)
index 0000000..64ff196
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <math.h>
+#include "mtxutl.h"
+
+#define PI 3.14159265358979323846
+#define END_OF_VEC -1
+
+#define NKOUHO   20
+#define NKOUHO_LONG   500
+
+#define MAX(X,Y)    ( ((X)>(Y))?(X):(Y) )
+#define MIN(X,Y)    ( ((X)<(Y))?(X):(Y) )
+
diff --git a/binaries/src/mafft/core/fftFunctions.c b/binaries/src/mafft/core/fftFunctions.c
new file mode 100644 (file)
index 0000000..927dc3f
--- /dev/null
@@ -0,0 +1,760 @@
+#include "mltaln.h"
+
+#define SEGMENTSIZE 150
+#define TMPTMPTMP 0
+
+#define DEBUG 0
+
+void keika( char *str, int current, int all )
+{
+       if( current == 0 )
+               fprintf( stderr, "%s :         ", str );
+
+               fprintf( stderr, "\b\b\b\b\b\b\b\b" );
+               fprintf( stderr, "%3d /%3d", current+1, all+1 );
+
+       if( current+1 == all )
+               fprintf( stderr, "\b\b\b\b\b\b\b\bdone.     \n" );
+}
+
+double maxItch( double *soukan, int size )
+{
+       int i;
+       double value = 0.0;
+       double cand;
+       for( i=0; i<size; i++ ) 
+               if( ( cand = soukan[i] ) > value ) value = cand;
+       return( value );
+}
+
+void calcNaiseki( Fukusosuu *value, Fukusosuu *x, Fukusosuu *y )
+{
+       value->R =  x->R * y->R + x->I * y->I;
+       value->I = -x->R * y->I + x->I * y->R;
+}
+
+Fukusosuu *AllocateFukusosuuVec( int l1 )
+{
+       Fukusosuu *value;
+       value = (Fukusosuu *)calloc( l1, sizeof( Fukusosuu ) );
+       if( !value )
+       {
+               fprintf( stderr, "Cannot allocate %d FukusosuuVec\n", l1 );
+               return( NULL );
+       }
+       return( value );
+}
+       
+Fukusosuu **AllocateFukusosuuMtx( int l1, int l2 )
+{
+       Fukusosuu **value;
+       int j;
+//     fprintf( stderr, "allocating %d x %d FukusosuuMtx\n", l1, l2 );
+       value = (Fukusosuu **)calloc( l1+1, sizeof( Fukusosuu * ) );
+       if( !value ) 
+       {
+               fprintf( stderr, "Cannot allocate %d x %d FukusosuuVecMtx\n", l1, l2 );
+               exit( 1 );
+       }
+       for( j=0; j<l1; j++ ) 
+       {
+               value[j] = AllocateFukusosuuVec( l2 );
+               if( !value[j] )
+               {
+                       fprintf( stderr, "Cannot allocate %d x %d FukusosuuVecMtx\n", l1, l2 );
+                       exit( 1 );
+               }
+       }
+       value[l1] = NULL;
+       return( value );
+}
+
+Fukusosuu ***AllocateFukusosuuCub( int l1, int l2, int l3 )
+{
+       Fukusosuu ***value;
+       int i;
+       value = calloc( l1+1, sizeof( Fukusosuu ** ) );
+       if( !value ) ErrorExit( "Cannot allocate Fukusosuu" );
+       for( i=0; i<l1; i++ ) value[i] = AllocateFukusosuuMtx( l2, l3 );
+       value[l1] = NULL;
+       return( value );
+}
+
+void FreeFukusosuuVec( Fukusosuu *vec )
+{
+       free( (void *)vec );
+}
+
+void FreeFukusosuuMtx( Fukusosuu **mtx )
+{
+       int i;
+
+       for( i=0; mtx[i]; i++ ) 
+               free( (void *)mtx[i] );
+       free( (void *)mtx );
+}
+
+int getKouho( int *kouho, int nkouho, double *soukan, int nlen2 )
+{
+       int i, j;
+       int nlen4 = nlen2 / 2;
+       double max;
+       double tmp;
+       int ikouho = 0; // by D.Mathog, iinoka?
+       for( j=0; j<nkouho; j++ ) 
+       {
+               max = -9999.9;
+               for( i=0; i<nlen2; i++ ) 
+               {
+                       if( ( tmp = soukan[i] ) > max )
+                       {
+                               ikouho = i;
+                               max = tmp;
+                       }
+               }
+#if 0
+               if( max < 0.15 )
+               {
+                       break;
+               }
+#endif
+#if 0
+               fprintf( stderr, "Kouho No.%d, pos=%d, score=%f, lag=%d\n", j, ikouho, soukan[ikouho], ikouho-nlen4 );
+#endif
+               soukan[ikouho] = -9999.9;
+               kouho[j] = ( ikouho - nlen4 );
+       }
+       return( j );
+}
+
+void zurasu2( int lag, int    clus1, int    clus2, 
+                       char  **seq1, char  **seq2, 
+                                          char **aseq1, char **aseq2 )
+{
+       int i;
+#if 0
+       fprintf( stderr, "### lag = %d\n", lag );
+#endif
+       if( lag > 0 )
+       {
+               for( i=0; i<clus1; i++ ) aseq1[i] = seq1[i];
+               for( i=0; i<clus2; i++ ) aseq2[i] = seq2[i]+lag;
+       }
+       else
+       {
+               for( i=0; i<clus1; i++ ) aseq1[i] = seq1[i]-lag;
+               for( i=0; i<clus2; i++ ) aseq2[i] = seq2[i];
+       }
+}
+
+void zurasu( int lag, int    clus1, int    clus2, 
+                      char  **seq1, char  **seq2, 
+                                         char **aseq1, char **aseq2 )
+{
+       int i;
+#if DEBUG
+       fprintf( stderr, "lag = %d\n", lag );
+#endif
+       if( lag > 0 )
+       {
+               for( i=0; i<clus1; i++ ) strcpy( aseq1[i], seq1[i] );
+               for( i=0; i<clus2; i++ ) strcpy( aseq2[i], seq2[i]+lag );
+       }
+       else
+       {
+               for( i=0; i<clus1; i++ ) strcpy( aseq1[i], seq1[i]-lag );
+               for( i=0; i<clus2; i++ ) strcpy( aseq2[i], seq2[i] );
+       }
+}
+
+
+int alignableReagion( int    clus1, int    clus2, 
+                                          char  **seq1, char  **seq2,
+                                          double *eff1, double *eff2,
+                                          Segment *seg )
+{
+       int i, j, k;
+       int status, starttmp = 0; // by D.Mathog, a gess
+       double score;
+       int value = 0;
+       int len, maxlen;
+       int length = 0; // by D.Mathog, a gess
+       static TLS double *stra = NULL;
+       static TLS int alloclen = 0;
+       double totaleff;
+       double cumscore;
+       static TLS double threshold;
+       static TLS double *prf1 = NULL;
+       static TLS double *prf2 = NULL;
+       static TLS int *hat1 = NULL;
+       static TLS int *hat2 = NULL;
+       int pre1, pre2;
+#if 0
+       char **seq1pt;
+       char **seq2pt;
+       double *eff1pt;
+       double *eff2pt;
+#endif
+
+#if 0
+       fprintf( stderr, "### In alignableRegion, clus1=%d, clus2=%d \n", clus1, clus2 );
+       fprintf( stderr, "seq1[0] = %s\n", seq1[0] );
+       fprintf( stderr, "seq2[0] = %s\n", seq2[0] );
+       fprintf( stderr, "eff1[0] = %f\n", eff1[0] );
+       fprintf( stderr, "eff2[0] = %f\n", eff2[0] );
+#endif
+
+       if( clus1 == 0 )
+       {
+               FreeDoubleVec( stra ); stra = NULL;
+               FreeDoubleVec( prf1 ); prf1 = NULL;
+               FreeDoubleVec( prf2 ); prf2 = NULL;
+               FreeIntVec( hat1 ); hat1 = NULL;
+               FreeIntVec( hat2 ); hat2 = NULL;
+               return( 0 );
+       }
+
+       if( prf1 == NULL )
+       {
+               prf1 = AllocateDoubleVec( 26 );
+               prf2 = AllocateDoubleVec( 26 );
+               hat1 = AllocateIntVec( 27 );
+               hat2 = AllocateIntVec( 27 );
+       }
+
+       len = MIN( strlen( seq1[0] ), strlen( seq2[0] ) );
+       maxlen = MAX( strlen( seq1[0] ), strlen( seq2[0] ) ) + fftWinSize;
+       if( alloclen < maxlen )
+       {
+               if( alloclen )
+               {
+                       FreeDoubleVec( stra );
+               }
+               else
+               {
+                       threshold = (int)fftThreshold / 100.0 * 600.0 * fftWinSize;
+               }
+               stra = AllocateDoubleVec( maxlen );
+               alloclen = maxlen;
+       }
+
+
+       totaleff = 0.0;
+       for( i=0; i<clus1; i++ ) for( j=0; j<clus2; j++ ) totaleff += eff1[i] * eff2[j];
+       for( i=0; i<len; i++ )
+       {
+               /* make prfs */
+               for( j=0; j<26; j++ )
+               {
+                       prf1[j] = 0.0;
+                       prf2[j] = 0.0;
+               }
+#if 0
+               seq1pt = seq1;
+               eff1pt = eff1;
+               j = clus1;
+               while( j-- ) prf1[amino_n[(*seq1pt++)[i]]] += *eff1pt++;
+#else
+               for( j=0; j<clus1; j++ ) prf1[amino_n[(int)seq1[j][i]]] += eff1[j];
+#endif
+               for( j=0; j<clus2; j++ ) prf2[amino_n[(int)seq2[j][i]]] += eff2[j];
+
+               /* make hats */
+               pre1 = pre2 = 26;
+               for( j=25; j>=0; j-- )
+               {
+                       if( prf1[j] )
+                       {
+                               hat1[pre1] = j;
+                               pre1 = j;
+                       }
+                       if( prf2[j] )
+                       {
+                               hat2[pre2] = j;
+                               pre2 = j;
+                       }
+               }
+               hat1[pre1] = -1;
+               hat2[pre2] = -1;
+
+               /* make site score */
+               stra[i] = 0.0;
+               for( k=hat1[26]; k!=-1; k=hat1[k] ) 
+                       for( j=hat2[26]; j!=-1; j=hat2[j] ) 
+//                             stra[i] += n_dis[k][j] * prf1[k] * prf2[j];
+                               stra[i] += n_disFFT[k][j] * prf1[k] * prf2[j];
+               stra[i] /= totaleff;
+       }
+
+       (seg+0)->skipForeward = 0;
+       (seg+1)->skipBackward = 0;
+       status = 0;
+       cumscore = 0.0;
+       score = 0.0;
+       for( j=0; j<fftWinSize; j++ ) score += stra[j];
+
+       for( i=1; i<len-fftWinSize; i++ )
+       {
+               score = score - stra[i-1] + stra[i+fftWinSize-1];
+#if TMPTMPTMP
+               fprintf( stderr, "%d %10.0f   ? %10.0f\n", i, score, threshold );
+#endif
+
+               if( score > threshold )
+               {
+#if 0
+                       seg->start = i;
+                       seg->end = i;
+                       seg->center = ( seg->start + seg->end + fftWinSize ) / 2 ;
+                       seg->score = score;
+                       status = 0;
+                       value++;
+#else
+                       if( !status )
+                       {
+                               status = 1;
+                               starttmp = i;
+                               length = 0;
+                               cumscore = 0.0;
+                       }
+                       length++;
+                       cumscore += score;
+#endif
+               }
+               if( score <= threshold || length > SEGMENTSIZE )
+               {
+                       if( status )
+                       {
+                               if( length > fftWinSize )
+                               {
+                                       seg->start = starttmp;
+                                       seg->end = i;
+                                       seg->center = ( seg->start + seg->end + fftWinSize ) / 2 ;
+                                       seg->score = cumscore;
+#if 0
+                                       fprintf( stderr, "%d-%d length = %d, score = %f, value = %d\n", seg->start, seg->end, length, cumscore, value );
+#endif
+                                       if( length > SEGMENTSIZE )
+                                       {
+                                               (seg+0)->skipForeward = 1;
+                                               (seg+1)->skipBackward = 1;
+                                       }
+                                       else
+                                       {
+                                               (seg+0)->skipForeward = 0;
+                                               (seg+1)->skipBackward = 0;
+                                       }
+                                       value++;
+                                       seg++;
+                               }
+                               length = 0;
+                               cumscore = 0.0;
+                               status = 0;
+                               starttmp = i;
+                               if( value > MAXSEG - 3 ) ErrorExit( "TOO MANY SEGMENTS!");
+                       }
+               }
+       }
+       if( status && length > fftWinSize )
+       {
+               seg->end = i;
+               seg->start = starttmp;
+               seg->center = ( starttmp + i + fftWinSize ) / 2 ;
+               seg->score = cumscore;
+#if 0
+fprintf( stderr, "%d-%d length = %d\n", seg->start, seg->end, length );
+#endif
+               value++;
+       }
+#if TMPTMPTMP
+       exit( 0 );
+#endif
+//     fprintf( stderr, "returning %d\n", value );
+       return( value );
+}
+
+
+static int permit( Segment *seg1, Segment *seg2 )
+{
+       return( 0 );
+       if( seg1->end >= seg2->start ) return( 0 );
+       if( seg1->pair->end >= seg2->pair->start ) return( 0 );
+       else return( 1 );
+}
+
+void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut )
+{
+       int i, j, k, shift, cur1, cur2, count, klim;
+       static TLS int crossscoresize = 0;
+       static TLS int *result1 = NULL;
+       static TLS int *result2 = NULL;
+       static TLS int *ocut1 = NULL;
+       static TLS int *ocut2 = NULL;
+       double maximum;
+       static TLS double **crossscore = NULL;
+       static TLS int **track = NULL;
+       static TLS double maxj, maxi;
+       static TLS int pointj, pointi;
+
+       if( cut1 == NULL) 
+       {
+               if( result1 )
+               {
+                       free( result1 );
+                       free( result2 );
+                       free( ocut1 );
+                       free( ocut2 );
+                       FreeIntMtx( track );
+               FreeDoubleMtx( crossscore );
+               }
+               return;
+       }
+
+       if( result1 == NULL )
+       {
+               result1 = AllocateIntVec( MAXSEG );
+               result2 = AllocateIntVec( MAXSEG );
+               ocut1 = AllocateIntVec( MAXSEG );
+               ocut2 = AllocateIntVec( MAXSEG );
+       }
+
+    if( crossscoresize < *ncut+2 )
+    {
+        crossscoresize = *ncut+2;
+               if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize );
+               if( track ) FreeIntMtx( track );
+        if( crossscore ) FreeDoubleMtx( crossscore );
+               track = AllocateIntMtx( crossscoresize, crossscoresize );
+        crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+    }
+
+#if 0
+       for( i=0; i<*ncut-2; i++ )
+               fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score );
+
+       for( i=0; i<*ncut; i++ )
+               fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] );
+       for( i=0; i<*ncut; i++ ) 
+       {
+               for( j=0; j<*ncut; j++ )
+                       fprintf( stderr, "%#4.0f ", ocrossscore[i][j] );
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+       for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ )  /* mudadanaa */
+               crossscore[i][j] = ocrossscore[i][j];
+       for( i=0; i<*ncut; i++ ) 
+       {
+               ocut1[i] = cut1[i];
+               ocut2[i] = cut2[i];
+       }
+
+       for( i=1; i<*ncut; i++ )
+       {
+#if 0
+               fprintf( stderr, "### i=%d/%d\n", i,*ncut );
+#endif
+               for( j=1; j<*ncut; j++ )
+               {
+                       pointi = 0; maxi = 0.0;
+                       klim = j-2;
+                       for( k=0; k<klim; k++ )
+                       {
+/*
+                               fprintf( stderr, "k=%d, i=%d\n", k, i );
+*/
+                               if( k && k<*ncut-1 && j<*ncut-1 && !permit( seg1[k-1], seg1[j-1] ) ) continue;
+                               if( crossscore[i-1][k] > maxj )
+                               {
+                                       pointi = k;
+                                       maxi = crossscore[i-1][k];
+                               }
+                       }
+
+                       pointj = 0; maxj = 0.0;
+                       klim = i-2;
+                       for( k=0; k<klim; k++ )
+                       {
+                               if( k && k<*ncut-1 && i<*ncut-1 && !permit( seg2[k-1], seg2[i-1] ) ) continue;
+                               if( crossscore[k][j-1] > maxj )
+                               {
+                                       pointj = k;
+                                       maxj = crossscore[k][j-1];
+                               }
+                       }       
+
+                       maxi += penalty;
+                       maxj += penalty;
+
+                       maximum = crossscore[i-1][j-1];
+                       track[i][j] = 0;
+
+                       if( maximum < maxi )
+                       {
+                               maximum = maxi ;
+                               track[i][j] = j - pointi;
+                       }
+
+                       if( maximum < maxj )
+                       {
+                               maximum = maxj ;
+                               track[i][j] = pointj - i;
+                       }
+
+                       crossscore[i][j] += maximum;
+               }
+       }
+#if 0
+       for( i=0; i<*ncut; i++ ) 
+       {
+               for( j=0; j<*ncut; j++ )
+                       fprintf( stderr, "%3d ", track[i][j] );
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+
+       result1[MAXSEG-1] = *ncut-1;
+       result2[MAXSEG-1] = *ncut-1;
+
+       for( i=MAXSEG-1; i>=1; i-- )
+       {
+               cur1 = result1[i];
+               cur2 = result2[i];
+               if( cur1 == 0 || cur2 == 0 ) break;
+               shift = track[cur1][cur2];
+               if( shift == 0 )
+               {
+                       result1[i-1] = cur1 - 1;
+                       result2[i-1] = cur2 - 1;
+                       continue;
+               }
+               else if( shift > 0 )
+               {
+                       result1[i-1] = cur1 - 1;
+                       result2[i-1] = cur2 - shift;
+               }
+               else if( shift < 0 )
+               {
+                       result1[i-1] = cur1 + shift;
+                       result2[i-1] = cur2 - 1;
+               }
+       }
+
+       count = 0;
+       for( j=i; j<MAXSEG; j++ )
+       {
+               if( ocrossscore[result1[j]][result2[j]] == 0.0 ) continue;
+
+               if( result1[j] == result1[j-1] || result2[j] == result2[j-1] )
+                       if( ocrossscore[result1[j]][result2[j]] > ocrossscore[result1[j-1]][result2[j-1]] )
+                               count--;
+                               
+               cut1[count] = ocut1[result1[j]];
+               cut2[count] = ocut2[result2[j]];
+
+               count++;
+       }
+
+       *ncut = count;
+#if 0
+       for( i=0; i<*ncut; i++ )
+               fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] );
+#endif
+}
+
+void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut )
+// memory complexity = O(n^3), time complexity = O(n^2)
+{
+       int i, j, shift, cur1, cur2, count;
+       static TLS int crossscoresize = 0;
+       static TLS int jumpposi, *jumppos;
+       static TLS double jumpscorei, *jumpscore;
+       static TLS int *result1 = NULL;
+       static TLS int *result2 = NULL;
+       static TLS int *ocut1 = NULL;
+       static TLS int *ocut2 = NULL;
+       double maximum;
+       static TLS double **crossscore = NULL;
+       static TLS int **track = NULL;
+
+       if( result1 == NULL )
+       {
+               result1 = AllocateIntVec( MAXSEG );
+               result2 = AllocateIntVec( MAXSEG );
+               ocut1 = AllocateIntVec( MAXSEG );
+               ocut2 = AllocateIntVec( MAXSEG );
+       }
+    if( crossscoresize < *ncut+2 )
+    {
+        crossscoresize = *ncut+2;
+               if( fftkeika ) fprintf( stderr, "allocating crossscore and track, size = %d\n", crossscoresize );
+               if( track ) FreeIntMtx( track );
+        if( crossscore ) FreeDoubleMtx( crossscore );
+        if( jumppos ) FreeIntVec( jumppos );
+        if( jumpscore ) FreeDoubleVec( jumpscore );
+               track = AllocateIntMtx( crossscoresize, crossscoresize );
+        crossscore = AllocateDoubleMtx( crossscoresize, crossscoresize );
+        jumppos = AllocateIntVec( crossscoresize );
+        jumpscore = AllocateDoubleVec( crossscoresize );
+    }
+
+#if 0
+       for( i=0; i<*ncut-2; i++ )
+               fprintf( stderr, "%d.start = %d, score = %f\n", i, seg1[i]->start, seg1[i]->score );
+
+       for( i=0; i<*ncut; i++ )
+               fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] );
+       for( i=0; i<*ncut; i++ ) 
+       {
+               for( j=0; j<*ncut; j++ )
+                       fprintf( stderr, "%#4.0f ", ocrossscore[i][j] );
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+       for( i=0; i<*ncut; i++ ) for( j=0; j<*ncut; j++ )  /* mudadanaa */
+               crossscore[i][j] = ocrossscore[i][j];
+       for( i=0; i<*ncut; i++ ) 
+       {
+               ocut1[i] = cut1[i];
+               ocut2[i] = cut2[i];
+       }
+       for( j=0; j<*ncut; j++ )
+       {
+               jumpscore[j] = -999.999;
+               jumppos[j] = -1;
+       }
+
+       for( i=1; i<*ncut; i++ )
+       {
+
+               jumpscorei = -999.999;
+               jumpposi = -1;
+
+               for( j=1; j<*ncut; j++ )
+               {
+#if 1
+                       fprintf( stderr, "in blockalign3, ### i=%d, j=%d\n", i, j );
+#endif
+
+
+#if 0
+                       for( k=0; k<j-2; k++ )
+                       {
+/*
+                               fprintf( stderr, "k=%d, i=%d\n", k, i );
+*/
+                               if( k && k<*ncut-1 && j<*ncut-1 && !permit( seg1[k-1], seg1[j-1] ) ) continue;
+                               if( crossscore[i-1][k] > maxj )
+                               {
+                                       pointi = k;
+                                       maxi = crossscore[i-1][k];
+                               }
+                       }
+
+                       pointj = 0; maxj = 0.0;
+                       for( k=0; k<i-2; k++ )
+                       {
+                               if( k && k<*ncut-1 && i<*ncut-1 && !permit( seg2[k-1], seg2[i-1] ) ) continue;
+                               if( crossscore[k][j-1] > maxj )
+                               {
+                                       pointj = k;
+                                       maxj = crossscore[k][j-1];
+                               }
+                       }       
+
+
+                       maxi += penalty;
+                       maxj += penalty;
+#endif
+                       maximum = crossscore[i-1][j-1];
+                       track[i][j] = 0;
+
+                       if( maximum < jumpscorei && permit( seg1[jumpposi], seg1[i] ) )
+                       {
+                               maximum = jumpscorei;
+                               track[i][j] = j - jumpposi;
+                       }
+
+                       if( maximum < jumpscore[j] && permit( seg2[jumppos[j]], seg2[j] ) )
+                       {
+                               maximum = jumpscore[j];
+                               track[i][j] = jumpscore[j] - i;
+                       }
+
+                       crossscore[i][j] += maximum;
+
+                       if( jumpscorei < crossscore[i-1][j] )
+                       {
+                               jumpscorei = crossscore[i-1][j];
+                               jumpposi = j;
+                       }
+
+                       if( jumpscore[j] < crossscore[i][j-1] )
+                       {
+                               jumpscore[j] = crossscore[i][j-1];
+                               jumppos[j] = i;
+                       }
+               }
+       }
+#if 0
+       for( i=0; i<*ncut; i++ ) 
+       {
+               for( j=0; j<*ncut; j++ )
+                       fprintf( stderr, "%3d ", track[i][j] );
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+
+       result1[MAXSEG-1] = *ncut-1;
+       result2[MAXSEG-1] = *ncut-1;
+
+       for( i=MAXSEG-1; i>=1; i-- )
+       {
+               cur1 = result1[i];
+               cur2 = result2[i];
+               if( cur1 == 0 || cur2 == 0 ) break;
+               shift = track[cur1][cur2];
+               if( shift == 0 )
+               {
+                       result1[i-1] = cur1 - 1;
+                       result2[i-1] = cur2 - 1;
+                       continue;
+               }
+               else if( shift > 0 )
+               {
+                       result1[i-1] = cur1 - 1;
+                       result2[i-1] = cur2 - shift;
+               }
+               else if( shift < 0 )
+               {
+                       result1[i-1] = cur1 + shift;
+                       result2[i-1] = cur2 - 1;
+               }
+       }
+
+       count = 0;
+       for( j=i; j<MAXSEG; j++ )
+       {
+               if( ocrossscore[result1[j]][result2[j]] == 0.0 ) continue;
+
+               if( result1[j] == result1[j-1] || result2[j] == result2[j-1] )
+                       if( ocrossscore[result1[j]][result2[j]] > ocrossscore[result1[j-1]][result2[j-1]] )
+                               count--;
+                               
+               cut1[count] = ocut1[result1[j]];
+               cut2[count] = ocut2[result2[j]];
+
+               count++;
+       }
+
+       *ncut = count;
+#if 0
+       for( i=0; i<*ncut; i++ )
+               fprintf( stderr, "i=%d, cut1 = %d, cut2 = %d\n", i, cut1[i], cut2[i] );
+#endif
+}
+
diff --git a/binaries/src/mafft/core/functions.h b/binaries/src/mafft/core/functions.h
new file mode 100644 (file)
index 0000000..44d8688
--- /dev/null
@@ -0,0 +1,319 @@
+extern int intlen( int *num );
+extern char seqcheck( char **seq );
+extern void scmx_calc( int icyc, char **aseq, double *effarr, float **scmx );
+extern void exitall( char arr[] );
+extern void display( char **seq, int nseq );
+extern void intergroup_score( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value );
+extern void intergroup_score_gapnomi( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value );
+extern void intergroup_score_new( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value );
+extern double score_calc5( char **seq, int s, double **eff, int ex );
+extern double score_calc4( char **seq, int s, double **eff, int ex );
+extern void upg2( int nseq, double **eff, int ***topol, double **len );
+//extern void veryfastsupg_float_realloc_nobk_halfmtx( int njob, float **mtx, int ***topol, float **len );
+//extern void veryfastsupg_float_realloc_nobk( int njob, float **mtx, int ***topol, float **len );
+extern void veryfastsupg_int_realloc_nobk( int njob, int **mtx, int ***topol, double **len );
+extern void veryfastsupg( int nseq, double **oeff, int ***topol, double **len );
+extern void veryfastsupg_double( int nseq, double **oeff, int ***topol, double **len );
+extern void veryfastsupg_double_loadtree( int nseq, double **oeff, int ***topol, double **len );
+extern void veryfastsupg_double_loadtop( int nseq, double **oeff, int ***topol, double **len );
+extern void veryfastsupg_int( int nseq, int **oeff, int ***topol, double **len );
+extern void fastsupg( int nseq, double **oeff, int ***topol, double **len );
+extern void supg( int nseq, double **oeff, int ***topol, double **len );
+extern void spg( int nseq, double **oeff, int ***topol, double **len );
+extern double ipower( double x, int n );
+extern void countnode( int nseq, int ***topol, double **node );
+extern void countnode_int( int nseq, int ***topol, int **node );
+extern void counteff_simple( int nseq, int ***topol, double **len, double *node );
+extern void counteff_simple_float( int nseq, int ***topol, float **len, double *node );
+extern void counteff( int nseq, int ***topol, double **len, double **node );
+extern float score_calc1( char *seq1, char *seq2 );
+extern float score_calcp( char *seq1, char *seq2, int len );
+extern float substitution_nid( char *seq1, char *seq2 );
+extern float substitution_score( char *seq1, char *seq2 );
+extern float substitution_hosei( char *seq1, char *seq2 );
+extern float substitution( char *seq1, char *seq2 );
+extern void treeconstruction( char **seq, int nseq, int ***topol, double **len, double **eff );
+extern float bscore_calc( char **seq, int s, double **eff );
+extern void AllocateTmpSeqs( char ***mseq2pt, char **mseq1pt, int locnlenmax );
+extern void FreeTmpSeqs( char **mseq2, char *mseq1 );
+extern void gappick_samestring( char *aseq );
+extern void gappick0( char *aseq, char *seq );
+extern void gappick( int nseq, int s, char **aseq, char **mseq2, 
+                                        double **eff, double *effarr );
+extern void commongappick_record( int nseq, char **seq, int *map );
+extern void commongappick( int nseq, char **seq );
+extern double score_calc0( char **seq, int s, double **eff, int ex );
+extern void strins( char *str1, char *str2 );
+extern int isaligned( int nseq, char **seq );
+extern double score_calc_for_score( int nseq, char **seq );
+extern void floatncpy( float *vec1, float *vec2, int len );
+extern float score_calc_a( char **seq, int s, double **eff );
+extern float score_calc_s( char **seq, int s, double **eff );
+extern double score_calc_for_score_s( int s, char **seq );
+extern double SSPscore( int s, char **seq );
+extern double DSPscore( int s, char **seq );
+extern int searchAnchors( int nseq, char **seq, Segment *seg );
+extern char *progName( char *str );
+extern void dontcalcimportance( int nseq, double *eff, char **seq, LocalHom **localhom );
+extern void calcimportance( int nseq, double *eff, char **seq, LocalHom **localhom );
+extern void weightimportance2( int nseq, double *eff, LocalHom **localhom );
+extern void weightimportance4( int clus1, int clus2, double *eff1, double *eff2, LocalHom ***localhom );
+extern void extendlocalhom( int nseq, LocalHom **localhom );
+extern void extendlocalhom2( int nseq, LocalHom **localhom, double **mtx );
+extern int makelocal( char *s1, char *s2, int thr );
+extern void mdfymtx( char **pair, int s1, double **partialmtx, double **mtx );
+extern float score_calc( char **seq, int s );
+extern void cpmx_calc( char **seq, float **cpmx, double *eff, int lgth, int clus );
+extern void cpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus );
+extern void MScpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus );
+extern void mseqcat( char **seq1, char **seq2, double **eff, double *effarr1, double *effarr2, char name1[M][B], char name2[M][B], int clus1, int clus2 );
+extern void strnbcat( char *s1, char *s2, int m );
+extern int conjuctionforgaln( int s0, int s1, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d );
+extern int fastconjuction( int *memlist, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d );
+extern int fastconjuction_noname_kozo( int *memlist, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d );
+extern int fastconjuction_noname( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d );
+extern int fastconjuction_noweight( int *memlist, char **seq, char **aseq, double *peff, char *d );
+extern int conjuctionfortbfast( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char *d );
+extern int conjuctionfortbfast_kozo( double *tmptmp, char **pair, int s, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d );
+extern int conjuction( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d );
+extern void floatdelete( float **cpmx, int d, int len );
+extern void chardelete( char *seq, int d );
+extern int RootBranchNode( int nseq, int ***topol, int step, int branch );
+extern void BranchLeafNode( int nseq, int ***topol, int *node, int step, int branch );
+extern void RootLeafNode( int nseq, int ***topol, int *node );
+extern void nodeFromABranch( int nseq, int *result, int **pairwisenode, int ***topol, double **len, int step, int num );
+extern void OneClusterAndTheOther( int locnjob, char **pair, int *s1, int *s2, int ***topol, int step, int branch );
+extern void makeEffMtx( int nseq, double **mtx, double *vec );
+extern void node_eff( int nseq, double *eff, int *node );
+extern int shrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink );
+extern int msshrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink );
+extern int fastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink );
+extern int msfastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink );
+extern int TreeDependentIteration( int locnjob, char **name, int nlen[M], char **aseq, char **bseq, int ***topol, double **len, int alloclen, LocalHom **localhomtable, RNApair ***single, int nkozo, char *kozoarivec );
+extern void checkMinusLength( int nseq, double **len );
+extern void negativeMember2( int *mem, int *query, int locnseq );
+extern int *negativeMember( int *query, int locnseq );
+extern int IntExistsInVec( int query, int *vector );
+extern NodeInCub searchParent( int top, int ***topol, int Start, int End );
+extern void stopolInit( int n, Node *stopol );
+extern void treeCnv( Node *stopol, int locnseq, int ***topol, double **len, double **bw );
+extern int isLeaf( Node node );
+extern double syntheticLength( Node *ob, Node *oppositeNode );
+extern double calcW( Node *ob, Node *op );
+extern void calcBranchWeight( double **bw, int locnseq, Node *stopol, int ***topol, double **len );
+extern void branchWeightToPairWeight( int locnseq, int ***topol, double **pw, double **bw );
+extern void weightFromABranch_rec( double *result, Node *ob, Node *op );
+extern void weightFromABranch( int nseq, double *result, Node *stopol, int ***topol, int step, int LorR );
+extern void keika( char *str, int current, int all );
+extern double maxItch( double *soukan, int size );
+extern void calcNaiseki( Fukusosuu *value, Fukusosuu *x, Fukusosuu *y );
+extern Fukusosuu *AllocateFukusosuuVec( int l1 );
+extern Fukusosuu **AllocateFukusosuuMtx( int l1, int l2 );
+extern Fukusosuu ***AllocateFukusosuuCub( int l1, int l2, int l3 );
+extern void FreeFukusosuuVec( Fukusosuu *vec );
+extern void FreeFukusosuuMtx( Fukusosuu **mtx );
+extern int getKouho( int *kouho, int nkouho, double *soukan, int nlen2 );
+extern void zurasu2( int lag, int    clus1, int    clus2, char  **seq1, char  **seq2, char **aseq1, char **aseq2 );
+extern void zurasu( int lag, int    clus1, int    clus2, char  **seq1, char  **seq2, char **aseq1, char **aseq2 );
+extern int alignableReagion( int    clus1, int    clus2, char  **seq1, char  **seq2, double *eff1, double *eff2, Segment *seg );
+extern void blockAlign( int *cut1, int *cut2, double **ocrossscore, int *ncut );
+extern void blockAlign2( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut );
+extern void blockAlign3( int *cut1, int *cut2, Segment **seg1, Segment **seg2, double **ocrossscore, int *ncut );
+extern float A__align11( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch );
+extern float imp_match_out_scH( int i1, int j1 );
+extern void imp_match_init_strictH( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore );
+extern float imp_match_out_scQ( int i1, int j1 );
+extern float imp_match_out_scR( int i1, int j1 );
+extern void imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore );
+extern void imp_match_init_strictR( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore );
+extern void imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom );
+extern float MSalignmm( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, int *, int, int *, int headgp, int tailgp );
+extern float Lalignmm_hmout( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map );
+extern float Lalign2m2m_hmout( char **seq1, char **seq2, char **seq1r, char **seq2r, char *dir1, char *dir2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, char *, char *, char *, char *, float **map );
+extern float MSalign11( char **seq1, char **seq2, int alloclen );
+//extern float rnalocal( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, RNApair **pair );
+extern float A__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *, int, int *, int headgp, int tailgp );
+extern float H__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 );
+extern float Q__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 );
+extern float Q__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2, int *gapmap1, int *gapmap2 );
+extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 );
+extern float R__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, char *gs1, char *gs2, char *ge1, char *ge2 );
+extern float A__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 );
+extern float D__align_gapmap( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int *gapmap1, int *gapmap2 );
+extern float translate_and_Calign( char **mseq1, char **mseq2, double *effarr1, double *effarr2, int clus1, int clus2, int alloclen );
+extern double Fgetlag( char  **seq1, char  **seq2, double *eff1, double *eff2, int    clus1, int    clus2, int alloclen );
+extern float Falign( char  **seq1, char  **seq2, double *eff1, double *eff2, int    clus1, int    clus2, int alloclen, int *fftlog, int *, int, int * );
+extern float Falign_udpari_long( char  **seq1, char  **seq2, double *eff1, double *eff2, int    clus1, int    clus2, int alloclen, int *fftlog );
+float Falign_localhom( char  **seq1, char  **seq2, double *eff1, double *eff2, int    clus1, int    clus2, int alloclen, LocalHom ***localhom, float *totalimpmatch, int *gapmap1, int *gapmap2, int *chudanpt, int chudanref, int *chudanres );
+extern float part_imp_match_out_sc( int i1, int j1 );
+extern float part_imp_match_out_scQ( int i1, int j1 );
+extern void part_imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, int forscore );
+extern void part_imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore );
+extern void part_imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom );
+extern float partA__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *, int *, int, int * );
+extern float partQ__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *, char *, char *, char *);
+extern float G__align11( char **seq1, char **seq2, int alloclen, int headgp, int tailgp  );
+extern float G__align11_noalign( int mtx[0x80][0x80], int penal, int penal_ex, char **seq1, char **seq2, int alloclen );
+extern float L__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt );
+extern float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt );
+extern float genG__align11( char **seq1, char **seq2, int alloclen );
+extern float VAalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt );
+extern float suboptalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt )
+;
+extern int fft(int n, Fukusosuu *x, int dum);
+extern void topolcpy( int s1[], int s2[], int *mpt1, int *mpt2 );
+extern void topolcat( int s1[], int s2[], int *mpt1, int *mpt2 );
+extern void topolsort( int m, int s[] );
+extern void topolswap( int s1[], int s2[], int *mpt1, int *mpt2 );
+extern void reduc( double **mtx, int nseq, int im, int jm );
+extern void  nj( int nseq, double **omtx, int ***topol, double **dis );
+extern void JTTmtx( double **rsr, double *freq, char locamino[26], char locgrp[26], int isTM );
+extern void BLOSUMmtx( int n, double **matrix, double *freq, char *amino, char *amino_grp );
+extern void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa );
+extern void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa );
+extern void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa );
+extern void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa );
+extern void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa );
+extern char *cutal( char *al, int al_display_start, int start, int end );
+extern void ErrorExit( char *message );
+extern void strncpy_caseC( char *str1, char *str2, int len );
+extern void seqUpper( int nseq, char **seq );
+extern void seqLower( int nseq, char **seq );
+extern int getaline_fp_eof( char *s, int l, FILE *fp );
+extern int getaline_fp_eof_new(char s[], int l, FILE *fp);
+extern int myfgets(char s[], int l, FILE *fp);
+extern float input_new( FILE *fp, int d );
+extern void PreRead( FILE *fp, int *locnjob, int *locnlenmax );
+extern int allSpace( char *str );
+extern void Read( char name[M][B], int nlen[M], char **seq );
+extern void FRead( FILE *fp, char name[][B], int nlen[], char **seq );
+extern void kake2hiku( char *str );
+extern void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq );
+extern void readData( FILE *fp, char name[][B], int nlen[], char **seq );
+extern void readData_pointer_casepreserve( FILE *fp, char **name, int *nlen, char **seq );
+extern void readData_pointer( FILE *fp, char **name, int *nlen, char **seq );
+extern void readData_pointer2( FILE *fp, int nseq, char **name, int *nlen, char **seq );
+extern void readData_varlen( FILE *fp, char **name, int *nlen, char **seq );
+extern int countATGC( char *s, int *total );
+extern void getnumlen( FILE *fp );
+extern void getnumlen_casepreserve( FILE *fp, int *nlenmin );
+extern void getnumlen_nogap( FILE *fp, int *nlenmin );
+extern void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq );
+extern void writeDataforgaln( FILE *fp, int locnjob, char **name, int *nlen, char **aseq );
+extern void writeData( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq );
+extern void writeData_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq );
+extern void readhat2_floathalf( FILE *fp, int nseq, char name[M][B], float **mtx );
+extern void readhat2_floathalf_pointer( FILE *fp, int nseq, char **name, float **mtx );
+extern void readhat2_float( FILE *fp, int nseq, char name[M][B], float **mtx );
+extern void readhat2_int( FILE *fp, int nseq, char name[M][B], int **mtx );
+extern void readhat2_pointer( FILE *fp, int nseq, char **name, double **mtx );
+extern void readhat2( FILE *fp, int nseq, char name[M][B], double **mtx );
+extern void WriteFloatHat2_pointer_halfmtx( FILE *hat2p, int locnjob, char **name, float **mtx );
+extern void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], float **mtx );
+extern void WriteHat2_int( FILE *hat2p, int locnjob, char name[M][B], int **mtx );
+extern void WriteHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx );
+extern void WriteHat2_pointer( FILE *hat2p, int locnjob, char **name, double **mtx );
+extern int ReadFasta_sub( FILE *fp, double *dis, int nseq, char name[M][B] );
+extern int ReadSsearch( FILE *fp, double *dis, int nseq, char name[M][B] );
+extern int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist );
+extern int ReadBlastm7_scoreonly( FILE *fp, double *dis, int nin );
+extern int ReadBlastm7_avscore( FILE *fp, double *dis, int nin );
+extern int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist );
+extern int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist );
+extern int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist );
+extern int ReadFasta34m10_scoreonly_nuc( FILE *fp, double *dis, int nin );
+extern int ReadFasta34m10_scoreonly( FILE *fp, double *dis, int nin );
+extern int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist );
+extern int ReadFasta3( FILE *fp, double *dis, int nseq, char name[M][B] );
+extern int ReadFasta( FILE *fp, double *dis, int nseq, char name[M][B] );
+extern int ReadOpt( FILE *fp, int opt[M], int nseq, char name[M][B] );
+extern int ReadOpt2( FILE *fp, int opt[M], int nseq, char name[M][B] );
+extern int writePre( int nseq, char **name, int nlen[M], char **aseq, int force );
+extern void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr );
+extern void initSignalSM( void );
+extern void initFiles( void );
+extern void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq );
+extern void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec );
+extern void readlocalhomtable2( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec );
+extern void outlocalhom( LocalHom **localhom, int nseq );
+extern void outlocalhompt( LocalHom ***localhom, int n1, int n2 );
+extern void FreeLocalHomTable( LocalHom **localhomtable, int n ) ;
+extern void constants( int nseq, char **seq );
+extern void clustalout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, char *mark, char *comment, int *order, int namelen );
+extern void phylipout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, int *order );
+extern void writeData_reorder( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq, int *order );
+extern void writeData_reorder_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq, int *order );
+
+extern void resetlocalhom( int, LocalHom ** );
+extern int load1SeqWithoutName_new( FILE *fpp, char *cbuf );
+extern char *load1SeqWithoutName_realloc( FILE *fpp );
+extern char *load1SeqWithoutName_realloc_casepreserve( FILE *fpp );
+extern int disttbfast( char **in, int nlen[M], char name[M][B] );
+extern void searchKUorWA( FILE *fp );
+extern void gapireru( char *res, char *ori, char *gt );
+extern int seqlen( char *seq );
+extern void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len );
+extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len );
+extern void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len );
+extern void st_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len );
+extern void getdiaminofreq_x( float *freq, int clus, char **seq, double *eff, int len );
+extern void new_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len, char *s, char *e );
+extern void new_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len, char *g );
+extern void new_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len, char *g );
+extern void new_OpeningGapCount_zure( float *ogcp, int clus, char **seq, double *eff, int len, char *s, char *e );
+extern void getGapPattern( float *fgcp, int clus, char **seq, double *eff, int len, char *g );
+extern void getgapfreq( float *freq, int clus, char **seq, double *eff, int len );
+extern void getgapfreq_zure( float *freq, int clus, char **seq, double *eff, int len );
+//extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s );
+extern void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *s );
+extern void getdiaminofreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e );
+extern void getdigapfreq_part( float *freq, int clus, char **seq, double *eff, int len, char *s, char *e );
+extern void getdiaminofreq_st( float *freq, int clus, char **seq, double *eff, int len );
+extern void getdigapfreq_st( float *freq, int clus, char **seq, double *eff, int len );
+extern void st_getGapPattern( Gappat **gpat, int clus, char **seq, double *eff, int len );
+extern void getkyokaigap( char *g, char **s, int pos, int n );
+extern double *loadaamtx( void );
+extern float naivepairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal );
+extern float naivepairscore11( char *seq1, char *seq2, int penal );
+extern float naiveQpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal );
+extern float naiveRpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal );
+extern float naiveHpairscore( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, int penal );
+extern void foldrna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void foldrna_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void part_imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void part_imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void imp_rnaQ_gappick( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***gr1, RNApair ***gr2, int *gapmap1, int *gapmap2, RNApair *pair );
+extern void foldalignedrna( int clus1, int clus2, char **mseq1, char **mseq2, double *effarr1, double *effarr2, RNApair *rnapairboth );
+void readmccaskill( FILE *fp, RNApair **pairprob, int length );
+void makegrouprna( RNApair ***group, RNApair ***all, int *memlist );
+void makegrouprnait( RNApair ***group, RNApair ***all, char **pair, int s );
+extern void fixed_musclesupg_float_realloc_nobk_halfmtx( int nseq, float **eff, int ***topol, float **len, Treedep * );
+extern void loadtree( int nseq, int ***topol, float **len, char **name, int *nlen, Treedep * );
+extern void loadtop( int nseq, float **eff, int ***topol, float **len );
+extern void fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( int nseq, float **eff, int ***topol, float **len, char **name, int *nlen, Treedep * );
+extern void fixed_musclesupg_double_treeout( int nseq, double **eff, int ***topol, double **len, char **name );
+extern void imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1kozo, double*eff2kozo, LocalHom ***localhom, int forscore );
+extern void miyataout_reorder_pointer( FILE *fp, int locnjob, int nlenmax, char **name, int *nlen, char **aseq, int *order );
+extern void veryfastsupg_double_outtree( int nseq, double **eff, int ***topol, double **len, char **name );
+extern void cpmx_ribosum( char **seq, char **seqr, char *dir, float **cpmx, double *eff, int lgth, int clus );
+extern void rnaalifoldcall( char **seq, int nseq, RNApair **pairprob );
+extern void readpairfoldalign( FILE *fp, char *seq1, char *seq2, char *aln1, char *aln2, int q1, int q2, int *of1, int *of2, int sumlen );
+extern void write1seq( FILE *fp, char *aseq );
+extern void assignstrweight( int nseq, double *strweight, Node *stopol, int ***topol, int step, int LorR, char *kozoari, double *seqweight );
+extern void cutData( FILE *, int **, char **, int * );
+extern void cutAlignment( FILE *, int **, char **, int *, char **, char ** );
+extern void catData( FILE * );
+extern void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *isalignedpt );
+extern void getnumlen_nogap_outallreg( FILE *fp, int *nlenminpt );
+extern double plainscore( int nseq, char **seq );
+extern void eq2dash( char *s );
+extern void findnewgaps( int n, char **seq, int *gaplen );
+extern void findcommongaps( int, char **, int * );
+extern void adjustgapmap( int, int *, char * );
+extern void insertnewgaps( int njob, int *alreadyaligned, char **seq, int *ex1, int *ex2, int *gaplen, int *gapmap, int alloclen, char alg );
+extern void restorecommongaps( int n, char **seq, int *top0, int *top1, int *gaplen, int alloclen );
+extern int samemember( int *mem, int *cand );
+extern int includemember( int *mem, int *cand );
+extern void profilealignment( int n0, int n1, int n2, char **aln0, char **aln1, char **aln2, int alloclen, char alg );
diff --git a/binaries/src/mafft/core/genGalign11.c b/binaries/src/mafft/core/genGalign11.c
new file mode 100644 (file)
index 0000000..3a3edb6
--- /dev/null
@@ -0,0 +1,486 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char *seq2 = s2[0];
+       int *intptr = amino_dis[(int)s1[0][i1]];
+
+       while( lgth2-- )
+               *match++ = intptr[(int)*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+static float genGtracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijpi, int **ijpj )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, limk;
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijpi[i][0] = -1;
+               ijpj[i][0] = -1; // ???
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+               ijpi[0][j] = -1; // ???
+        ijpj[0][j] = -1;
+    }
+
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = lgth1; jin = lgth2;
+       limk = lgth1+lgth2 + 1;
+       for( k=0; k<limk; k++ ) 
+       {
+               ifi = ( ijpi[iin][jin] );
+               jfi = ( ijpj[iin][jin] );
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+
+//             fprintf( stdout, "mseq1 = %s\n", mseq1[0] );
+//             fprintf( stdout, "mseq2 = %s\n", mseq2[0] );
+
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+
+float genG__align11( char **seq1, char **seq2, int alloclen )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+       float fpenalty = (float)penalty;
+       float fpenalty_OP = (float)penalty_OP;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+#if 1
+       float *wtmp;
+       int *ijpipt;
+       int *ijpjpt;
+       float *mjpt, *Mjpt, *prept, *curpt;
+       int *mpjpt, *Mpjpt;
+#endif
+       static float mi, *m;
+       static float Mi, *largeM;
+       static int **ijpi;
+       static int **ijpj;
+       static int mpi, *mp;
+       static int Mpi, *Mp;
+       static float *w1, *w2;
+       static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static char **mseq;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+       float tbk;
+       int tbki, tbkj;
+
+       wm = 0.0;
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+
+
+       if( lgth1 <= 0 || lgth2 <= 0 )
+       {
+               fprintf( stderr, "WARNING (g11): lgth1=%d, lgth2=%d\n", lgth1, lgth2 );
+       }
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+                       FreeFloatVec( largeM );
+                       FreeIntVec( Mp );
+
+                       FreeCharMtx( mseq );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+               largeM = AllocateFloatVec( ll2+2 );
+               Mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+                       FreeIntMtx( commonJP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+               commonJP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijpi = commonIP;
+       ijpj = commonJP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+       if( outgap == 1 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += fpenalty;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += fpenalty;
+               }
+       }
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+               largeM[j] = currentw[j-1]; Mp[j] = 0;
+       }
+
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0;               // lgth2==0 no toki error
+       else
+               lastverticalw[0] = currentw[lgth2-1]; // lgth2==0 no toki error
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+               Mi = previousw[0]; Mpi = 0;
+
+               ijpipt = ijpi[i] + 1;
+               ijpjpt = ijpj[i] + 1;
+               mjpt = m + 1;
+               Mjpt = largeM + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               Mpjpt = Mp + 1;
+               tbk = -9999999.9;
+               tbki = 0;
+               tbkj = 0;
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       wm = *prept;
+                       *ijpipt = i-1;
+                       *ijpjpt = j-1;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+fpenalty) > wm )
+                       {
+                               wm = g;
+//                             *ijpipt = i - 1; // iranai
+                               *ijpjpt = mpi;
+                       }
+                       if( (g=*prept) >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt + fpenalty) > wm )
+                       {
+                               wm = g;
+                               *ijpipt = *mpjpt;
+                               *ijpjpt = j - 1; //IRU!
+                       }
+                       if( (g=*prept) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 1
+                       g =  tbk + fpenalty_OP;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijpipt = tbki;
+                               *ijpjpt = tbkj;
+//                             fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
+                       }
+                       if( Mi > tbk )
+                       {
+                               tbk = Mi; //error desu.
+                               tbki = i-1;
+                               tbkj = Mpi;
+                       }
+                       if( *Mjpt > tbk )
+                       {
+                               tbk = *Mjpt;
+                               tbki = *Mpjpt;
+                               tbkj = j-1;
+                       }
+
+                       if( *prept > *Mjpt )
+                       {
+                               *Mjpt = *prept;
+                               *Mpjpt = i-1;
+                       }
+                       if( *prept > Mi )
+                       {
+                               Mi = *prept;
+                               Mpi = j-1;
+                       }
+
+#endif
+
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijpipt++;
+                       ijpjpt++;
+                       mjpt++;
+                       Mjpt++;
+                       prept++;
+                       mpjpt++;
+                       Mpjpt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1]; // lgth2==0 no toki error
+       }
+#if 0
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       fprintf( stdout, "i,j=%d,%d - ijpi,ijpj=%d,%d\n", i, j, ijpi[i][j], ijpj[i][j] );
+               }
+       }
+       fflush( stdout );
+#endif
+
+       genGtracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+#if 0
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+       fprintf( stderr, "wm = %f\n", wm );
+#endif
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/genalign11.c b/binaries/src/mafft/core/genalign11.c
new file mode 100644 (file)
index 0000000..29cb6fd
--- /dev/null
@@ -0,0 +1,661 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define DEBUG2 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+static TLS int localstop;
+
+#if 1
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 ) 
+{
+       char tmpc = s1[0][i1];
+       char *seq2 = s2[0];
+
+       while( lgth2-- )
+               *match++ = amino_dis[(int)tmpc][(int)*seq2++];
+}
+#else
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(*s1)[i1]][(*s2)[j]];
+}
+#endif
+
+#if 0
+static void match_calc_bk( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       int count = 0;
+
+       if( initialize )
+       {
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+#if 0 
+       {
+               float *fpt, **fptpt, *fpt2;
+               int *ipt, **iptpt;
+               fpt2 = match;
+               iptpt = cpmxpdn;
+               fptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *fpt2 = 0.0;
+                       ipt=*iptpt,fpt=*fptpt;
+                       while( *ipt > -1 )
+                               *fpt2 += scarr[*ipt++] * *fpt++;
+                       fpt2++,iptpt++,fptpt++;
+               } 
+       }
+#else
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+#endif
+
+static float gentracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijpi, int **ijpj, int *off1pt, int *off2pt, int endi, int endj )
+{
+       int i, j, l, iin, jin, lgth1, lgth2, k, limk;
+       int ifi=0, jfi=0; // by D.Mathog
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijpi[i][0] = localstop;
+        ijpj[i][0] = localstop;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijpi[0][j] = localstop;
+        ijpj[0][j] = localstop;
+    }
+
+       mseq1[0] += lgth1+lgth2;
+       *mseq1[0] = 0;
+       mseq2[0] += lgth1+lgth2;
+       *mseq2[0] = 0;
+       iin = endi; jin = endj;
+       limk = lgth1+lgth2;
+       for( k=0; k<=limk; k++ ) 
+       {
+
+               ifi = ( ijpi[iin][jin] );
+               jfi = ( ijpj[iin][jin] );
+               l = iin - ifi;
+//             if( ijpi[iin][jin] < 0 || ijpj[iin][jin] < 0 )
+//             {
+//                     fprintf( stderr, "skip! %d-%d\n", ijpi[iin][jin], ijpj[iin][jin] );
+//                     fprintf( stderr, "1: %c-%c\n", seq1[0][iin], seq1[0][ifi] );
+//                     fprintf( stderr, "2: %c-%c\n", seq2[0][jin], seq2[0][jfi] );
+//             }
+               while( --l ) 
+               {
+                       *--mseq1[0] = seq1[0][ifi+l];
+                       *--mseq2[0] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mseq1[0] = *gap;
+                       *--mseq2[0] = seq2[0][jfi+l];
+                       k++;
+               }
+
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mseq1[0] = seq1[0][ifi];
+               *--mseq2[0] = seq2[0][jfi];
+
+               if( ijpi[ifi][jfi] == localstop ) break;
+               if( ijpj[ifi][jfi] == localstop ) break; 
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
+       if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
+
+//     fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
+
+
+       return( 0.0 );
+}
+
+
+float genL__align11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj; 
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijpipt;
+       int *ijpjpt;
+       float *mjpt, *Mjpt, *prept, *curpt;
+       int *mpjpt, *Mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS float Mi, *largeM;
+       static TLS int **ijpi;
+       static TLS int **ijpj;
+       static TLS int mpi, *mp;
+       static TLS int Mpi, *Mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float maxwm;
+       float tbk;
+       int tbki, tbkj;
+       int endali, endalj;
+//     float localthr = 0.0;
+//     float localthr2 = 0.0;
+       float fpenalty = (float)penalty;
+       float fpenalty_OP = (float)penalty_OP;
+       float fpenalty_ex = (float)penalty_ex;
+//     float fpenalty_EX = (float)penalty_EX;
+       float foffset = (float)offset;
+       float localthr = -foffset;
+       float localthr2 = -foffset;
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+                       free( mseq1 );
+                       free( mseq2 );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+                       free( largeM );
+                       free( Mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+
+               }
+               return( 0.0 );
+       }
+
+
+
+//     fprintf( stderr, "@@@@@@@@@@@@@ penalty_OP = %f, penalty_EX = %f, pelanty = %f\n", fpenalty_OP, fpenalty_EX, fpenalty );
+
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+                       FreeFloatVec( largeM );
+                       FreeIntVec( Mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+               largeM = AllocateFloatVec( ll2+2 );
+               Mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       mseq1[0] = mseq[0];
+       mseq2[0] = mseq[1];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+                       FreeIntMtx( commonJP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+               commonJP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijpi = commonIP;
+       ijpj = commonJP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+               largeM[j] = currentw[j-1]; Mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999999999.9;
+       endali = endalj = 0;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+               Mi = previousw[0]; Mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+               ijpipt = ijpi[i] + 1;
+               ijpjpt = ijpj[i] + 1;
+               mjpt = m + 1;
+               Mjpt = largeM + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               Mpjpt = Mp + 1;
+               tbk = -999999.9;
+               tbki = 0;
+               tbkj = 0;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijpipt = i-1;
+                       *ijpjpt = j-1;
+
+
+//                     fprintf( stderr, "i,j=%d,%d %c-%c\n", i, j, seq1[0][i], seq2[0][j] );
+//                     fprintf( stderr, "wm=%f\n", wm );
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijpipt = i - 1; 
+                               *ijpjpt = mpi;
+                       }
+                       g = *prept;
+                       if( g > mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = *mjpt + fpenalty;
+#if 0
+                       fprintf( stderr, "m%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijpipt = *mpjpt;
+                               *ijpjpt = j - 1; //IRU!
+                       }
+                       g = *prept;
+                       if( g > *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+
+                       g =  tbk + fpenalty_OP; 
+//                     g =  tbk; 
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijpipt = tbki;
+                               *ijpjpt = tbkj;
+//                             fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
+                       }
+//                     g = Mi;
+                       if( Mi > tbk )
+                       {
+                               tbk = Mi; //error desu.
+                               tbki = i-1;
+                               tbkj = Mpi;
+                       }
+//                     g = *Mjpt;
+                       if( *Mjpt > tbk )
+                       {
+                               tbk = *Mjpt;
+                               tbki = *Mpjpt;
+                               tbkj = j-1;
+                       }
+//                     tbk += fpenalty_EX;// + foffset;
+
+//                     g = *prept;
+                       if( *prept > *Mjpt )
+                       {
+                               *Mjpt = *prept;
+                               *Mpjpt = i-1;
+                       }
+//                     *Mjpt += fpenalty_EX;// + foffset;
+
+//                     g = *prept;
+                       if( *prept > Mi )
+                       {
+                               Mi = *prept;
+                               Mpi = j-1;
+                       }
+//                     Mi += fpenalty_EX;// + foffset;
+
+
+//                     fprintf( stderr, "wm=%f, tbk=%f(%c-%c), mi=%f, *mjpt=%f\n", wm, tbk, seq1[0][tbki], seq2[0][tbkj], mi, *mjpt );
+//                     fprintf( stderr, "ijp = %c,%c\n", seq1[0][abs(*ijpipt)], seq2[0][abs(*ijpjpt)] );
+
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               *ijpipt = localstop;
+//                             *ijpjpt = localstop; 
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt += wm;
+                       ijpipt++;
+                       ijpjpt++;
+                       mjpt++;
+                       Mjpt++;
+                       prept++;
+                       mpjpt++;
+                       Mpjpt++;
+                       curpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+
+#if DEBUG2
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+
+       if( ijpi[endali][endalj] == localstop ) // && ijpj[endali][endalj] == localstop )
+       {
+               strcpy( seq1[0], "" );
+               strcpy( seq2[0], "" );
+               *off1pt = *off2pt = 0;
+               return( 0.0 );
+       }
+
+
+       gentracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj, off1pt, off2pt, endali, endalj );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       strcpy( seq1[0], mseq1[0] );
+       strcpy( seq2[0], mseq2[0] );
+
+#if 0
+       fprintf( stderr, "\n" );
+       fprintf( stderr, ">\n%s\n", mseq1[0] );
+       fprintf( stderr, ">\n%s\n", mseq2[0] );
+#endif
+
+
+       return( maxwm );
+}
+
diff --git a/binaries/src/mafft/core/getlag.c b/binaries/src/mafft/core/getlag.c
new file mode 100644 (file)
index 0000000..d37c2d8
--- /dev/null
@@ -0,0 +1,461 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'C';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       scoremtx = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'D':
+                                       scoremtx = -1;
+                                       break;
+                               case 'P':
+                                       scoremtx = 0;
+                                       break;
+                               case 'i':
+                                       contin = 1;
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 's':
+                                       treemethod = 's';
+                                       break;
+                               case 'x':
+                                       treemethod = 'x';
+                                       break;
+                               case 'p':
+                                       treemethod = 'p';
+                                       break;
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+                               case 'o':
+                                       outgap = 0;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+       readOtherOptions( &ppid, &fftThreshold, &fftWinSize );
+}
+
+
+void treebase( char **name, int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double **mtx, int ***topol, double **len, double **eff, int alloclen )
+{
+       int i, j, l;
+       int clus1, clus2;
+       int s1, s2, r1, r2;
+       float pscore;
+       static char *indication1, *indication2;
+       static char **name1, **name2;
+       static double **partialmtx = NULL;
+       static int ***partialtopol = NULL;
+       static double **partiallen = NULL;
+       static double **partialeff = NULL;
+       static double *effarr = NULL;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+#if 0
+       char pair[njob][njob];
+#else
+       static char **pair;
+#endif
+       if( partialtopol == NULL ) 
+       {
+               partialmtx = AllocateDoubleMtx( njob, njob );
+               partialtopol = AllocateIntCub( njob, 2, njob );
+               partialeff = AllocateDoubleMtx( njob, njob );
+               partiallen = AllocateDoubleMtx( njob, 2 );
+               effarr = AllocateDoubleVec( njob );
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               indication1 = AllocateCharVec( njob*3+100 );
+               indication2 = AllocateCharVec( njob*3+100 );
+               name1 = AllocateCharMtx( njob, B+1 );
+               name2 = AllocateCharMtx( njob, B+1 );
+#if 0
+#else
+               pair = AllocateCharMtx( njob, njob );
+#endif
+       }
+
+       if( checkC )
+               for( i=0; i<njob; i++ ) fprintf( stderr, "eff in tb-%d %f\n", i, eff[i][i] );
+
+       for( i=0; i<njob; i++ ) effarr[i] = eff[i][i];
+       for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
+
+       if( checkC )
+               for( i=0; i<njob; i++ ) fprintf( stderr, "effarr for aseq-%d %f\n", i, effarr[i] );
+
+       writePre( njob, name, nlen, aseq, 0 );
+
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
+       for( i=0; i<njob; i++ ) pair[i][i] = 1;
+       for( l=0; l<njob-1; l++ )
+       {
+               s1 = topol[l][0][0];
+               for( i=0; (r1=topol[l][0][i])>-1; i++ ) 
+                       if( pair[s1][r1] != 1 ) exit( 1 );
+               s2 = topol[l][1][0];
+               for( i=0; (r2=topol[l][1][i])>-1; i++ ) 
+                       if( pair[s2][r2] != 1 ) exit( 1 );
+
+               clus1 = conjuction( pair, s1, aseq, mseq1, effarr1, effarr, name, name1, indication1 );
+               clus2 = conjuction( pair, s2, aseq, mseq2, effarr2, effarr, name, name2, indication2 );
+               fprintf( trap_g, "\nSTEP-%d\n", l );
+               fprintf( trap_g, "group1 = %s\n", indication1 );
+               fprintf( trap_g, "group2 = %s\n", indication2 );
+
+               fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 );
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+
+               if( checkC )
+                       for( i=0; i<clus1; i++ ) fprintf( stderr, "STEP%d-eff for mseq1-%d %f\n", l+1, i, effarr1[i] );
+/*
+               fprintf( stderr, "before align all\n" );
+               display( aseq, njob );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+               pscore = Fgetlag( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+
+               for( i=0; (r2=topol[l][1][i])>-1; i++ ) 
+               {
+                       pair[s1][r2] = 1;
+                       pair[s2][r2] = 0;
+               }
+
+               writePre( njob, name, nlen, aseq, 0 );
+
+               if( disp ) display( aseq, njob );
+               fprintf( stderr, "\n" );
+
+       }
+}
+
+static void WriteOptions( FILE *fp )
+{
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+       if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+       else if( scoremtx ==  1 ) fprintf( fp, "Dayhoff( machigai ga aru )\n" );
+       else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       else if( scoremtx == -1 ) fprintf( fp, "DNA\n" );
+
+    if( scoremtx == 0 || scoremtx == -1 )
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    else
+        fprintf( fp, "Gap Penalty = %+5.2f\n", (double)ppenalty/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Apgorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'x' )
+               fprintf( fp, "Tree = UPGMA (3).\n" );
+       else if( treemethod == 's' )
+               fprintf( fp, "Tree = UPGMA (2).\n" );
+       else if( treemethod == 'p' )
+               fprintf( fp, "Tree = UPGMA (1).\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( scoremtx == -1 )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char **name, **seq;
+       static char **mseq1, **mseq2;
+       static char **aseq;
+       static char **bseq;
+       static double **pscore;
+       static double **eff;
+       static double **node0, **node1;
+       int i, j;
+       static int ***topol;
+       static double **len;
+       FILE *prep;
+       char c;
+       int alloclen;
+
+       arguments( argc, argv );
+       getnumlen( stdin );
+       rewind( stdin );
+
+       name = AllocateCharMtx( njob, B+1 );
+       seq = AllocateCharMtx( njob, nlenmax*5+1 );
+       aseq = AllocateCharMtx( njob, nlenmax*5+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*5+1 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       alloclen = nlenmax*5;
+
+       topol = AllocateIntCub( njob, 2, njob );
+       len = AllocateDoubleMtx( njob, 2 );
+       pscore = AllocateDoubleMtx( njob, njob );
+       eff = AllocateDoubleMtx( njob, njob );
+       node0 = AllocateDoubleMtx( njob, njob );
+       node1 = AllocateDoubleMtx( njob, njob );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData_pointer( stdin, name, nlen, seq );
+#endif
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+       writePre( njob, name, nlen, seq, 0 );
+
+       if( tbutree == 0 )
+       {
+               for( i=1; i<njob; i++ ) 
+               {
+                       if( nlen[i] != nlen[0] ) 
+                       {
+                               fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
+                               exit( 1 );
+                       }
+               }
+               for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+               {
+               /*
+                       pscore[i][j] = (double)score_calc1( seq[i], seq[j] );
+               */
+                       pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+               }
+       }
+       else
+       {
+               fprintf( stderr, "Loading 'hat2' ... " );
+               prep = fopen( "hat2", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat2." );
+               readhat2_pointer( prep, njob, name, pscore );
+               fclose( prep );
+               fprintf( stderr, "done.\n" );
+
+#if 0
+               prep = fopen( "hat2_check", "w" );
+               WriteHat2( prep, njob, name, pscore );
+               fclose( prep );
+#endif
+
+       }
+
+       fprintf( stderr, "Constructing dendrogram ... " );
+       if( treemethod == 'x' )
+               supg( njob, pscore, topol, len );
+       else if( treemethod == 's' )
+               spg( njob, pscore, topol, len );
+       else if( treemethod == 'p' )
+               upg2( njob, pscore, topol, len );
+       else 
+               ErrorExit( "Incorrect tree\n" );
+       fprintf( stderr, "done.\n" );
+
+       countnode( njob, topol, node0 );
+       if( tbrweight )
+       {
+               weight = 3; 
+               utree = 0; counteff( njob, topol, len, eff ); utree = 1;
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) eff[i][i] = 1.0;
+       }
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+       treebase( name, nlen, bseq, aseq, mseq1, mseq2, pscore, topol, len, eff, alloclen );
+
+       fprintf( trap_g, "done\n" );
+       fclose( trap_g );
+
+       writePre( njob, name, nlen, aseq, !contin );
+       writeData_pointer( stdout, njob, name, nlen, aseq );
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/io.c b/binaries/src/mafft/core/io.c
new file mode 100644 (file)
index 0000000..75520d2
--- /dev/null
@@ -0,0 +1,4600 @@
+#include "mltaln.h"
+
+static int upperCase = 0;
+
+#define DEBUG   0
+#define IODEBUG 0
+
+char creverse( char f )
+{
+       static char *table = NULL;
+       if( table == NULL )
+       {
+               table = AllocateCharVec(0x80);
+               table['a'] = 't';
+               table['c'] = 'g';
+               table['g'] = 'c';
+               table['t'] = 'a';
+               table['u'] = 'a';
+               table['m'] = 'k';
+               table['r'] = 'y';
+               table['w'] = 'w';
+               table['s'] = 's';
+               table['y'] = 'r';
+               table['k'] = 'm';
+               table['v'] = 'b';
+               table['h'] = 'd';
+               table['d'] = 'h';
+               table['b'] = 'v';
+               table['n'] = 'n';
+               table['-'] = '-';
+               table['.'] = '.';
+               table['*'] = '*';
+       }
+       return( table[(int)f] );
+}
+
+void sreverse( char *r, char *s )
+{
+       r += strlen( s );
+       *r-- = 0;
+       while( *s )
+               *r-- = creverse( *s++ );
+//             *r-- = ( *s++ );
+}
+
+void gappick_samestring( char *seq )
+{
+       char *aseq = seq;
+
+       for( ; *seq != 0; seq++ )
+       {
+               if( *seq != '-' )
+                       *aseq++ = *seq;
+       }
+       *aseq = 0;
+}
+
+#if 0
+
+static int addlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       int iscore;
+       int isumscore;
+       int sumoverlap;
+       LocalHom *tmppt;
+       int st;
+       int nlocalhom = 0;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+       isumscore = 0;
+       sumoverlap = 0;
+
+#if 0
+       fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom );
+       fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 );
+       fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 );
+       fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip );
+       fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 );
+#endif
+
+       if( skip )
+       {
+               while( --skip > 0 ) localhompt = localhompt->next;
+               localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+               localhompt = localhompt->next;
+//             fprintf( stderr, "tmppt = %p, localhompt = %p\n", tmppt, localhompt );
+       }
+       tmppt = localhompt;
+
+       st = 0;
+       iscore = 0;
+       while( *pt1 != 0 )
+       {
+//             fprintf( stderr, "In in while loop\n" );
+//             fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       isumscore += iscore;
+                       sumoverlap += end2-start2+1;
+#else
+                       tmppt->overlapaa   = end2-start2+1;
+                       tmppt->opt = iscore * 5.8 / 600;
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+                       fprintf( stderr, "iscore (1)= %d\n", iscore );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+                       iscore = 0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]];
+//                     fprintf( stderr, "%c-%c, score(0) = %d\n", *pt1, *pt2, iscore );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+
+       if( st )
+       {
+               if( nlocalhom++ > 0 )
+               {
+//                     fprintf( stderr, "reallocating ...\n" );
+                       tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                     fprintf( stderr, "done\n" );
+                       tmppt = tmppt->next;
+                       tmppt->next = NULL;
+               }
+               end1 = pos1 - 1;
+               end2 = pos2 - 1;
+               tmppt->start1 = start1;
+               tmppt->start2 = start2;
+               tmppt->end1   = end1  ;
+               tmppt->end2   = end2  ;
+
+#if 1
+               isumscore += iscore;
+               sumoverlap += end2-start2+1;
+#else
+               tmppt->overlapaa   = end2-start2+1;
+               tmppt->opt = (double)iscore * 5.8 / 600;
+               tmppt->overlapaa   = overlapaa;
+               tmppt->opt = (double)opt;
+#endif
+#if 0
+               fprintf( stderr, "score (2)= %d\n", iscore );
+               fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+               fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+       }
+
+       for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
+       {
+               tmppt->overlapaa = sumoverlap;
+               tmppt->opt = (double)sumscore * 5.8 / 600 / sumoverlap;
+       }
+       return( nlocalhom );
+}
+
+#endif
+
+
+
+static int addlocalhom_r( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa, int skip )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       double score;
+       double sumscore;
+       int sumoverlap;
+       LocalHom *tmppt = NULL; // by D.Mathog, a guess
+       int st;
+       int nlocalhom = 0;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+       sumscore = 0.0;
+       sumoverlap = 0;
+       start1 = 0; // by D.Mathog, a guess
+       start2 = 0; // by D.Mathog, a guess
+
+#if 0
+       fprintf( stderr, "nlocalhom = %d in addlocalhom\n", nlocalhom );
+       fprintf( stderr, "al1 = %s, al2 = %s\n", al1, al2 );
+       fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 );
+       fprintf( stderr, "localhopt = %p, skip = %d\n", localhompt, skip );
+#endif
+       fprintf( stderr, "pt1 = \n%s\n, pt2 = \n%s\n", pt1, pt2 );
+
+       if( skip )
+       {
+               while( --skip > 0 ) localhompt = localhompt->next;
+               localhompt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+               localhompt = localhompt->next;
+               fprintf( stderr, "tmppt = %p, localhompt = %p\n", (void *)tmppt, (void *)localhompt );
+       }
+       tmppt = localhompt;
+
+       st = 0;
+       score = 0.0;
+       while( *pt1 != 0 )
+       {
+               fprintf( stderr, "In in while loop\n" );
+               fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       sumscore += score;
+                       sumoverlap += end2-start2+1;
+#else
+                       tmppt->overlapaa   = end2-start2+1;
+                       tmppt->opt = score * 5.8 / 600;
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+                       fprintf( stderr, "score (1)= %f\n", score );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+                       score = 0.0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]];
+//                     fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+       if( nlocalhom++ > 0 )
+       {
+//             fprintf( stderr, "reallocating ...\n" );
+               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//             fprintf( stderr, "done\n" );
+               tmppt = tmppt->next;
+               tmppt->next = NULL;
+       }
+       end1 = pos1 - 1;
+       end2 = pos2 - 1;
+       tmppt->start1 = start1;
+       tmppt->start2 = start2;
+       tmppt->end1   = end1  ;
+       tmppt->end2   = end2  ;
+
+#if 1
+       sumscore += score;
+       sumoverlap += end2-start2+1;
+#else
+       tmppt->overlapaa   = end2-start2+1;
+       tmppt->opt = score * 5.8 / 600;
+       tmppt->overlapaa   = overlapaa;
+       tmppt->opt = (double)opt;
+#endif
+
+       fprintf( stderr, "score (2)= %f\n", score );
+       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+
+       for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
+       {
+               tmppt->overlapaa = sumoverlap;
+               tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
+       }
+       return( nlocalhom );
+}
+void putlocalhom3( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       double score;
+       double sumscore;
+       int sumoverlap;
+       LocalHom *tmppt;
+       LocalHom *subnosento;
+       int st;
+       int saisho;
+
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+       sumscore = 0.0;
+       sumoverlap = 0;
+       start1 = 0; // by Mathog, a guess
+       start2 = 0; // by Mathog, a guess
+
+       subnosento = localhompt;
+       while( subnosento->next ) subnosento = subnosento->next;
+       tmppt = subnosento;
+
+       saisho = ( localhompt->nokori == 0 );
+
+       fprintf( stderr, "localhompt = %p\n", (void *)localhompt );
+       fprintf( stderr, "tmppt = %p\n", (void *)tmppt );
+       fprintf( stderr, "subnosento = %p\n", (void *)subnosento );
+
+       st = 0;
+       score = 0.0;
+       while( *pt1 != 0 )
+       {
+//             fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( localhompt->nokori++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       if( divpairscore )
+                       {
+                               tmppt->overlapaa   = end2-start2+1;
+                               tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
+                       }
+                       else
+                       {
+                               sumscore += score;
+                               sumoverlap += end2-start2+1;
+                       }
+#else
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+                       fprintf( stderr, "score (1)= %f\n", score );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+                       score = 0.0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
+//                     fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+       if( *(pt1-1) != '-' && *(pt2-1) != '-'  )
+       {
+               if( localhompt->nokori++ > 0 )
+               {
+//                     fprintf( stderr, "reallocating ...\n" );
+                       tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                     fprintf( stderr, "done\n" );
+                       tmppt = tmppt->next;
+                       tmppt->next = NULL;
+               }
+
+               end1 = pos1 - 1;
+               end2 = pos2 - 1;
+               tmppt->start1 = start1;
+               tmppt->start2 = start2;
+               tmppt->end1   = end1  ;
+               tmppt->end2   = end2  ;
+
+
+#if 1
+               if( divpairscore )
+               {
+                       tmppt->overlapaa   = end2-start2+1;
+                       tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
+               }
+               else
+               {
+                       sumscore += score;
+                       sumoverlap += end2-start2+1;
+               }
+#else
+               tmppt->overlapaa   = overlapaa;
+               tmppt->opt = (double)opt;
+#endif
+
+#if 0
+               fprintf( stderr, "score (2)= %f\n", score );
+               fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+               fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+       }
+
+       fprintf( stderr, "sumscore = %f\n", sumscore );
+       if( !divpairscore )
+       {
+
+               if( !saisho ) subnosento = subnosento->next;
+               for( tmppt=subnosento; tmppt; tmppt=tmppt->next )
+               {
+                       tmppt->overlapaa = sumoverlap;
+                       tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
+                       fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
+               }
+       }
+}
+void putlocalhom_ext( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       int iscore;
+       int isumscore;
+       int sumoverlap;
+       LocalHom *tmppt = localhompt;
+       int nlocalhom = 0;
+       int st;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+
+       isumscore = 0;
+       sumoverlap = 0;
+       start1 = 0; // by D.Mathog, a guess
+       start2 = 0; // by D.Mathog, a guess
+
+       st = 0;
+       iscore = 0;
+       while( *pt1 != 0 )
+       {
+//             fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       if( divpairscore )
+                       {
+                               tmppt->overlapaa   = end2-start2+1;
+                               tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600;
+                       }
+                       else
+                       {
+                               isumscore += iscore;
+                               sumoverlap += end2-start2+1;
+                       }
+#else
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+                       fprintf( stderr, "iscore (1)= %d\n", iscore );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+                       iscore = 0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
+//                     fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+       if( *(pt1-1) != '-' && *(pt2-1) != '-'  )
+       {
+               if( nlocalhom++ > 0 )
+               {
+//                     fprintf( stderr, "reallocating ...\n" );
+                       tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                     fprintf( stderr, "done\n" );
+                       tmppt = tmppt->next;
+                       tmppt->next = NULL;
+               }
+               end1 = pos1 - 1;
+               end2 = pos2 - 1;
+               tmppt->start1 = start1;
+               tmppt->start2 = start2;
+               tmppt->end1   = end1  ;
+               tmppt->end2   = end2  ;
+       
+#if 1
+               if( divpairscore )
+               {
+                       tmppt->overlapaa   = end2-start2+1;
+                       tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600;
+               }
+               else
+               {
+                       isumscore += iscore;
+                       sumoverlap += end2-start2+1;
+               }
+#else
+               tmppt->overlapaa   = overlapaa;
+               tmppt->opt = (double)opt;
+#endif
+
+#if 0
+               fprintf( stderr, "iscore (2)= %d\n", iscore );
+               fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+               fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+       }
+
+       if( !divpairscore )
+       {
+               for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
+               {
+                       tmppt->overlapaa = sumoverlap;
+//                     tmppt->opt = (double)isumscore * 5.8 / ( 600 * sumoverlap );
+                       tmppt->opt = (double)600 * 5.8 / 600;
+//                     fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
+               }
+       }
+}
+
+void putlocalhom_str( char *al1, char *al2, double *equiv, double scale, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
+{
+       int posinaln, pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       int isumscore;
+       int sumoverlap;
+       LocalHom *tmppt = localhompt;
+       int nlocalhom = 0;
+//     int st;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+       isumscore = 0;
+       sumoverlap = 0;
+       start1 = 0; // by D.Mathog, a guess
+       start2 = 0; // by D.Mathog, a guess
+
+       posinaln = 0;
+       while( *pt1 != 0 )
+       {
+               if( *pt1 != '-' && *pt2 != '-' && equiv[posinaln] > 0.0 )
+               {
+                       start1 = end1 = pos1; start2 = end2 = pos2;
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ... (posinaln=%d)\n", posinaln );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+                       tmppt->overlapaa   = 1;
+//                     tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600;
+                       tmppt->opt = equiv[posinaln] * scale;
+//                     fprintf( stdout, "*pt1=%c, *pt2=%c, equiv=%f\n", *pt1, *pt2, equiv[posinaln] );
+
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+               posinaln++;
+       }
+}
+
+void putlocalhom2( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       int iscore;
+       int isumscore;
+       int sumoverlap;
+       LocalHom *tmppt = localhompt;
+       int nlocalhom = 0;
+       int st;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+
+       isumscore = 0;
+       sumoverlap = 0;
+       start1 = 0; // by D.Mathog, a guess
+       start2 = 0; // by D.Mathog, a guess
+
+       st = 0;
+       iscore = 0;
+       while( *pt1 != 0 )
+       {
+//             fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       if( divpairscore )
+                       {
+                               tmppt->overlapaa   = end2-start2+1;
+                               tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600;
+                       }
+                       else
+                       {
+                               isumscore += iscore;
+                               sumoverlap += end2-start2+1;
+                       }
+#else
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+                       fprintf( stderr, "iscore (1)= %d\n", iscore );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+                       iscore = 0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       iscore += n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
+//                     fprintf( stderr, "%c-%c, iscore(0) = %d\n", *pt1, *pt2, iscore );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+       if( *(pt1-1) != '-' && *(pt2-1) != '-'  )
+       {
+               if( nlocalhom++ > 0 )
+               {
+//                     fprintf( stderr, "reallocating ...\n" );
+                       tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                     fprintf( stderr, "done\n" );
+                       tmppt = tmppt->next;
+                       tmppt->next = NULL;
+               }
+               end1 = pos1 - 1;
+               end2 = pos2 - 1;
+               tmppt->start1 = start1;
+               tmppt->start2 = start2;
+               tmppt->end1   = end1  ;
+               tmppt->end2   = end2  ;
+       
+#if 1
+               if( divpairscore )
+               {
+                       tmppt->overlapaa   = end2-start2+1;
+                       tmppt->opt = (double)iscore / tmppt->overlapaa * 5.8 / 600;
+               }
+               else
+               {
+                       isumscore += iscore;
+                       sumoverlap += end2-start2+1;
+               }
+#else
+               tmppt->overlapaa   = overlapaa;
+               tmppt->opt = (double)opt;
+#endif
+
+#if 0
+               fprintf( stderr, "iscore (2)= %d\n", iscore );
+               fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+               fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+       }
+
+       if( !divpairscore )
+       {
+               for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
+               {
+                       tmppt->overlapaa = sumoverlap;
+                       tmppt->opt = (double)isumscore * 5.8 / ( 600 * sumoverlap );
+//                     fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
+               }
+       }
+}
+void putlocalhom( char *al1, char *al2, LocalHom *localhompt, int off1, int off2, int opt, int overlapaa )
+{
+       int pos1, pos2, start1, start2, end1, end2;
+       char *pt1, *pt2;
+       double score;
+       double sumscore;
+       int sumoverlap;
+       LocalHom *tmppt = localhompt;
+       int nlocalhom = 0;
+       int st;
+       pt1 = al1; pt2 = al2;
+       pos1 = off1; pos2 = off2;
+
+
+       sumscore = 0.0;
+       sumoverlap = 0;
+       start1 = 0; // by D.Mathog, a guess
+       start2 = 0; // by D.Mathog, a guess
+
+       st = 0;
+       score = 0.0;
+       while( *pt1 != 0 )
+       {
+//             fprintf( stderr, "pt = %c, %c, st=%d\n", *pt1, *pt2, st );
+               if( st == 1 && ( *pt1 == '-' || *pt2 == '-' ) )
+               {
+                       end1 = pos1 - 1;
+                       end2 = pos2 - 1;
+
+                       if( nlocalhom++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating ...\n" );
+                               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//                             fprintf( stderr, "done\n" );
+                               tmppt = tmppt->next;
+                               tmppt->next = NULL;
+                       }
+                       tmppt->start1 = start1;
+                       tmppt->start2 = start2;
+                       tmppt->end1   = end1  ;
+                       tmppt->end2   = end2  ;
+
+#if 1
+                       if( divpairscore )
+                       {
+                               tmppt->overlapaa   = end2-start2+1;
+                               tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
+                       }
+                       else
+                       {
+                               sumscore += score;
+                               sumoverlap += end2-start2+1;
+                       }
+#else
+                       tmppt->overlapaa   = overlapaa;
+                       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+                       fprintf( stderr, "score (1)= %f\n", score );
+                       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+                       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+                       score = 0.0;
+                       st = 0;
+               }
+               else if( *pt1 != '-' && *pt2 != '-' )
+               {
+                       if( st == 0 )
+                       {
+                               start1 = pos1; start2 = pos2;
+                               st = 1;
+                       }
+                       score += (double)n_dis[(int)amino_n[(int)*pt1]][(int)amino_n[(int)*pt2]]; // - offset ¤Ï¤¤¤é¤Ê¤¤¤«¤â
+//                     fprintf( stderr, "%c-%c, score(0) = %f\n", *pt1, *pt2, score );
+               }
+               if( *pt1++ != '-' ) pos1++;
+               if( *pt2++ != '-' ) pos2++;
+       }
+       if( nlocalhom++ > 0 )
+       {
+//             fprintf( stderr, "reallocating ...\n" );
+               tmppt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+//             fprintf( stderr, "done\n" );
+               tmppt = tmppt->next;
+               tmppt->next = NULL;
+       }
+       end1 = pos1 - 1;
+       end2 = pos2 - 1;
+       tmppt->start1 = start1;
+       tmppt->start2 = start2;
+       tmppt->end1   = end1  ;
+       tmppt->end2   = end2  ;
+
+#if 1
+       if( divpairscore )
+       {
+               tmppt->overlapaa   = end2-start2+1;
+               tmppt->opt = score / tmppt->overlapaa * 5.8 / 600;
+       }
+       else
+       {
+               sumscore += score;
+               sumoverlap += end2-start2+1;
+       }
+#else
+       tmppt->overlapaa   = overlapaa;
+       tmppt->opt = (double)opt;
+#endif
+
+#if 0
+       fprintf( stderr, "score (2)= %f\n", score );
+       fprintf( stderr, "al1: %d - %d\n", start1, end1 );
+       fprintf( stderr, "al2: %d - %d\n", start2, end2 );
+#endif
+
+       if( !divpairscore )
+       {
+               for( tmppt=localhompt; tmppt; tmppt=tmppt->next )
+               {
+                       tmppt->overlapaa = sumoverlap;
+                       tmppt->opt = sumscore * 5.8 / 600 / sumoverlap;
+//                     fprintf( stderr, "tmpptr->opt = %f\n", tmppt->opt );
+               }
+       }
+}
+
+char *cutal( char *al, int al_display_start, int start, int end )
+{
+       int pos;
+       char *pt = al;
+       char *val = NULL;
+
+       pos = al_display_start;
+       do
+       {
+               if( start == pos ) val = pt;
+               if( end == pos ) break;
+//             fprintf( stderr, "pos=%d, *pt=%c, val=%p\n", pos, *pt, val );
+               if( *pt != '-' ) pos++;
+       } while( *pt++ != 0 );
+       *(pt+1) = 0;
+       return( val );
+}
+
+void ErrorExit( char *message )
+{
+       fprintf( stderr, "%s\n", message );
+       exit( 1 );
+}
+
+void strncpy_caseC( char *str1, char *str2, int len )
+{
+       if( dorp == 'd' && upperCase > 0 ) 
+       {
+               while( len-- )
+                       *str1++ = toupper( *str2++ );
+       }
+       else strncpy( str1, str2, len );
+}
+       
+void seqUpper( int nseq, char **seq ) /* not used */
+{
+       int i, j, len;
+       for( i=0; i<nseq; i++ ) 
+       {
+               len = strlen( seq[i] );
+               for( j=0; j<len; j++ ) 
+                       seq[i][j] = toupper( seq[i][j] );
+       }
+}
+
+void seqLower( int nseq, char **seq )
+{
+       int i, j, len;
+       for( i=0; i<nseq; i++ ) 
+       {
+               len = strlen( seq[i] );
+               for( j=0; j<len; j++ ) 
+                       seq[i][j] = tolower( seq[i][j] );
+       }
+}
+
+int getaline_fp_eof( char *s, int l, FILE *fp )  /* end of file -> return 1 */
+{
+    int c, i = 0 ;
+    int noteofflag = 0;
+    for( i=0; i<l && ( noteofflag = ( (c=getc(fp)) != EOF ) ) && c != '\n'; i++ ) 
+       *s++ = c;
+    *s = '\0' ;
+     return( !noteofflag );
+}
+
+int getaline_fp_eof_new(s, l, fp)  /* end of file -> return 1 */
+char    s[] ; int l ; FILE *fp ;
+{
+        int c = 0, i = 0 ;
+               int noteofflag = 0;
+
+               if( feof( fp ) ) return( 1 );
+
+               for( i=0; i<l && ( noteofflag = ( (c=getc(fp)) != EOF ) ) && c != '\n'; i++ ) 
+        { *s++ = c ; }
+        *s = '\0' ;
+               if( c != '\n' && c != EOF ) while( getc(fp) != '\n' )
+                       ;
+               return( !noteofflag );
+}
+
+int myfgets(s, l, fp)  /* l°Ê¾å¤Ï¡¢¹ÔËö¤Þ¤ÇÆɤßÈô¤Ð¤¹ */
+char    s[] ; int l ; FILE *fp ;
+{
+        int     c = 0, i = 0 ;
+
+               if( feof( fp ) ) return( 1 );
+
+               for( i=0; i<l && ( c=getc( fp ) ) != '\n'; i++ ) 
+               *s++ = c;
+        *s = '\0' ;
+               if( c != '\n' ) 
+                       while( getc(fp) != '\n' )
+                               ;
+               return( 0 );
+}
+
+float input_new( FILE *fp, int d )
+{
+       char mojiretsu[10];
+       int i, c;
+
+       c = getc( fp );
+       if( c != '\n' )
+               ungetc( c, fp );
+
+       for( i=0; i<d; i++ )
+               mojiretsu[i] = getc( fp );
+       mojiretsu[i] = 0;
+
+       return( atof( mojiretsu ) );
+}
+
+
+void PreRead( FILE *fp, int *locnjob, int *locnlenmax )
+{
+       int i, nleni;
+       char b[B];
+
+       fgets( b, B-1, fp ); *locnjob = atoi( b );
+       *locnlenmax = 0;
+       i=0; 
+       while( i<*locnjob )
+       {
+               fgets( b, B-1, fp );
+               if( !strncmp( b, "=", 1 ) )
+               {
+                       i++;
+                       fgets( b, B-1, fp ); nleni = atoi( b );
+                       if( nleni > *locnlenmax ) *locnlenmax = nleni;
+               }
+       }
+       if( *locnlenmax > N )
+       {
+               fprintf( stderr, "TOO LONG SEQUENCE!\n" );
+               exit( 1 );
+       }
+       if( njob > M  ) 
+       {
+               fprintf( stderr, "TOO MANY SEQUENCE!\n" );
+               fprintf( stderr, "%d > %d\n", njob, M );
+               exit( 1 );
+       }
+}      
+
+int allSpace( char *str )
+{
+       int value = 1;
+       while( *str ) value *= ( !isdigit( *str++ ) );
+       return( value );
+}
+       
+void Read( char name[M][B], int nlen[M], char **seq )
+{
+       extern void FRead( FILE *x, char y[M][B], int z[M], char **w );
+       FRead( stdin, name, nlen, seq );
+}
+
+
+void FRead( FILE *fp, char name[][B], int nlen[], char **seq )
+{
+       int i, j; 
+       char b[B];
+
+       fgets( b, B-1, fp );
+#if DEBUG
+       fprintf( stderr, "b = %s\n", b );
+#endif
+
+    if( strstr( b, "onnet" ) ) scoremtx = 1;
+    else if( strstr( b, "DnA" ) ) 
+       {
+               scoremtx = -1; 
+               upperCase = -1;
+       }
+    else if( strstr( b, "dna" ) ) 
+       {
+               scoremtx = -1; 
+               upperCase = 0;
+       }
+       else if( strstr( b, "DNA" ) )
+       {
+               scoremtx = -1; 
+               upperCase = 1;
+       }
+    else if( strstr( b, "M-Y" ) || strstr( b, "iyata" ) ) scoremtx = 2; 
+    else scoremtx = 0;
+#if DEBUG
+       fprintf( stderr, " %s->scoremtx = %d\n", b, scoremtx );
+#endif
+
+       geta2 = GETA2;
+
+#if 0
+       if( strlen( b ) >=25 )
+       {
+               b[25] = 0;
+       #if DEBUG
+               fprintf( stderr, "kimuraR = %s\n", b+20 );
+       #endif
+               kimuraR = atoi( b+20 );
+
+               if( kimuraR < 0 || 20 < kimuraR ) ErrorExit( "Illeagal kimuraR value.\n" );
+               if( allSpace( b+20 ) ) kimuraR = NOTSPECIFIED;
+       }
+       else kimuraR = NOTSPECIFIED;
+       #if DEBUG
+       fprintf( stderr, "kimuraR = %d\n", kimuraR );
+       #endif
+
+       if( strlen( b ) >=20 )
+       {
+               b[20] = 0;
+       #if DEBUG
+               fprintf( stderr, "pamN = %s\n", b+15 );
+       #endif
+               pamN = atoi( b+15 );
+               if( pamN < 0 || 400 < pamN ) ErrorExit( "Illeagal pam value.\n" );
+               if( allSpace( b+15 ) ) pamN = NOTSPECIFIED;
+       }
+       else pamN = NOTSPECIFIED;
+
+       if( strlen( b ) >= 15 )
+       {
+               b[15] = 0;
+       #if DEBUG
+               fprintf( stderr, "poffset = %s\n", b+10 );
+       #endif
+               poffset = atoi( b+10 );
+               if( poffset > 500 ) ErrorExit( "Illegal extending gap ppenalty\n" );
+               if( allSpace( b+10 ) ) poffset = NOTSPECIFIED;
+       }
+       else poffset = NOTSPECIFIED;
+
+       if( strlen( b ) >= 10 )
+       {
+               b[10] = 0;
+       #if DEBUG
+               fprintf( stderr, "ppenalty = %s\n", b+5 );
+       #endif
+               ppenalty = atoi( b+5 );
+               if( ppenalty > 0 ) ErrorExit( "Illegal opening gap ppenalty\n" );
+               if( allSpace( b+5 ) ) ppenalty = NOTSPECIFIED;
+       }
+       else ppenalty = NOTSPECIFIED;
+#endif
+
+       for( i=0; i<njob; i++ )
+       {
+               getaline_fp_eof_new( b, B-1, fp );
+               strcpy( name[i], b );
+#if DEBUG
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               fgets( b, B-1, fp ); nlen[i] = atoi( b );      /* seq i no nagasa */
+               seq[i][0] = 0;
+               if( nlen[i] ) for( j=0; j <= (nlen[i]-1)/C; j++ )
+               {
+                       getaline_fp_eof_new( b, B-1, fp );
+                       /*      b[C] = 0;  */
+                       strcat( seq[i], b );
+               } 
+               seq[i][nlen[i]] = 0;
+       }
+       if( scoremtx == -1 && upperCase != -1 ) seqLower( njob, seq );
+}
+
+
+static int countKUorWA( FILE *fp )
+{
+       int value;
+       int c, b;
+
+       value= 0;
+       b = '\n';
+       while( ( c = getc( fp ) ) != EOF )
+       {
+               if( b == '\n' && ( c == '>' ) )
+                       value++;
+               b = c;
+       }
+       rewind( fp );
+       return( value );
+}
+
+void searchKUorWA( FILE *fp )
+{
+       int c, b;
+       b = '\n';
+       while( !( ( ( c = getc( fp ) ) == '>' || c == EOF ) && b == '\n' ) )
+               b = c;
+       ungetc( c, fp );
+}
+
+static int onlyGraph( char *str )
+{
+       char tmp;
+       char *res = str;
+       char *bk = str;
+
+//     while( (tmp=*str++) ) if( isgraph( tmp ) ) *res++ = tmp;
+       while( (tmp=*str++) ) 
+       {
+               if( 0x20 < tmp && tmp < 0x7f ) *res++ = tmp;
+               if( tmp == '>' )
+               {
+                       fprintf( stderr, "========================================================\n" );
+                       fprintf( stderr, "========================================================\n" );
+                       fprintf( stderr, "=== \n" );
+                       fprintf( stderr, "=== ERROR!! \n" );
+                       fprintf( stderr, "=== In the '--anysymbol' and '--preservecase' modes, \n" );
+                       fprintf( stderr, "=== '>' in sequence is unacceptable.\n" );
+                       fprintf( stderr, "=== \n" );
+                       fprintf( stderr, "========================================================\n" );
+                       fprintf( stderr, "========================================================\n" );
+                       exit( 1 );
+               }
+       }
+       *res = 0;
+       return( res - bk );
+}
+
+static int onlyAlpha_lower( char *str )
+{
+       char tmp;
+       char *res = str;
+       char *bk = str;
+
+       while( (tmp=*str++) )
+               if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' )
+                       *res++ = tolower( tmp );
+       *res = 0;
+       return( res - bk );
+}
+static int onlyAlpha_upper( char *str )
+{
+       char tmp;
+       char *res = str;
+       char *bk = str;
+
+       while( (tmp=*str++) )
+               if( isalpha( tmp ) || tmp == '-' || tmp == '*' || tmp == '.' )
+                       *res++ = toupper( tmp );
+       *res = 0;
+       return( res - bk );
+}
+
+void kake2hiku( char *str )
+{
+       do
+               if( *str == '*' ) *str = '-';
+       while( *str++ );
+}
+
+char *load1SeqWithoutName_realloc_casepreserve( FILE *fpp )
+{
+       int c, b;
+       char *cbuf;
+       int size = N;
+       char *val;
+
+       val = malloc( (size+1) * sizeof( char ) );
+       cbuf = val;
+
+       b = '\n';
+       while( ( c = getc( fpp ) ) != EOF &&           
+          !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) )
+       {
+               *cbuf++ = (char)c;  /* Ä¹¤¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */
+               if( cbuf - val == size )
+               {
+                       size += N;
+                       fprintf( stderr, "reallocating...\n" );
+                       val = (char *)realloc( val, (size+1) * sizeof( char ) );
+                       if( !val )
+                       {
+                               fprintf( stderr, "Allocation error in load1SeqWithoutName_realloc \n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "done.\n" );
+                       cbuf = val + size-N;
+               }
+               b = c;
+       }
+       ungetc( c, fpp );
+       *cbuf = 0;
+       onlyGraph( val );
+//     kake2hiku( val );
+       return( val );
+}
+
+char *load1SeqWithoutName_realloc( FILE *fpp )
+{
+       int c, b;
+       char *cbuf;
+       int size = N;
+       char *val;
+
+       val = malloc( (size+1) * sizeof( char ) );
+       cbuf = val;
+
+       b = '\n';
+       while( ( c = getc( fpp ) ) != EOF &&           
+          !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) )
+       {
+               *cbuf++ = (char)c;  /* Ä¹¤¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */
+               if( cbuf - val == size )
+               {
+                       size += N;
+                       fprintf( stderr, "reallocating...\n" );
+                       val = (char *)realloc( val, (size+1) * sizeof( char ) );
+                       if( !val )
+                       {
+                               fprintf( stderr, "Allocation error in load1SeqWithoutName_realloc \n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "done.\n" );
+                       cbuf = val + size-N;
+               }
+               b = c;
+       }
+       ungetc( c, fpp );
+       *cbuf = 0;
+       if( dorp == 'd' )
+               onlyAlpha_lower( val );
+       else
+               onlyAlpha_upper( val );
+       kake2hiku( val );
+       return( val );
+}
+
+int load1SeqWithoutName_new( FILE *fpp, char *cbuf )
+{
+       int c, b;
+       char *bk = cbuf;
+
+       b = '\n';
+       while( ( c = getc( fpp ) ) != EOF &&                    /* by T. Nishiyama */
+          !( ( c == '>' || c == '(' || c == EOF ) && b == '\n' ) )
+       {
+               *cbuf++ = (char)c;  /* Ä¹¤¹¤®¤Æ¤â¤·¤é¤Ê¤¤ */
+               b = c;
+       }
+       ungetc( c, fpp );
+       *cbuf = 0;
+       if( dorp == 'd' )
+               onlyAlpha_lower( bk );
+       else
+               onlyAlpha_upper( bk );
+       kake2hiku( bk );
+       return( 0 );
+}
+
+
+void readDataforgaln( FILE *fp, char **name, int *nlen, char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+#if 0
+       if( !tmpseq )
+       {
+               tmpseq = AllocateCharVec( N );
+       }
+#endif
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               strcpy( seq[i], tmpseq );
+               nlen[i] = strlen( seq[i] );
+               free( tmpseq );
+       }
+       if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
+#if 0
+       free( tmpseq );
+#endif
+}
+
+void readData_varlen( FILE *fp, char **name, int *nlen, char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               nlen[i] = strlen( tmpseq );
+//             fprintf( stderr, "nlen[%d] = %d\n", i+1, nlen[i] );
+               seq[i] = calloc( nlen[i]+1, sizeof( char ) );
+               strcpy( seq[i], tmpseq );
+               free( tmpseq );
+       }
+       if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
+#if 0
+       free( tmpseq );
+#endif
+}
+
+void readData_pointer2( FILE *fp, int nseq, char **name, int *nlen, char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+#if 0
+       if( !tmpseq )
+       {
+               tmpseq = AllocateCharVec( N );
+       }
+#endif
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<nseq; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               strcpy( seq[i], tmpseq );
+               free( tmpseq );
+               nlen[i] = strlen( seq[i] );
+       }
+       if( dorp == 'd' && upperCase != -1 ) seqLower( nseq, seq );
+#if 0
+       free( tmpseq );
+#endif
+       if( outnumber )
+       {
+               char *namebuf;
+               char *cptr;
+               namebuf = calloc( B+100, sizeof( char ) );
+               for( i=0; i<nseq; i++ )
+               {
+                       namebuf[0] = '=';
+                       cptr = strstr( name[i], "_numo_e_" );
+                       if( cptr )
+                               sprintf( namebuf+1, "_numo_s_%08d_numo_e_%s", i+1, cptr+8 );
+                       else
+                               sprintf( namebuf+1, "_numo_s_%08d_numo_e_%s", i+1, name[i]+1 );
+                       strncpy( name[i], namebuf, B );
+                       name[i][B-1] = 0;
+               }
+               free( namebuf );
+//             exit( 1 );
+       }
+}
+
+
+void readData_pointer_casepreserve( FILE *fp, char **name, int *nlen, char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+#if 0
+       if( !tmpseq )
+       {
+               tmpseq = AllocateCharVec( N );
+       }
+#endif
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+               strcpy( seq[i], tmpseq );
+               free( tmpseq );
+               nlen[i] = strlen( seq[i] );
+       }
+}
+
+
+void readData_pointer( FILE *fp, char **name, int *nlen, char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+#if 0
+       if( !tmpseq )
+       {
+               tmpseq = AllocateCharVec( N );
+       }
+#endif
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               strcpy( seq[i], tmpseq );
+               free( tmpseq );
+               nlen[i] = strlen( seq[i] );
+       }
+       if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
+#if 0
+       free( tmpseq );
+#endif
+       if( outnumber )
+       {
+               char *namebuf;
+               char *cptr;
+               namebuf = calloc( B+100, sizeof( char ) );
+               for( i=0; i<njob; i++ )
+               {
+                       namebuf[0] = '=';
+                       cptr = strstr( name[i], "_numo_e_" );
+                       if( cptr )
+                               sprintf( namebuf+1, "_numo_s_%08d_numo_e_%s", i+1, cptr+8 );
+                       else
+                               sprintf( namebuf+1, "_numo_s_%08d_numo_e_%s", i+1, name[i]+1 );
+                       strncpy( name[i], namebuf, B );
+                       name[i][B-1] = 0;
+               }
+               free( namebuf );
+//             exit( 1 );
+       }
+}
+
+void readData( FILE *fp, char name[][B], int nlen[], char **seq )
+{
+       int i; 
+       static char *tmpseq = NULL;
+
+#if 0
+       if( !tmpseq )
+       {
+               tmpseq = AllocateCharVec( N );
+       }
+#endif
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               name[i][0] = '='; getc( fp ); 
+#if 0
+               fgets( name[i]+1, B-2, fp ); 
+               j = strlen( name[i] );
+               if( name[i][j-1] != '\n' )
+                       ErrorExit( "Too long name\n" );
+               name[i][j-1] = 0;
+#else
+               myfgets( name[i]+1, B-2, fp ); 
+#endif
+#if 0
+               fprintf( stderr, "name[%d] = %s\n", i, name[i] );
+#endif
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               strcpy( seq[i], tmpseq );
+               nlen[i] = strlen( seq[i] );
+               free( tmpseq );
+       }
+       if( dorp == 'd' && upperCase != -1 ) seqLower( njob, seq );
+#if 0
+       free( tmpseq );
+#endif
+}
+
+void cutAlignment( FILE *fp, int **regtable, char **revtable, int *outtable, char **name, char **outseq )
+{
+       int i, j; 
+       int outlen;
+       static char *tmpseq = NULL;
+       static char *dumname = NULL;
+       char *fs, *rs;
+       int npos, lpos;
+       int startpos, endpos, seqlen;
+
+       if( dumname == NULL )
+       {
+               dumname = AllocateCharVec( N );
+       }
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+
+       npos = 0;
+       for( i=0; i<njob; i++ )
+       {
+               dumname[0] = '>'; getc( fp ); 
+               myfgets( dumname+1, B-1, fp ); 
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+
+               if( outtable[i] )
+               {
+//                     putc( '>', stdout );
+//                     puts( dumname+1 );
+
+       
+                       strncat( name[npos], dumname, B-1 );
+                       name[npos][B-1] = 0;
+       
+                       if( dorp == 'd' && upperCase != -1 ) seqLower( 1, &tmpseq );
+                       seqlen = strlen( tmpseq );
+                       lpos = 0;
+                       for( j=0; j<5; j++ )
+                       {
+                               if( regtable[0][j*2] == -1 && regtable[0][j*2+1] == -1 ) continue;
+
+                               startpos = regtable[0][j*2];
+                               endpos   = regtable[0][j*2+1];
+                               if( startpos > endpos )
+                               {
+                                       endpos   = regtable[0][j*2];
+                                       startpos = regtable[0][j*2+1];
+                               }
+
+                               if( startpos < 0 ) startpos = 0;
+                               if( endpos   < 0 ) endpos   = 0;
+                               if( endpos   >= seqlen ) endpos   = seqlen-1;
+                               if( startpos >= seqlen ) startpos = seqlen-1;
+
+//                             fprintf( stderr, "startpos = %d, endpos = %d\n", startpos, endpos );
+
+                               outlen = endpos - startpos+1;
+                               if( revtable[0][j] == 'f' )
+                               {
+//                                     fprintf( stderr, "regtable[%d][st] = %d\n", i, regtable[0][j*2+0] );
+//                                     fprintf( stderr, "regtable[%d][en] = %d\n", i, regtable[0][j*2+1] );
+//                                     fprintf( stderr, "outlen = %d\n", outlen );
+//                                     fprintf( stdout, "%.*s\n", outlen, tmpseq+regtable[0][j*2] );
+                                       strncpy( outseq[npos] + lpos, tmpseq+startpos, outlen );
+                                       lpos += outlen;
+                               }
+                               else
+                               {
+                                       fs = AllocateCharVec( outlen+1 );
+                                       rs = AllocateCharVec( outlen+1 );
+
+                                       fs[outlen] = 0;
+                                       strncpy( fs, tmpseq+startpos, outlen );
+                                       sreverse( rs, fs );
+//                                     fprintf( stdout, "%s\n", rs );
+                                       strncpy( outseq[npos] + lpos, rs, outlen );
+                                       lpos += outlen;
+                                       free( fs );
+                                       free( rs );
+                               }
+                               outseq[npos][lpos] = 0;
+                       }
+                       npos++;
+               }
+               free( tmpseq );
+       }
+}
+
+void cutData( FILE *fp, int **regtable, char **revtable, int *outtable )
+{
+       int i, j; 
+       int outlen, seqlen, startpos, endpos;
+       static char *tmpseq = NULL;
+       static char *dumname = NULL;
+       char *fs, *rs;
+
+       if( dumname == NULL )
+       {
+               dumname = AllocateCharVec( N );
+       }
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               dumname[0] = '='; getc( fp ); 
+               myfgets( dumname+1, B-2, fp ); 
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+
+               if( outtable[i] )
+               {
+                       gappick_samestring( tmpseq );
+                       putc( '>', stdout );
+                       puts( dumname+1 );
+
+                       seqlen = strlen( tmpseq );
+
+                       if( dorp == 'd' && upperCase != -1 ) seqLower( 1, &tmpseq );
+                       for( j=0; j<5; j++ )
+                       {
+                               if( regtable[i][j*2] == -1 && regtable[i][j*2+1] == -1 ) continue;
+
+                               startpos = regtable[i][j*2];
+                               endpos   = regtable[i][j*2+1];
+
+                               if( startpos > endpos )
+                               {
+                                       endpos   = regtable[i][j*2];
+                                       startpos = regtable[i][j*2+1];
+                               }
+
+                               if( startpos < 0 ) startpos = 0;
+                               if( endpos   < 0 ) endpos   = 0;
+                               if( endpos   >= seqlen ) endpos   = seqlen-1;
+                               if( startpos >= seqlen ) startpos = seqlen-1;
+
+                               outlen = endpos - startpos + 1;
+                               if( revtable[i][j] == 'f' )
+                               {
+                                       fprintf( stderr, "startpos = %d\n", startpos );
+                                       fprintf( stderr, "endpos   = %d\n", endpos );
+                                       fprintf( stderr, "outlen = %d\n", outlen );
+                                       fprintf( stdout, "%.*s\n", outlen, tmpseq+startpos );
+                               }
+                               else
+                               {
+                                       fs = AllocateCharVec( outlen+1 );
+                                       rs = AllocateCharVec( outlen+1 );
+
+                                       fs[outlen] = 0;
+                                       strncpy( fs, tmpseq+startpos, outlen );
+                                       sreverse( rs, fs );
+                                       fprintf( stdout, "%s\n", rs );
+                                       free( fs );
+                                       free( rs );
+                               }
+                       }
+               }
+               free( tmpseq );
+       }
+}
+
+void catData( FILE *fp )
+{
+       int i; 
+       static char *tmpseq = NULL;
+       static char *dumname = NULL;
+//     char *cptr;
+
+       if( dumname == NULL )
+       {
+               dumname = AllocateCharVec( N );
+       }
+
+       rewind( fp );
+       searchKUorWA( fp );
+
+       for( i=0; i<njob; i++ )
+       {
+               dumname[0] = '='; getc( fp ); 
+               myfgets( dumname+1, B-2, fp ); 
+               if( outnumber )
+               {
+                       fprintf( stdout, ">_numo_s_%08d_numo_e_", i+1 );
+               }
+               else
+               {
+                       putc( '>', stdout );
+               }
+               puts( dumname+1 );
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               if( dorp == 'd' && upperCase != -1 ) seqLower( 1, &tmpseq );
+               puts( tmpseq );
+               free( tmpseq );
+       }
+}
+
+int countATGC( char *s, int *total )
+{
+       int nATGC;
+       int nChar;
+       char c;
+       nATGC = nChar = 0;
+
+       if( *s == 0 ) 
+       {
+               total = 0;
+               return( 0 );
+       }
+
+       do
+       {
+               c = tolower( *s );
+               if( isalpha( c ) )
+               {
+                       nChar++;
+                       if( c == 'a' || c == 't' || c == 'g' || c == 'c' || c == 'u' || c == 'n' )
+                               nATGC++;
+               }
+       }
+       while( *++s );
+
+       *total = nChar;
+       return( nATGC );
+}
+
+double countATGCbk( char *s )
+{
+       int nATGC;
+       int nChar;
+       char c;
+       nATGC = nChar = 0;
+
+       do
+       {
+               c = tolower( *s );
+               if( isalpha( c ) )
+               {
+                       nChar++;
+                       if( c == 'a' || c == 't' || c == 'g' || c == 'c' || c == 'u' || c == 'n' )
+                               nATGC++;
+               }
+       }
+       while( *++s );
+       return( (double)nATGC / nChar );
+}
+
+
+int countnogaplen( char *seq )
+{
+       int val = 0;
+       while( *seq )
+               if( *seq++ != '-' ) val++;
+       return( val );
+}
+
+void getnumlen_casepreserve( FILE *fp, int *nlenminpt )
+{
+       int total;
+       int nsite = 0;
+       int atgcnum;
+       int i, tmp;
+       char *tmpseq, *tmpname;
+       double atgcfreq;
+       tmpname = AllocateCharVec( N );
+       njob = countKUorWA( fp );
+       searchKUorWA( fp );
+       nlenmax = 0;
+       *nlenminpt = 99999999;
+       atgcnum = 0;
+       total = 0;
+       for( i=0; i<njob; i++ )
+       {
+               myfgets( tmpname, N-1, fp );
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+               tmp = strlen( tmpseq );
+               if( tmp > nlenmax ) nlenmax  = tmp;
+               if( tmp < *nlenminpt ) *nlenminpt  = tmp;
+               atgcnum += countATGC( tmpseq, &nsite );
+               total += nsite;
+               free( tmpseq );
+       }
+       free( tmpname );
+       atgcfreq = (double)atgcnum / total;
+//     fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+       if( dorp == NOTSPECIFIED )
+       {
+               if( atgcfreq > 0.75 )   
+               {
+                       dorp = 'd';
+                       upperCase = -1;
+               }
+               else                  
+               {
+                       dorp = 'p';
+                       upperCase = 0;
+               }
+       }
+}
+
+void getnumlen_nogap( FILE *fp, int *nlenminpt )
+{
+       int total;
+       int nsite = 0;
+       int atgcnum;
+       int i, tmp;
+       char *tmpseq, *tmpname;
+       double atgcfreq;
+       tmpname = AllocateCharVec( N );
+       njob = countKUorWA( fp );
+       searchKUorWA( fp );
+       nlenmax = 0;
+       *nlenminpt = 99999999;
+       atgcnum = 0;
+       total = 0;
+       for( i=0; i<njob; i++ )
+       {
+               myfgets( tmpname, N-1, fp );
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               tmp = countnogaplen( tmpseq );
+               if( tmp > nlenmax ) nlenmax  = tmp;
+               if( tmp < *nlenminpt ) *nlenminpt  = tmp;
+               atgcnum += countATGC( tmpseq, &nsite );
+               total += nsite;
+               free( tmpseq );
+       }
+       free( tmpname );
+       atgcfreq = (double)atgcnum / total;
+       fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+       if( dorp == NOTSPECIFIED )
+       {
+               if( atgcfreq > 0.75 )   
+               {
+                       dorp = 'd';
+                       upperCase = -1;
+               }
+               else                  
+               {
+                       dorp = 'p';
+                       upperCase = 0;
+               }
+       }
+}
+
+
+void getnumlen_nogap_outallreg( FILE *fp, int *nlenminpt )
+{
+       int total;
+       int nsite = 0;
+       int atgcnum;
+       int i, tmp;
+       char *tmpseq, *tmpname;
+       double atgcfreq;
+       tmpname = AllocateCharVec( N );
+       njob = countKUorWA( fp );
+       searchKUorWA( fp );
+       nlenmax = 0;
+       *nlenminpt = 99999999;
+       atgcnum = 0;
+       total = 0;
+       for( i=0; i<njob; i++ )
+       {
+               myfgets( tmpname, N-1, fp );
+               fprintf( stdout, "%s\n", tmpname );
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+               tmp = countnogaplen( tmpseq );
+               fprintf( stdout, "%d\n", tmp );
+               if( tmp > nlenmax ) nlenmax  = tmp;
+               if( tmp < *nlenminpt ) *nlenminpt  = tmp;
+               atgcnum += countATGC( tmpseq, &nsite );
+               total += nsite;
+               free( tmpseq );
+       }
+       free( tmpname );
+       atgcfreq = (double)atgcnum / total;
+       fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+       if( dorp == NOTSPECIFIED )
+       {
+               if( atgcfreq > 0.75 )   
+               {
+                       dorp = 'd';
+                       upperCase = -1;
+               }
+               else                  
+               {
+                       dorp = 'p';
+                       upperCase = 0;
+               }
+       }
+}
+
+void getnumlen_nogap_outallreg_web( FILE *fp, FILE *ofp, int *nlenminpt, int *isalignedpt )
+{
+       int total;
+       int nsite = 0;
+       int atgcnum;
+       int alnlen = 0, alnlen_prev;
+       int i, tmp;
+       char *tmpseq, *tmpname;
+       double atgcfreq;
+       tmpname = AllocateCharVec( N );
+       njob = countKUorWA( fp );
+       searchKUorWA( fp );
+       nlenmax = 0;
+       *nlenminpt = 99999999;
+       atgcnum = 0;
+       total = 0;
+       alnlen_prev = -1;
+       *isalignedpt = 1;
+       for( i=0; i<njob; i++ )
+       {
+               myfgets( tmpname, N-1, fp );
+//             fprintf( stdout, "%s\n", tmpname );
+               tmpseq = load1SeqWithoutName_realloc_casepreserve( fp );
+               tmp = countnogaplen( tmpseq );
+//             fprintf( stdout, "%d\n", tmp );
+               if( tmp > nlenmax ) nlenmax  = tmp;
+               if( tmp < *nlenminpt ) *nlenminpt  = tmp;
+               atgcnum += countATGC( tmpseq, &nsite );
+               total += nsite;
+
+               alnlen = strlen( tmpseq );
+//             fprintf( stdout, "##### alnlen, alnlen_prev = %d, %d\n", alnlen, alnlen_prev );
+               if( i>0 && alnlen_prev != alnlen ) *isalignedpt = 0;
+               alnlen_prev = alnlen;
+
+               free( tmpseq );
+               atgcfreq = (double)atgcnum / total;
+//             fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+//             if( dorp == NOTSPECIFIED ) // you kentou
+               {
+                       if( atgcfreq > 0.75 )   
+                       {
+                               dorp = 'd';
+                               upperCase = -1;
+                       }
+                       else                  
+                       {
+                               dorp = 'p';
+                               upperCase = 0;
+                       }
+               }
+       
+
+
+
+               fprintf( ofp, " <label for='s%d'><input type='checkbox' id='s%d' name='s%d' checked>%s</label>\n", i, i, i, tmpname );
+               fprintf( ofp, "<span id='t%d-0' style='display:none'>", i );
+               fprintf( ofp, " <a href='javascript:void(0)' onclick='ddcycle(this.form,\"t%d\")'>+reg</a>", i );
+               fprintf( ofp, " Begin:<input type='text' name='b%d-0' size='8' value='1'> End:<input type='text' name='e%d-0' size='8' value='%d'>", i, i, tmp );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='r%d-0'><input type='checkbox' name='r%d-0' id='r%d-0'>Reverse</label>", i, i, i );
+               fprintf( ofp, "  Sequence Length:<input type='text' name='l%d' size='8' value='%d' readonly='readonly'>", i, tmp );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='t%d-1' style='display:none'>", i );
+               fprintf( ofp, "      Begin:<input type='text' name='b%d-1' size='8' value=''> End:<input type='text' name='e%d-1' size='8' value=''>", i, i );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='r%d-1'><input type='checkbox' name='r%d-1' id='r%d-1'>Reverse</label>", i, i, i );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='t%d-2' style='display:none'>", i );
+               fprintf( ofp, "      Begin:<input type='text' name='b%d-2' size='8' value=''> End:<input type='text' name='e%d-2' size='8' value=''>", i, i );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='r%d-2'><input type='checkbox' name='r%d-2' id='r%d-2'>Reverse</label>", i, i, i );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='t%d-3' style='display:none'>", i );
+               fprintf( ofp, "      Begin:<input type='text' name='b%d-3' size='8' value=''> End:<input type='text' name='e%d-3' size='8' value=''>", i, i );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='r%d-3'><input type='checkbox' name='r%d-3' id='r%d-3'>Reverse</label>", i, i, i );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='t%d-4' style='display:none'>", i );
+               fprintf( ofp, "      Begin:<input type='text' name='b%d-4' size='8' value=''> End:<input type='text' name='e%d-4' size='8' value=''>", i, i );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='r%d-4'><input type='checkbox' name='r%d-4' id='r%d-4'>Reverse</label>", i, i, i );
+               fprintf( ofp, "\n</span>" );
+       }
+       free( tmpname );
+       atgcfreq = (double)atgcnum / total;
+       fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+//     if( dorp == NOTSPECIFIED ) // you kentou
+       {
+               if( atgcfreq > 0.75 )   
+               {
+                       dorp = 'd';
+                       upperCase = -1;
+               }
+               else                  
+               {
+                       dorp = 'p';
+                       upperCase = 0;
+               }
+       }
+       if( *isalignedpt )
+       {
+               fprintf( ofp, "\n" );
+               fprintf( ofp, "<span id='tall-0' style='display:none'>" );
+               fprintf( ofp, "Cut the alignment\n" );
+               fprintf( ofp, " <a href='javascript:void(0)' onclick='ddcycle(this.form,\"tall\")'>+reg</a>" );
+               fprintf( ofp, " Begin:<input type='text' name='ball-0' size='8' value='1'> End:<input type='text' name='eall-0' size='8' value='%d'>", alnlen );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='rall-0'><input type='checkbox' name='rall-0' id='rall-0'>Reverse</label>" );
+               fprintf( ofp, "  Alignment length:<input type='text' name='lall' size='8' value='%d' readonly='readonly'>", alnlen );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='tall-1' style='display:none'>" );
+               fprintf( ofp, "      Begin:<input type='text' name='ball-1' size='8' value=''> End:<input type='text' name='eall-1' size='8' value=''>" );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='rall-1'><input type='checkbox' name='rall-1' id='rall-1'>Reverse</label>" );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='tall-2' style='display:none'>" );
+               fprintf( ofp, "      Begin:<input type='text' name='ball-2' size='8' value=''> End:<input type='text' name='eall-1' size='8' value=''>" );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='rall-2'><input type='checkbox' name='rall-2' id='rall-2'>Reverse</label>" );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='tall-3' style='display:none'>" );
+               fprintf( ofp, "      Begin:<input type='text' name='ball-3' size='8' value=''> End:<input type='text' name='eall-1' size='8' value=''>" );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='rall-3'><input type='checkbox' name='rall-3' id='rall-3'>Reverse</label>" );
+               fprintf( ofp, "\n</span>" );
+               fprintf( ofp, "<span id='tall-4' style='display:none'>" );
+               fprintf( ofp, "      Begin:<input type='text' name='ball-4' size='8' value=''> End:<input type='text' name='eall-1' size='8' value=''>" );
+               if( dorp == 'd' ) fprintf( ofp, " <label for='rall-4'><input type='checkbox' name='rall-4' id='rall-4'>Reverse</label>" );
+               fprintf( ofp, "\n</span>" );
+       }
+
+}
+
+void getnumlen( FILE *fp )
+{
+       int total;
+       int nsite = 0;
+       int atgcnum;
+       int i, tmp;
+       char *tmpseq;
+       char *tmpname;
+       double atgcfreq;
+       tmpname = AllocateCharVec( N );
+       njob = countKUorWA( fp );
+       searchKUorWA( fp );
+       nlenmax = 0;
+       atgcnum = 0;
+       total = 0;
+       for( i=0; i<njob; i++ )
+       {
+               myfgets( tmpname, N-1, fp );
+               tmpseq = load1SeqWithoutName_realloc( fp );
+               tmp = strlen( tmpseq );
+               if( tmp > nlenmax ) nlenmax  = tmp;
+               atgcnum += countATGC( tmpseq, &nsite );
+               total += nsite;
+//             fprintf( stderr, "##### total = %d\n", total );
+               free( tmpseq );
+       }
+
+       atgcfreq = (double)atgcnum / total;
+//     fprintf( stderr, "##### atgcfreq = %f\n", atgcfreq );
+       if( dorp == NOTSPECIFIED )
+       {
+               if( atgcfreq > 0.75 )   
+               {
+                       dorp = 'd';
+                       upperCase = -1;
+               }
+               else                  
+               {
+                       dorp = 'p';
+                       upperCase = 0;
+               }
+       }
+       free( tmpname );
+}
+       
+
+
+void WriteGapFill( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq )
+{
+       static char b[N];
+       int i, j;
+       int nalen[M];
+       static char gap[N];
+       static char buff[N];
+
+#if IODEBUG
+       fprintf( stderr, "IMAKARA KAKU\n" );
+#endif
+       nlenmax = 0;
+       for( i=0; i<locnjob; i++ )
+       {
+               int len = strlen( aseq[i] );
+               if( nlenmax < len ) nlenmax = len;
+       }
+
+       for( i=0; i<nlenmax; i++ ) gap[i] = '-';
+       gap[nlenmax] = 0;
+
+       fprintf( fp, "%5d", locnjob );
+       fprintf( fp, "\n" );
+
+       for( i=0; i<locnjob; i++ )
+       {
+               strcpy( buff, aseq[i] );
+               strncat( buff, gap, nlenmax-strlen( aseq[i] ) );
+               buff[nlenmax] = 0;
+               nalen[i] = strlen( buff );
+               fprintf( fp, "%s\n", name[i] );
+               fprintf( fp, "%5d\n", nalen[i] );
+               for( j=0; j<nalen[i]; j=j+C )
+               {
+                       strncpy_caseC( b, buff+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+               }
+       }
+#if DEBUG
+       fprintf( stderr, "nalen[0] = %d\n", nalen[0] );
+#endif
+#if IODEBUG
+       fprintf( stderr, "KAKIOWATTA\n" );
+#endif
+}
+
+void writeDataforgaln( FILE *fp, int locnjob, char **name, int *nlen, char **aseq )
+{
+       int i, j;
+       int nalen;
+
+       for( i=0; i<locnjob; i++ )
+       {
+               nalen = strlen( aseq[i] );
+               fprintf( fp, ">%s\n", name[i]+1 );
+               for( j=0; j<nalen; j=j+C )
+               {
+#if 0
+                       strncpy( b, aseq[i]+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+#else
+                       fprintf( fp, "%.*s\n", C, aseq[i]+j );
+#endif
+               }
+       }
+}
+
+void writeData_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq )
+{
+       int i, j;
+       int nalen;
+
+       for( i=0; i<locnjob; i++ )
+       {
+#if DEBUG
+               fprintf( stderr, "i = %d in writeData\n", i );
+#endif
+               nalen = strlen( aseq[i] );
+               fprintf( fp, ">%s\n", name[i]+1 );
+               for( j=0; j<nalen; j=j+C )
+               {
+#if 0
+                       strncpy( b, aseq[i]+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+#else
+                       fprintf( fp, "%.*s\n", C, aseq[i]+j );
+#endif
+               }
+       }
+}
+
+void writeData( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq )
+{
+       int i, j;
+       int nalen;
+
+       for( i=0; i<locnjob; i++ )
+       {
+#if DEBUG
+               fprintf( stderr, "i = %d in writeData\n", i );
+#endif
+               nalen = strlen( aseq[i] );
+               fprintf( fp, ">%s\n", name[i]+1 );
+               for( j=0; j<nalen; j=j+C )
+               {
+#if 0
+                       strncpy( b, aseq[i]+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+#else
+                       fprintf( fp, "%.*s\n", C, aseq[i]+j );
+#endif
+               }
+       }
+}
+
+
+void write1seq( FILE *fp, char *aseq )
+{
+       int j;
+       int nalen;
+
+       nalen = strlen( aseq );
+       for( j=0; j<nalen; j=j+C )
+               fprintf( fp, "%.*s\n", C, aseq+j );
+}
+
+
+
+void readhat2_floathalf_pointer( FILE *fp, int nseq, char **name, float **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j-i] = ( input_new( fp, D ) );
+    }
+}
+void readhat2_floathalf( FILE *fp, int nseq, char name[M][B], float **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j-i] = ( input_new( fp, D ) );
+    }
+}
+void readhat2_float( FILE *fp, int nseq, char name[M][B], float **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j] = ( input_new( fp, D ) );
+    }
+}
+void readhat2_int( FILE *fp, int nseq, char name[M][B], int **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j] = (int)( input_new( fp, D ) * INTMTXSCALE + 0.5 );
+    }
+}
+
+void readhat2_pointer( FILE *fp, int nseq, char **name, double **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j] = (double)input_new( fp, D);
+    }
+}
+void readhat2( FILE *fp, int nseq, char name[M][B], double **mtx )
+{
+    int i, j, nseq0;
+    char b[B];
+
+    fgets( b, B, fp );
+    fgets( b, B, fp ); b[5] = 0; nseq0 = atoi( b ); if( nseq != nseq0 ) ErrorExit( "hat2 is wrong." );
+    fgets( b, B, fp );
+    for( i=0; i<nseq; i++ )
+    {
+#if 0
+        getaline_fp_eof( b, B, fp ); 
+#else
+               myfgets( b, B-2, fp );
+#endif
+#if 0
+               j = MIN( strlen( b+6 ), 10 );
+        if( strncmp( name[i], b+6 , j ) ) 
+               {
+                       fprintf( stderr, "Error in hat2\n" );
+                       fprintf( stderr, "%s != %s\n", b, name[i] );
+                       exit( 1 );
+               }
+#endif
+    }
+    for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+    {
+        mtx[i][j] = (double)input_new( fp, D);
+    }
+}
+
+void WriteFloatHat2_pointer_halfmtx( FILE *hat2p, int locnjob, char **name, float **mtx )
+{
+       int i, j, ijsa;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=1; j<locnjob-i; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob; i++ )
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       fprintf( hat2p, "%#6.3f", mtx[i][j-i] );
+                       ijsa = j-i;
+                       if( ijsa % 12 == 0 || ijsa == locnjob-i-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+
+void WriteFloatHat2_pointer( FILE *hat2p, int locnjob, char **name, float **mtx )
+{
+       int i, j;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=1; j<locnjob-i; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob; i++ )
+       {
+               for( j=1; j<locnjob-i; j++ ) 
+               {
+                       fprintf( hat2p, "%#6.3f", mtx[i][j] );
+                       if( j % 12 == 0 || j == locnjob-i-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+
+void WriteFloatHat2( FILE *hat2p, int locnjob, char name[M][B], float **mtx )
+{
+       int i, j;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=1; j<locnjob-i; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob; i++ )
+       {
+               for( j=1; j<locnjob-i; j++ ) 
+               {
+                       fprintf( hat2p, "%#6.3f", mtx[i][j] );
+                       if( j % 12 == 0 || j == locnjob-i-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+
+void WriteHat2_int( FILE *hat2p, int locnjob, char name[M][B], int **mtx )
+{
+       int i, j;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+       max /= INTMTXSCALE;
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob-1; i++ )
+       {
+               for( j=i+1; j<locnjob; j++ ) 
+               {
+                       fprintf( hat2p, "%#6.3f", (float)mtx[i][j] / INTMTXSCALE );
+                       if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+void WriteHat2_pointer( FILE *hat2p, int locnjob, char **name, double **mtx )
+{
+       int i, j;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob-1; i++ )
+       {
+               for( j=i+1; j<locnjob; j++ ) 
+               {
+                       fprintf( hat2p, "%#6.3f", mtx[i][j] );
+                       if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+void WriteHat2( FILE *hat2p, int locnjob, char name[M][B], double **mtx )
+{
+       int i, j;
+       double max = 0.0;
+       for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ ) if( mtx[i][j] > max ) max = mtx[i][j];
+
+       fprintf( hat2p, "%5d\n", 1 );
+       fprintf( hat2p, "%5d\n", locnjob );
+       fprintf( hat2p, " %#6.3f\n", max * 2.5 );
+
+       for( i=0; i<locnjob; i++ ) fprintf( hat2p, "%4d. %s\n", i+1, name[i] );
+       for( i=0; i<locnjob-1; i++ )
+       {
+               for( j=i+1; j<locnjob; j++ ) 
+               {
+                       fprintf( hat2p, "%#6.3f", mtx[i][j] );
+                       if( (j-i) % 12 == 0 || j == locnjob-1 ) fprintf( hat2p, "\n" );
+               }
+       }
+}
+
+#if 0
+void WriteHat2plain( FILE *hat2p, int locnjob, double **mtx )
+{
+       int i, j, ilim;
+
+       ilim = locnjob-1;
+       for( i=0; i<ilim; i++ )
+       {
+               fprintf( hat2p, "%d-%d d=%.3f\n", i+1, i+1, 0.0 );
+               for( j=i+1; j<locnjob; j++ ) 
+               {
+                       fprintf( hat2p, "%d-%d d=%.3f\n", i+1, j+1, mtx[i][j] );
+               }
+       }
+}
+#endif
+
+int ReadFasta_sub( FILE *fp, double *dis, int nseq, char name[M][B] )
+{
+    int i, count=0;
+    char b[B];
+    int junban[M];
+
+    count = 0;
+    for( i=0; i<10000000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+            count++;
+        }
+    }
+
+       for( i=0; i<nseq; i++ ) dis[i] = 0.0;
+    count = 0;
+    for( i=0; i<100000 && count<nseq; i++ )
+    {
+               if( fgets( b, B-1, fp ) ) break;
+        if( !strncmp( name[junban[count]], b, 20  ) )
+        {
+            fgets( b, B-1, fp );
+            dis[junban[count]] = atof( b );
+            count++;
+        }
+    }
+    return 0;
+}
+
+
+int ReadSsearch( FILE *fp, double *dis, int nseq, char name[M][B] )
+{
+    int i, count=0;
+    char b[B];
+    int junban[M];
+       int opt;
+
+    count = 0;
+    for( i=0; i<10000000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+                       sscanf( b+75, "%d", &opt ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+        }
+    }
+
+/*
+    count = 0;
+    for( i=0; i<100000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( name[junban[count]], b, 20  ) )
+        {
+            dis[junban[count]] = atof( b+65 );
+            count++;
+        }
+    }
+*/
+    return 0;
+}
+
+int ReadBlastm7_avscore( FILE *fp, double *dis, int nin )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int *junban;
+       double score, sumscore;
+       double len, sumlen;
+       int qstart, qend, tstart, tend;
+       double scorepersite;
+       static char qal[N], tal[N], al[N];
+       int nlocalhom;
+
+       junban = calloc( nin, sizeof( int ) );
+
+       count = 0;
+       sumscore = 0.0;
+       sumlen = 0.0;
+       score = 0.0;
+       len = 0.0;
+       scorepersite = 0.0; // by D.Mathog, a guess
+    while( 1 )
+       {
+
+               if( feof( fp ) ) break;
+
+               while( fgets( b, B-1, fp ) )
+               {
+                       if( !strncmp( "          <Hit_def>", b, 19 ) || !strncmp( "              <Hsp_num>", b, 23 ) ) break;
+               }
+
+               if( !strncmp( "          <Hit_def>", b, 19 ) )
+               {
+                       junban[count] = atoi( b+31 );
+                       nlocalhom = 0;
+               }
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_score>", b, 25 ) ) break;
+               pt = b + 25;
+               score = atof( pt );
+               sumscore += score;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-from>", b, 30 ) ) break;
+               pt = b + 30;
+               qstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-to>", b, 28 ) ) break;
+               pt = b + 28;
+               qend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-from>", b, 28 ) ) break;
+               pt = b + 28;
+               tstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-to>", b, 26 ) ) break;
+               pt = b + 26;
+               tend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_align-len>", b, 29 ) ) break;
+               pt = b + 29;
+               len = atoi( pt );
+               sumlen += len;
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_qseq>", al, 24 ) ) break;
+
+               strcpy( qal, al+24 );
+               pt = qal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_hseq>", al, 24 ) ) break;
+
+               strcpy( tal, al+24 );
+               pt = tal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+//             fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa );
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "            </Hsp>:", b, 18 ) ) break;
+
+
+               fgets( b, B-1, fp );
+
+
+               if( !strncmp( "          </Hit_hsps>", b, 21 ) )
+               {
+                       dis[junban[count++]] = sumscore;
+                       sumscore = 0.0;
+                       fgets( b, B-1, fp );
+                       fgets( b, B-1, fp );
+                       scorepersite = sumscore / sumlen;
+                       if( scorepersite != (int)scorepersite )
+                       {
+                               fprintf( stderr, "ERROR! sumscore=%f, sumlen=%f, and scorepersite=%f\n", sumscore, sumlen, scorepersite );
+                               exit( 1 );
+                       }
+
+                       if( !strncmp( "      </Iteration_hits>", b, 23 ) ) break;
+               }
+       }
+
+       free( junban );
+
+    return (int)scorepersite;
+}
+int ReadBlastm7_scoreonly( FILE *fp, double *dis, int nin )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int *junban;
+       int overlapaa;
+       double score, sumscore;
+       int qstart, qend, tstart, tend;
+       static char qal[N], tal[N], al[N];
+       int nlocalhom;
+
+       junban = calloc( nin, sizeof( int ) );
+
+       count = 0;
+       sumscore = 0.0;
+       score = 0.0;
+    while( 1 )
+       {
+
+               if( feof( fp ) ) break;
+
+               while( fgets( b, B-1, fp ) )
+               {
+                       if( !strncmp( "          <Hit_def>", b, 19 ) || !strncmp( "              <Hsp_num>", b, 23 ) ) break;
+               }
+
+               if( !strncmp( "          <Hit_def>", b, 19 ) )
+               {
+                       junban[count] = atoi( b+31 );
+                       nlocalhom = 0;
+               }
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_score>", b, 25 ) ) break;
+               pt = b + 25;
+               score = atof( pt );
+               sumscore += score;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-from>", b, 30 ) ) break;
+               pt = b + 30;
+               qstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-to>", b, 28 ) ) break;
+               pt = b + 28;
+               qend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-from>", b, 28 ) ) break;
+               pt = b + 28;
+               tstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-to>", b, 26 ) ) break;
+               pt = b + 26;
+               tend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_align-len>", b, 29 ) ) break;
+               pt = b + 29;
+               overlapaa = atoi( pt );
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_qseq>", al, 24 ) ) break;
+
+               strcpy( qal, al+24 );
+               pt = qal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_hseq>", al, 24 ) ) break;
+
+               strcpy( tal, al+24 );
+               pt = tal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+//             fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa );
+
+//             nlocalhom += addlocalhom_r( qal, tal, localhomlist+junban[count], qstart, tstart, score, overlapaa, nlocalhom );
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "            </Hsp>:", b, 18 ) ) break;
+
+
+               fgets( b, B-1, fp );
+
+
+               if( !strncmp( "          </Hit_hsps>", b, 21 ) )
+               {
+                       dis[junban[count++]] = sumscore;
+                       sumscore = 0.0;
+                       fgets( b, B-1, fp );
+                       fgets( b, B-1, fp );
+                       if( !strncmp( "      </Iteration_hits>", b, 23 ) ) break;
+               }
+       }
+
+       free( junban );
+
+    return count;
+}
+
+int ReadBlastm7( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    static int junban[M];
+       int overlapaa;
+       double score, sumscore;
+       int qstart, qend, tstart, tend;
+       static char qal[N], tal[N], al[N];
+       int nlocalhom;
+
+
+
+       count = 0;
+       sumscore = 0.0;
+       score = 0.0;
+       nlocalhom = 0;
+    while( 1 )
+       {
+
+               if( feof( fp ) ) break;
+
+               while( fgets( b, B-1, fp ) )
+               {
+                       if( !strncmp( "          <Hit_def>", b, 19 ) || !strncmp( "              <Hsp_num>", b, 23 ) ) break;
+               }
+
+               if( !strncmp( "          <Hit_def>", b, 19 ) )
+               {
+                       junban[count] = atoi( b+31 );
+                       nlocalhom = 0;
+               }
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_score>", b, 25 ) ) break;
+               pt = b + 25;
+               score = atof( pt );
+               sumscore += score;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-from>", b, 30 ) ) break;
+               pt = b + 30;
+               qstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_query-to>", b, 28 ) ) break;
+               pt = b + 28;
+               qend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-from>", b, 28 ) ) break;
+               pt = b + 28;
+               tstart = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_hit-to>", b, 26 ) ) break;
+               pt = b + 26;
+               tend = atoi( pt ) - 1;
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "              <Hsp_align-len>", b, 29 ) ) break;
+               pt = b + 29;
+               overlapaa = atoi( pt );
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_qseq>", al, 24 ) ) break;
+
+               strcpy( qal, al+24 );
+               pt = qal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+               while( fgets( al, N-100, fp ) )
+                       if( !strncmp( "              <Hsp_hseq>", al, 24 ) ) break;
+
+               strcpy( tal, al+24 );
+               pt = tal;
+               while( *++pt != '<' )
+                       ;
+               *pt = 0;
+
+
+//             fprintf( stderr, "t=%d, score = %f, qstart=%d, qend=%d, tstart=%d, tend=%d, overlapaa=%d\n", junban[count], score, qstart, qend, tstart, tend, overlapaa );
+
+               nlocalhom += addlocalhom_r( qal, tal, localhomlist+junban[count], qstart, tstart, score, overlapaa, nlocalhom );
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "            </Hsp>:", b, 18 ) ) break;
+
+
+               fgets( b, B-1, fp );
+
+
+               if( !strncmp( "          </Hit_hsps>", b, 21 ) )
+               {
+                       dis[junban[count++]] = sumscore;
+                       sumscore = 0.0;
+                       fgets( b, B-1, fp );
+                       fgets( b, B-1, fp );
+                       if( !strncmp( "      </Iteration_hits>", b, 23 ) ) break;
+               }
+       }
+    return count;
+}
+
+int ReadFasta34noalign( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    static int junban[M];
+       int opt;
+       double z, bits;
+
+
+    count = 0;
+#if 0
+    for( i=0; i<10000000 && count<nseq; i++ )
+#else
+    while( !feof( fp ) )
+#endif
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       pt = strchr( b, ')' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+
+        }
+    }
+
+    return count;
+}
+int ReadFasta34m10_nuc( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    static int junban[M];
+       int overlapaa;
+       int opt, qstart, qend, tstart, tend;
+       double z, bits;
+       int qal_display_start, tal_display_start;
+       static char qal[N], tal[N];
+       char *qal2, *tal2;
+       int c;
+
+
+    count = 0;
+#if 0
+    for( i=0; i<10000000 && count<nseq; i++ )
+#else
+    while( !feof( fp ) )
+#endif
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       if( strchr( b, 'r' ) ) continue;
+
+                       pt = strchr( b, ']' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+
+        }
+               else if( 0 == strncmp( ">>+==========+", b, 14 ) )
+               {
+                       break;
+               }
+
+    }
+       if( !count ) return -1;
+
+       count = 0;
+    while( 1 )
+       {
+               if( strncmp( ">>+==========+", b, 14 ) )
+               {
+                       fgets( b, B-1, fp );
+                       if( feof( fp ) ) break;
+                       continue;
+               }
+               junban[count++] = atoi( b+14 );
+//             fprintf( stderr, "t = %d\n", atoi( b+14 ) );
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               opt = atoi( pt );
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_overlap:", b+4, 9 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               overlapaa = atoi( pt );
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_start:", b+4, 7 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qstart = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_stop:", b+4, 6 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qend = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_display_start:", b+4, 15 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qal_display_start = atoi( pt ) - 1;
+
+               pt = qal;
+               while( (c = fgetc( fp )) )
+               {
+                       if( c == '>' ) 
+                       {
+                               ungetc( c, fp );
+                               break;
+                       }
+                       if( isalpha( c ) || c == '-' ) 
+                       *pt++ = c;
+               }
+               *pt = 0;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_start:", b+4, 7 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tstart = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_stop:", b+4, 6 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tend = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_display_start:", b+4, 15 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tal_display_start = atoi( pt ) - 1;
+
+               pt = tal;
+               while( ( c = fgetc( fp ) ) )
+               {
+                       if( c == '>' ) 
+                       {
+                               ungetc( c, fp );
+                               break;
+                       }
+                       if( isalpha( c ) || c == '-' ) 
+                       *pt++ = c;
+               }
+               *pt = 0;
+
+//             fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend );
+//             fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start );
+
+//             fprintf( stderr, "qal = %s\n", qal );
+//             fprintf( stderr, "tal = %s\n", tal );
+
+               qal2 = cutal( qal, qal_display_start, qstart, qend );
+               tal2 = cutal( tal, tal_display_start, tstart, tend );
+
+//             fprintf( stderr, "qal2 = %s\n", qal2 );
+//             fprintf( stderr, "tal2 = %s\n", tal2 );
+
+//             fprintf( stderr, "putting   %d - %d, opt = %d\n", qmem, junban[count-1], opt );
+               putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa );
+       }
+//     fprintf( stderr, "count = %d\n", count );
+    return count;
+}
+int ReadFasta34m10( FILE *fp, double *dis, int qmem, char name[M][B], LocalHom *localhomlist )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    static int junban[M];
+       int overlapaa;
+       int opt, qstart, qend, tstart, tend;
+       double z, bits;
+       int qal_display_start, tal_display_start;
+       static char qal[N], tal[N];
+       char *qal2, *tal2;
+       int c;
+
+
+    count = 0;
+#if 0
+    for( i=0; i<10000000 && count<nseq; i++ )
+#else
+    while( !feof( fp ) )
+#endif
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       pt = strchr( b, ')' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+
+        }
+               else if( 0 == strncmp( ">>+==========+", b, 14 ) )
+               {
+                       break;
+               }
+
+    }
+       if( !count ) return -1;
+
+       count = 0;
+    while( 1 )
+       {
+               if( strncmp( ">>+==========+", b, 14 ) )
+               {
+                       fgets( b, B-1, fp );
+                       if( feof( fp ) ) break;
+                       continue;
+               }
+               junban[count++] = atoi( b+14 );
+//             fprintf( stderr, "t = %d\n", atoi( b+14 ) );
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "; fa_opt:", b, 9 ) || !strncmp( "; sw_s-w opt:", b, 13 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               opt = atoi( pt );
+
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_overlap:", b+4, 9 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               overlapaa = atoi( pt );
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_start:", b+4, 7 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qstart = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_stop:", b+4, 6 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qend = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_display_start:", b+4, 15 ) ) break;
+               pt = strstr( b, ":" ) +1;
+               qal_display_start = atoi( pt ) - 1;
+
+               pt = qal;
+               while( (c = fgetc( fp )) )
+               {
+                       if( c == '>' ) 
+                       {
+                               ungetc( c, fp );
+                               break;
+                       }
+                       if( isalpha( c ) || c == '-' ) 
+                       *pt++ = c;
+               }
+               *pt = 0;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_start:", b+4, 7 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tstart = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_stop:", b+4, 6 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tend = atoi( pt ) - 1;
+
+               while( fgets( b, B-1, fp ) )
+                       if( !strncmp( "_display_start:", b+4, 15 ) ) break;
+               pt = strstr( b, ":" ) + 1;
+               tal_display_start = atoi( pt ) - 1;
+
+               pt = tal;
+               while( ( c = fgetc( fp ) ) )
+               {
+                       if( c == '>' ) 
+                       {
+                               ungetc( c, fp );
+                               break;
+                       }
+                       if( isalpha( c ) || c == '-' ) 
+                       *pt++ = c;
+               }
+               *pt = 0;
+
+//             fprintf( stderr, "(%d-%d:%d-%d)\n", qstart, qend, tstart, tend );
+//             fprintf( stderr, "qal_display_start = %d, tal_display_start = %d\n", qal_display_start, tal_display_start );
+
+//             fprintf( stderr, "qal = %s\n", qal );
+//             fprintf( stderr, "tal = %s\n", tal );
+
+               qal2 = cutal( qal, qal_display_start, qstart, qend );
+               tal2 = cutal( tal, tal_display_start, tstart, tend );
+
+//             fprintf( stderr, "qal2 = %s\n", qal2 );
+//             fprintf( stderr, "tal2 = %s\n", tal2 );
+
+//             fprintf( stderr, "putting   %d - %d, opt = %d\n", qmem, junban[count-1], opt );
+               putlocalhom( qal2, tal2, localhomlist+junban[count-1], qstart, tstart, opt, overlapaa );
+       }
+//     fprintf( stderr, "count = %d\n", count );
+    return count;
+}
+int ReadFasta34m10_scoreonly_nucbk( FILE *fp, double *dis, int nin )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int pos;
+       int opt;
+       double z, bits;
+
+    count = 0;
+    while( !feof( fp ) )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+===========+", b, 13 ) )
+        {
+            pos = atoi( b+13 );
+
+                       if( strchr( b, 'r' ) ) continue;
+
+//                     pt = strchr( b, ')' ) + 1;
+                       pt = strchr( b, ']' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+            dis[pos] += (double)opt;
+            count++;
+#if 0
+                       fprintf( stderr, "b=%s\n", b );
+                       fprintf( stderr, "opt=%d\n", opt );
+                       fprintf( stderr, "pos=%d\n", pos );
+                       fprintf( stderr, "dis[pos]=%f\n", dis[pos] );
+#endif
+
+        }
+               else if( 0 == strncmp( ">>><<<", b, 6 ) )
+               {
+                       break;
+               }
+
+    }
+       if( !count ) return -1;
+
+    return count;
+}
+
+int ReadFasta34m10_scoreonly_nuc( FILE *fp, double *dis, int nin )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int pos;
+       int opt;
+       double z, bits;
+       int c;
+       int *yonda;
+
+
+       yonda = AllocateIntVec( nin );
+       for( c=0; c<nin; c++ ) yonda[c] = 0;
+       for( c=0; c<nin; c++ ) dis[c] = 0.0;
+
+    count = 0;
+    while( !feof( fp ) )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+===========+", b, 13 ) )
+        {
+            pos = atoi( b+13 );
+
+                       if( strchr( b, 'r' ) ) continue;
+
+//                     pt = strchr( b, ')' ) + 1;
+                       pt = strchr( b, ']' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+                       if( yonda[pos] == 0 )
+                       {
+                   dis[pos] += (double)opt;
+                               yonda[pos] = 1;
+                       }
+            count++;
+#if 0
+                       fprintf( stderr, "b=%s\n", b );
+                       fprintf( stderr, "opt=%d\n", opt );
+                       fprintf( stderr, "pos=%d\n", pos );
+                       fprintf( stderr, "dis[pos]=%f\n", dis[pos] );
+#endif
+
+        }
+        else if( !strncmp( ">>>", b, 3 ) )
+               {
+                       for( c=0; c<nin; c++ ) yonda[c] = 0;
+               }
+               else if( 0 == strncmp( ">>><<<", b, 6 ) )
+               {
+                       break;
+               }
+
+    }
+
+       free( yonda );
+
+       if( !count ) return -1;
+
+    return count;
+}
+
+int ReadFasta34m10_scoreonly( FILE *fp, double *dis, int nin )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int pos;
+       int opt;
+       double z, bits;
+       int c;
+       int *yonda;
+
+
+       yonda = AllocateIntVec( nin );
+       for( c=0; c<nin; c++ ) yonda[c] = 0;
+       for( c=0; c<nin; c++ ) dis[c] = 0.0;
+
+    count = 0;
+    while( !feof( fp ) )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+===========+", b, 13 ) )
+        {
+            pos = atoi( b+13 );
+
+                       pt = strchr( b, ')' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+                       if( yonda[pos] == 0 )
+                       {
+                   dis[pos] += (double)opt;
+                               yonda[pos] = 1;
+                       }
+            count++;
+#if 0
+                       fprintf( stderr, "b=%s\n", b );
+                       fprintf( stderr, "opt=%d\n", opt );
+                       fprintf( stderr, "pos=%d\n", pos );
+                       fprintf( stderr, "dis[pos]=%f\n", dis[pos] );
+#endif
+
+        }
+        else if( !strncmp( ">>>", b, 3 ) )
+               {
+                       for( c=0; c<nin; c++ ) yonda[c] = 0;
+               }
+               else if( 0 == strncmp( ">>><<<", b, 6 ) )
+               {
+                       break;
+               }
+
+    }
+
+       free( yonda );
+
+       if( !count ) return -1;
+
+    return count;
+}
+int ReadFasta34( FILE *fp, double *dis, int nseq, char name[M][B], LocalHom *localhomlist )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    static int junban[M];
+       int overlapaa;
+       int opt, qstart, qend, tstart, tend;
+       double z, bits;
+
+
+    count = 0;
+#if 0
+    for( i=0; i<10000000 && count<nseq; i++ )
+#else
+    while( !feof( fp ) )
+#endif
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       pt = strchr( b, ')' ) + 1;
+                       sscanf( pt, "%d %lf %lf",  &opt, &bits, &z ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+
+        }
+               else if( 0 == strncmp( ">>+==========+", b, 14 ) )
+               {
+                       break;
+               }
+
+    }
+       if( !count ) return -1;
+
+       count = 0;
+    while( !feof( fp ) )
+       {
+               if( !strncmp(">>+==========+", b, 14 ) )
+               {
+            junban[count] = atoi( b+14 );
+            count++;
+               fgets( b, B-1, fp ); // initn:
+                       pt = strstr( b, "opt: " ) + 5;
+                       localhomlist[junban[count-1]].opt = atof( pt );
+               fgets( b, B-1, fp ); // Smith-Waterman score
+                       pt = strstr( b, "ungapped) in " ) + 13;
+                       sscanf( pt, "%d", &overlapaa ); 
+                       fprintf( stderr, "pt = %s, overlapaa = %d\n", pt, overlapaa );
+                       pt = strstr( b, "overlap (" ) + 8;
+                       sscanf( pt, "(%d-%d:%d-%d)", &qstart, &qend, &tstart, &tend ); 
+                       localhomlist[junban[count-1]].overlapaa = overlapaa;
+                       localhomlist[junban[count-1]].start1 = qstart-1;
+                       localhomlist[junban[count-1]].end1   = qend-1;
+                       localhomlist[junban[count-1]].start2 = tstart-1;
+                       localhomlist[junban[count-1]].end2   = tend-1;
+               }
+        fgets( b, B-1, fp );
+       }
+       fprintf( stderr, "count = %d\n", count );
+    return count;
+}
+
+int ReadFasta3( FILE *fp, double *dis, int nseq, char name[M][B] )
+{
+    int count=0;
+    char b[B];
+       char *pt;
+    int junban[M];
+       int initn, init1, opt;
+       double z;
+
+    count = 0;
+#if 0
+    for( i=0; i<10000000 && count<nseq; i++ )
+#else
+    while( !feof( fp ) )
+#endif
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       pt = strchr( b, ')' ) + 1;
+                       sscanf( pt, "%d %d %d %lf", &initn, &init1, &opt, &z ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+        }
+    }
+    return 0;
+}
+
+int ReadFasta( FILE *fp, double *dis, int nseq, char name[M][B] )
+{
+    int i, count=0;
+    char b[B];
+    int junban[M];
+       int initn, init1, opt;
+
+    count = 0;
+       for( i=0; i<nseq; i++ ) dis[i] = 0.0;
+    for( i=0; !feof( fp ) && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+
+                       sscanf( b+50, "%d %d %d", &initn, &init1, &opt ); 
+            dis[junban[count]] = (double)opt;
+            count++;
+        }
+    }
+
+/*
+    count = 0;
+    for( i=0; i<100000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( name[junban[count]], b, 20  ) )
+        {
+            dis[junban[count]] = atof( b+65 );
+            count++;
+        }
+    }
+*/
+    return 0;
+}
+
+
+int ReadOpt( FILE *fp, int opt[M], int nseq, char name[M][B] )
+{
+    int i, count=0;
+    char b[B];
+    int junban[M];
+       int optt, initn, init1;
+
+    count = 0;
+    for( i=0; i<10000000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+                       sscanf( b+50, "%d %d %d", &initn, &init1, &optt ); 
+            opt[junban[count]] = (double)optt;
+            count++;
+        }
+    }
+    return 0;
+}
+
+int ReadOpt2( FILE *fp, int opt[M], int nseq, char name[M][B] )
+{
+    int i, count=0;
+    char b[B];
+    int junban[M];
+
+    count = 0;
+    for( i=0; i<10000000 && count<nseq; i++ )
+    {
+        fgets( b, B-1, fp );
+        if( !strncmp( "+==========+", b, 12 ) )
+        {
+            junban[count] = atoi( b+12 );
+            opt[junban[count]] = atoi( b+65 );
+            count++;
+        }
+    }
+    return 0;
+}
+
+
+
+int writePre( int nseq, char **name, int nlen[M], char **aseq, int force )
+{
+#if USE_XCED
+       int i, value;
+       if( !signalSM )
+       {
+               if( force ) 
+               {
+                       rewind( prep_g );
+                       if( devide ) dvWrite( prep_g, nseq, name, nlen, aseq );
+#if 0
+                       else    WriteGapFill( prep_g, nseq, name, nlen, aseq );
+#else
+                       else    writeData( prep_g, nseq, name, nlen, aseq );
+#endif
+               }
+               return( 0 );
+       }
+       for( i=0; i<10; i++ )
+       {
+#if IODEBUG
+               fprintf( stderr, "SEMAPHORE = %d\n", signalSM[SEMAPHORE] );
+#endif
+               if( signalSM[SEMAPHORE]-- > 0 )
+               {
+#if 0 /* /tmp/pre ¤Î´Ø·¸¤Ç¤Ï¤º¤·¤¿ */
+                       if( ferror( prep_g ) ) prep_g = fopen( "pre", "w" );
+                       if( !prep_g ) ErrorExit( "Cannot re-open pre." ); 
+#endif
+                       rewind( prep_g );
+                       signalSM[STATUS] = IMA_KAITERU;
+#if IODEBUG
+                       if( force ) fprintf( stderr, "FINAL " );
+#endif
+                       if( devide ) dvWrite( prep_g, nseq, name, nlen, aseq );
+                       else    WriteGapFill( prep_g, nseq, name, nlen, aseq );
+                       /*
+                       fprintf( prep_g, '\EOF' );
+                       */
+                       fflush( prep_g );
+                       if( force ) signalSM[STATUS] = OSHIMAI;
+                       else        signalSM[STATUS] = KAKIOWATTA;
+                       value = 1;
+                       signalSM[SEMAPHORE]++;
+#if IODEBUG
+                       fprintf( stderr, "signalSM[STATUS] = %c\n", signalSM[STATUS] );
+#endif
+                       break;
+               }
+               else
+               {
+#if IODEBUG
+                       fprintf( stderr, "YONDERUKARA_AKIRAMERU\n" );
+#endif
+                       value = 0;
+                       signalSM[SEMAPHORE]++;
+                       if( !force ) break;
+#if IODEBUG
+                       fprintf( stderr, "MATSU\n" );
+#endif
+                       sleep( 1 );
+               }
+       }
+       if( force && !value ) ErrorExit( "xced ga pre wo hanasanai \n" );
+       return( value );
+#else
+       if( force ) 
+       {
+               rewind( prep_g );
+               writeData_pointer( prep_g, nseq, name, nlen, aseq );
+       }
+#endif
+       return( 0 );
+}
+
+
+void readOtherOptions( int *ppidptr, int *fftThresholdptr, int *fftWinSizeptr )
+{
+       if( calledByXced )
+       {
+               FILE *fp = fopen( "pre", "r" );
+               char b[B];
+               if( !fp ) ErrorExit( "Cannot open pre.\n" );
+               fgets( b, B-1, fp );
+               sscanf( b, "%d %d %d", ppidptr, fftThresholdptr, fftWinSizeptr );
+               fclose( fp );
+#if IODEBUG
+       fprintf( stderr, "b = %s\n", b );
+       fprintf( stderr, "ppid = %d\n", ppid );
+       fprintf( stderr, "fftThreshold = %d\n", fftThreshold );
+       fprintf( stderr, "fftWinSize = %d\n", fftWinSize );
+#endif
+       }
+       else
+       {
+               *ppidptr = 0;
+               *fftThresholdptr = FFT_THRESHOLD;
+               if( dorp == 'd' )
+                       *fftWinSizeptr = FFT_WINSIZE_D;
+               else
+                       *fftWinSizeptr = FFT_WINSIZE_P;
+       }
+#if 0
+       fprintf( stderr, "fftThresholdptr=%d\n", *fftThresholdptr );
+       fprintf( stderr, "fftWinSizeptr=%d\n", *fftWinSizeptr );
+#endif
+}
+
+void initSignalSM( void )
+{
+//     int signalsmid;
+
+#if IODEBUG
+       if( ppid ) fprintf( stderr, "PID of xced = %d\n", ppid );
+#endif
+       if( !ppid )
+       {
+               signalSM = NULL;
+               return;
+       }
+
+#if 0
+       signalsmid = shmget( (key_t)ppid, 3, IPC_ALLOC | 0666 );
+       if( signalsmid == -1 ) ErrorExit( "Cannot get Shared memory for signal.\n" );
+       signalSM = shmat( signalsmid, 0, 0 );
+       if( (int)signalSM == -1 ) ErrorExit( "Cannot attatch Shared Memory for signal!\n" );
+       signalSM[STATUS] = IMA_KAITERU;
+       signalSM[SEMAPHORE] = 1;
+#endif
+}
+
+void initFiles( void )
+{
+       char pname[100];
+       if( ppid )
+               sprintf( pname, "/tmp/pre.%d", ppid );
+       else
+               sprintf( pname, "pre" );
+       prep_g = fopen( pname, "w" );
+       if( !prep_g ) ErrorExit( "Cannot open pre" );
+
+       trap_g = fopen( "trace", "w" );
+       if( !trap_g ) ErrorExit( "cannot open trace" );
+       fprintf( trap_g, "PID = %d\n", getpid() );
+       fflush( trap_g );
+}
+
+
+void WriteForFasta( FILE *fp, int locnjob, char name[][B], int nlen[M], char **aseq )
+{
+    static char b[N];
+    int i, j;
+    int nalen[M];
+
+    for( i=0; i<locnjob; i++ )
+    {
+        nalen[i] = strlen( aseq[i] );
+        fprintf( fp, ">%s\n", name[i] );
+        for( j=0; j<nalen[i]; j=j+C ) 
+        {
+            strncpy( b, aseq[i]+j, C ); b[C] = 0;
+            fprintf( fp, "%s\n",b );
+        }
+    }
+}
+
+void readlocalhomtable2( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec )
+{
+       double opt;
+       static char buff[B];
+       char infor[100];
+       int i, j, overlapaa, start1, end1, start2, end2;
+       LocalHom *tmpptr1, *tmpptr2;
+
+//     for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) nlocalhom[i][j] = 0;
+
+       while ( NULL != fgets( buff, B-1, fp ) )
+       {
+//             fprintf( stderr, "\n" );
+               sscanf( buff, "%d %d %d %lf %d %d %d %d %s",  &i, &j, &overlapaa, &opt, &start1, &end1, &start2, &end2, infor );
+               if( *infor == 'k' ) kozoarivec[i] = kozoarivec[j] = 1;
+
+#if 0
+               if( start1 == end1 || start2 == end2 ) continue; //mondai ari
+#endif
+
+//             if( i < j )
+               {
+                       if( localhomtable[i][j].nokori++ > 0 )
+                       {
+                               tmpptr1 = localhomtable[i][j].last;
+//                             fprintf( stderr, "reallocating, localhomtable[%d][%d].nokori = %d\n", i, j, localhomtable[i][j].nokori );
+                               tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+                               tmpptr1 = tmpptr1->next;
+                               tmpptr1->extended = -1;
+                               tmpptr1->next = NULL;
+                               localhomtable[i][j].last = tmpptr1;
+//                             fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori );
+                       }
+                       else
+                       {
+                               tmpptr1 = localhomtable[i]+j;
+//                             fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", i, j, localhomtable[i][j].nokori );
+                       }
+       
+                       tmpptr1->start1 = start1;
+                       tmpptr1->start2 = start2;
+                       tmpptr1->end1 = end1;
+                       tmpptr1->end2 = end2;
+//                     tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8  * 600;
+//                     tmpptr1->opt = opt;
+                       tmpptr1->opt = ( opt + 0.00 ) / 5.8  * 600;
+                       tmpptr1->overlapaa = overlapaa;
+                       tmpptr1->korh = *infor;
+               }
+//             else
+               {
+                       if( localhomtable[j][i].nokori++ > 0 )
+                       {
+                               tmpptr2 = localhomtable[j][i].last;
+                               tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+                               tmpptr2 = tmpptr2->next;
+                               tmpptr2->extended = -1;
+                               tmpptr2->next = NULL;
+                               localhomtable[j][i].last = tmpptr2;
+//                             fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori );
+                       }
+                       else
+                       {
+                               tmpptr2 = localhomtable[j]+i;
+//                             fprintf( stderr, "### i,j = %d,%d, nokori=%d\n", j, i, localhomtable[j][i].nokori );
+                       }
+       
+                       tmpptr2->start2 = start1;
+                       tmpptr2->start1 = start2;
+                       tmpptr2->end2 = end1;
+                       tmpptr2->end1 = end2;
+//                     tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8  * 600;
+//                     tmpptr2->opt = opt;
+                       tmpptr2->opt = ( opt + 0.00 ) / 5.8  * 600;
+                       tmpptr2->overlapaa = overlapaa;
+                       tmpptr2->korh = *infor;
+       
+//                     fprintf( stderr, "i=%d, j=%d, st1=%d, en1=%d, opt = %f\n", i, j, tmpptr1->start1, tmpptr1->end1, opt );
+               }
+
+       }
+}
+void readlocalhomtable( FILE*fp, int njob, LocalHom **localhomtable, char *kozoarivec )
+{
+       double opt;
+       static char buff[B];
+       char infor[100];
+       int i, j, overlapaa, start1, end1, start2, end2;
+       int **nlocalhom = NULL;
+       LocalHom *tmpptr1=NULL, *tmpptr2=NULL; // by D.Mathog, a guess
+
+       nlocalhom = AllocateIntMtx( njob, njob );
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) nlocalhom[i][j] = 0;
+
+       while ( NULL != fgets( buff, B-1, fp ) )
+       {
+//             fprintf( stderr, "\n" );
+               sscanf( buff, "%d %d %d %lf %d %d %d %d %s",  &i, &j, &overlapaa, &opt, &start1, &end1, &start2, &end2, infor );
+               if( *infor == 'k' ) kozoarivec[i] = kozoarivec[j] = 1;
+
+#if 0
+               if( start1 == end1 || start2 == end2 ) continue; //mondai ari
+#endif
+
+
+//             if( i < j )
+               {
+                       if( nlocalhom[i][j]++ > 0 )
+                       {
+//                             fprintf( stderr, "reallocating, nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] );
+                               tmpptr1->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+                               tmpptr1 = tmpptr1->next;
+                               tmpptr1->next = NULL;
+                       }
+                       else
+                       {
+                               tmpptr1 = localhomtable[i]+j;
+//                             fprintf( stderr, "nlocalhom[%d][%d] = %d\n", i, j, nlocalhom[i][j] );
+                       }
+       
+                       tmpptr1->start1 = start1;
+                       tmpptr1->start2 = start2;
+                       tmpptr1->end1 = end1;
+                       tmpptr1->end2 = end2;
+//                     tmpptr1->opt = ( opt / overlapaa + 0.00 ) / 5.8  * 600;
+//                     tmpptr1->opt = opt;
+                       tmpptr1->opt = ( opt + 0.00 ) / 5.8  * 600;
+                       tmpptr1->overlapaa = overlapaa;
+                       tmpptr1->korh = *infor;
+       
+//                     fprintf( stderr, "i=%d, j=%d, opt = %f\n", i, j, opt );
+               }
+//             else
+               {
+                       if( nlocalhom[j][i]++ > 0 )
+                       {
+                               tmpptr2->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+                               tmpptr2 = tmpptr2->next;
+                               tmpptr2->next = NULL;
+                       }
+                       else
+                               tmpptr2 = localhomtable[j]+i;
+       
+                       tmpptr2->start2 = start1;
+                       tmpptr2->start1 = start2;
+                       tmpptr2->end2 = end1;
+                       tmpptr2->end1 = end2;
+//                     tmpptr2->opt = ( opt / overlapaa + 0.00 ) / 5.8  * 600;
+//                     tmpptr2->opt = opt;
+                       tmpptr2->opt = ( opt + 0.00 ) / 5.8  * 600;
+                       tmpptr2->overlapaa = overlapaa;
+                       tmpptr2->korh = *infor;
+               }
+
+       }
+       FreeIntMtx( nlocalhom );
+}
+
+void outlocalhom( LocalHom **localhom, int nseq )
+{
+       int i, j;
+       LocalHom *tmpptr;
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ )
+       {
+               tmpptr = localhom[i]+j;
+               fprintf( stderr, "%d-%d\n", i, j );
+               do
+               {
+                       fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f, opt=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt );
+               }
+               while( (tmpptr=tmpptr->next) );
+       }
+}
+
+void outlocalhompt( LocalHom ***localhom, int n1, int n2 )
+{
+       int i, j;
+       LocalHom *tmpptr;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               tmpptr = localhom[i][j];
+               fprintf( stderr, "%d-%d\n", i, j );
+               do
+               {
+                       fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f, opt=%f, wimp=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->importance, tmpptr->opt, tmpptr->wimportance );
+               }
+               while( (tmpptr=tmpptr->next) );
+       }
+}
+
+void FreeLocalHomTable( LocalHom **localhomtable, int n ) 
+{
+       int i, j;
+       LocalHom *ppp, *tmpptr;
+       for( i=0; i<n; i++ ) 
+       {
+               for( j=0; j<n; j++ )
+               {
+                       tmpptr=localhomtable[i]+j;
+                       ppp = tmpptr->next;
+                       for( ; tmpptr; tmpptr=ppp )
+                       {
+#if DEBUG
+                               fprintf( stderr, "i=%d, j=%d\n", i, j ); 
+#endif
+                               ppp = tmpptr->next;
+                               if( tmpptr!=localhomtable[i]+j ) 
+                               {
+#if DEBUG
+                                       fprintf( stderr, "freeing %p\n", tmpptr );
+#endif
+                                       free( tmpptr );
+                               }
+                       }
+               }
+#if DEBUG
+               fprintf( stderr, "freeing localhomtable[%d]\n", i );
+#endif
+               free( localhomtable[i] );
+       }
+#if DEBUG
+       fprintf( stderr, "freeing localhomtable\n" );
+#endif
+       free( localhomtable );
+#if DEBUG
+       fprintf( stderr, "freed\n" );
+#endif
+}
+
+char *progName( char *str )
+{
+    char *value; 
+    if( ( value = strrchr( str, '/' ) ) != NULL )
+        return( value+1 );
+    else    
+        return( str );
+}
+
+static void tabtospace( char *str )
+{
+       char *p;
+//     fprintf( stderr, "before = %s\n", str );
+       while( NULL != ( p = strchr( str , '\t' ) ) )
+       {
+               *p = ' ';
+       }
+//     fprintf( stderr, "after = %s\n", str );
+}
+
+static char *extractfirstword( char *str )
+{
+       char *val = str;
+
+       tabtospace( str );
+       while( *str )
+       {
+               if( val == str && *str == ' ' )
+               {
+                       val++; str++;
+               }
+               else if( *str != ' ' )
+               {
+                       str++;
+               }
+               else if( *str == ' ' )
+               {
+                       *str = 0;
+               }
+       }
+       return( val );
+}
+
+void phylipout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, int *order )
+{
+       int pos, pos2, j;
+       pos = 0;
+
+       fprintf( fp, " %d %d\n", nseq, maxlen );
+       
+       while( pos < maxlen )
+       {
+               for( j=0; j<nseq; j++ )
+               {
+                       if( pos == 0 )
+                               fprintf( fp, "%-10.10s", extractfirstword( name[order[j]]+1 ) );
+                       else
+                               fprintf( fp, "          " );
+
+                       pos2 = pos;
+                       while( pos2 < pos+41 && pos2 < maxlen )
+                       {
+                               fprintf( fp, " %.10s", seq[order[j]]+pos2 );
+                               pos2 += 10;
+                       }
+                       fprintf( fp, "\n" );
+               }
+               fprintf( fp, "\n" );
+               pos += 50;
+       }
+}
+
+void clustalout_pointer( FILE *fp, int nseq, int maxlen, char **seq, char **name, char *mark, char *comment, int *order, int namelen )
+{
+       int pos, j;
+       pos = 0;
+       if( comment == NULL )
+               fprintf( fp, "CLUSTAL format alignment by MAFFT (v%s)\n\n", VERSION );
+       else
+               fprintf( fp, "CLUSTAL format alignment by MAFFT %s (v%s)\n\n", comment, VERSION );
+       
+       while( pos < maxlen )
+       {
+               fprintf( fp, "\n" );
+               for( j=0; j<nseq; j++ )
+               {
+                       fprintf( fp, "%-*.*s ", namelen, namelen, extractfirstword( name[order[j]]+1 ) );
+                       fprintf( fp, "%.60s\n", seq[order[j]]+pos ); // Ä¹¤µ¤¬°ã¤¦¤È¤À¤á¡£
+               }
+               if( mark )
+               {
+                       fprintf( fp, "%-*.*s ", namelen, namelen, "" );
+                       fprintf( fp, "%.60s\n", mark + pos ); // Ä¹¤µ¤¬°ã¤¦¤È¤À¤á¡£
+               }
+               pos += 60;
+       }
+}
+
+
+void writeData_reorder_pointer( FILE *fp, int locnjob, char **name, int *nlen, char **aseq, int *order )
+{
+       int i, j, k;
+       int nalen;
+
+       for( i=0; i<locnjob; i++ )
+       {
+               k = order[i];
+#if DEBUG
+               fprintf( stderr, "i = %d in writeData\n", i );
+#endif
+               nalen = strlen( aseq[k] );
+               fprintf( fp, ">%s\n", name[k]+1 );
+               for( j=0; j<nalen; j=j+C )
+               {
+#if 0
+                       strncpy( b, aseq[k]+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+#else
+                       fprintf( fp, "%.*s\n", C, aseq[k]+j );
+#endif
+               }
+       }
+}
+void writeData_reorder( FILE *fp, int locnjob, char name[][B], int nlen[], char **aseq, int *order )
+{
+       int i, j, k;
+       int nalen;
+
+       for( i=0; i<locnjob; i++ )
+       {
+               k = order[i];
+#if DEBUG
+               fprintf( stderr, "i = %d in writeData\n", i );
+#endif
+               nalen = strlen( aseq[k] );
+               fprintf( fp, ">%s\n", name[k]+1 );
+               for( j=0; j<nalen; j=j+C )
+               {
+#if 0
+                       strncpy( b, aseq[k]+j, C ); b[C] = 0;
+                       fprintf( fp, "%s\n",b );
+#else
+                       fprintf( fp, "%.*s\n", C, aseq[k]+j );
+#endif
+               }
+       }
+}
+static void showaamtxexample()
+{
+       fprintf( stderr, "Format error in aa matrix\n" );
+       fprintf( stderr, "# Example:\n" );
+       fprintf( stderr, "# comment\n" );
+       fprintf( stderr, "   A  R  N  D  C  Q  E  G  H  I  L  K  M  F  P  S  T  W  Y  V\n" );
+       fprintf( stderr, "A  4 -1 -2 -2  0 -1 -1  0 -2 -1 -1 -1 -1 -2 -1  1  0 -3 -2  0\n" );
+       fprintf( stderr, "R -1  5  0 -2 -3  1  0 -2  0 -3 -2  2 -1 -3 -2 -1 -1 -3 -2 -3\n" );
+       fprintf( stderr, "...\n" );
+       fprintf( stderr, "V  0 -3 -3 -3 -1 -2 -2 -3 -3  3  1 -2  1 -1 -2 -2  0 -3 -1  4\n" );
+       fprintf( stderr, "frequency 0.07 0.05 0.04 0.05 0.02 .. \n" );
+       fprintf( stderr, "# Example end\n" );
+       fprintf( stderr, "Only the lower half is loaded\n" );
+       fprintf( stderr, "The last line (frequency) is optional.\n" );
+       exit( 1 );
+}
+
+double *loadaamtx( void )
+{
+       int i, j, k, ii, jj;
+       double *val;
+       double **raw;
+       int *map;
+       char *aaorder = "ARNDCQEGHILKMFPSTWYV";
+       char *inorder;
+       char *line;
+       char *ptr1;
+       char *ptr2;
+       char *mtxfname = "_aamtx";
+       FILE *mf;
+
+       raw = AllocateDoubleMtx( 21, 20 );
+       val = AllocateDoubleVec( 420 );
+       map = AllocateIntVec( 20 );
+
+       if( dorp != 'p' )
+       {
+               fprintf( stderr, "User-defined matrix is not supported for DNA\n" );
+               exit( 1 );
+       }
+
+       mf = fopen( mtxfname, "r" );
+       if( mf == NULL )
+       {
+               fprintf( stderr, "Cannot open the _aamtx file\n" );
+               exit( 1 );
+       }
+
+       inorder = calloc( 1000, sizeof( char ) );
+       line = calloc( 1000, sizeof( char ) );
+       
+
+       while( !feof( mf ) )
+       {
+               fgets( inorder, 999, mf );
+               if( inorder[0] != '#' ) break;
+       }
+       ptr1 = ptr2 = inorder;
+       while( *ptr2 )
+       {
+               if( isalpha( *ptr2 ) )
+               {
+                       *ptr1 = toupper( *ptr2 );
+                       ptr1++;
+               }
+               ptr2++;
+       }
+       inorder[20] = 0;
+
+       for( i=0; i<20; i++ )
+       {
+               ptr2 = strchr( inorder, aaorder[i] );
+               if( ptr2 == NULL )
+               {
+                       fprintf( stderr, "%c: not found in the first 20 letters.\n", aaorder[i] );
+                       showaamtxexample();
+               }
+               else
+               {
+                       map[i] = ptr2 - inorder;
+               }
+       }
+
+       i = 0;
+       while( !feof( mf ) )
+       {
+               fgets( line, 999, mf );
+//             fprintf( stderr, "line = %s\n", line );
+               if( line[0] == '#' ) continue;
+               ptr1 = line;
+//             fprintf( stderr, "line = %s\n", line );
+               for( j=0; j<=i; j++ )
+               {
+                       while( !isdigit( *ptr1 ) && *ptr1 != '-' && *ptr1 != '.' )
+                               ptr1++;
+
+                       raw[i][j] = atof( ptr1 );
+//                     fprintf( stderr, "raw[][]=%f, %c-%c %d-%d\n", raw[i][j], inorder[i], inorder[j], i, j );
+                       ptr1 = strchr( ptr1, ' ' );
+                       if( ptr1 == NULL && j<i) showaamtxexample();
+               }
+               i++;
+               if( i > 19 ) break;
+       }
+
+       for( i=0; i<20; i++ ) raw[20][i] = -1.0;
+       while( !feof( mf ) )
+       {
+               fgets( line, 999, mf );
+               if( line[0] == 'f' )
+               {
+//                     fprintf( stderr, "line = %s\n", line );
+                       ptr1 = line;
+                       for( j=0; j<20; j++ )
+                       {
+                               while( !isdigit( *ptr1 ) && *ptr1 != '-' && *ptr1 != '.' )
+                                       ptr1++;
+       
+                               raw[20][j] = atof( ptr1 );
+//                             fprintf( stderr, "raw[20][]=%f, %c %d\n", raw[20][j], inorder[i], j );
+                               ptr1 = strchr( ptr1, ' ' );
+                               if( ptr1 == NULL && j<19) showaamtxexample();
+                       }
+                       break;
+               }
+       }
+
+       k = 0;
+       for( i=0; i<20; i++ )
+       {
+               for( j=0; j<=i; j++ )
+               {
+                       if( i != j )
+                       {
+                               ii = MAX( map[i], map[j] );
+                               jj = MIN( map[i], map[j] );
+                       }
+                       else ii = jj = map[i];
+                       val[k++] = raw[ii][jj];
+//                     fprintf( stderr, "%c-%c, %f\n", aaorder[i], aaorder[j], val[k-1] );
+               }
+       }
+       for( i=0; i<20; i++ ) val[400+i] = raw[20][map[i]];
+
+       fprintf( stderr, "inorder = %s\n", inorder );
+       fclose( mf );
+       free( inorder );
+       free( line );
+       FreeDoubleMtx( raw );
+       free( map );
+       return( val );
+}
+
+
+void readmccaskill( FILE *fp, RNApair **pairprob, int length )
+{
+       char gett[1000];
+       int *pairnum;
+       int i;
+       int left, right;
+       float prob;
+       int c;
+
+       pairnum = (int *)calloc( length, sizeof( int ) );
+       for( i=0; i<length; i++ ) pairnum[i] = 0;
+
+       c = getc( fp );
+       {
+               if( c != '>' )
+               {
+                       fprintf( stderr, "format error in hat4\n" );
+                       exit( 1 );
+               }
+       }
+       fgets( gett, 999, fp );
+       while( 1 )
+       {
+               if( feof( fp ) ) break;
+               c = getc( fp );
+               ungetc( c, fp );
+               if( c == '>' )
+               {
+                       break;
+               }
+               fgets( gett, 999, fp );
+//             fprintf( stderr, "gett = %s\n", gett );
+               sscanf( gett, "%d %d %f", &left, &right, &prob );
+
+               if( left >= length || right >= length )
+               {
+                       fprintf( stderr, "format error in hat4\n" );
+                       exit( 1 );
+               }
+
+               if( prob < 0.01 ) continue; // 080607, mafft ni dake eikyou
+
+               if( left != right && prob > 0.0 )
+               {
+                       pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) );
+                       pairprob[left][pairnum[left]].bestscore = prob;
+                       pairprob[left][pairnum[left]].bestpos = right;
+                       pairnum[left]++;
+                       pairprob[left][pairnum[left]].bestscore = -1.0;
+                       pairprob[left][pairnum[left]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+
+                       pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) );
+                       pairprob[right][pairnum[right]].bestscore = prob;
+                       pairprob[right][pairnum[right]].bestpos = left;
+                       pairnum[right]++;
+                       pairprob[right][pairnum[right]].bestscore = -1.0;
+                       pairprob[right][pairnum[right]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", right, left, prob );
+               }
+       }
+       free( pairnum );
+}
+
+void readpairfoldalign( FILE *fp, char *s1, char *s2, char *aln1, char *aln2, int q1, int q2, int *of1, int *of2, int sumlen )
+{
+       char gett[1000];
+       int *maptoseq1;
+       int *maptoseq2;
+       char dumc;
+       int dumi;
+       char sinseq[100], sinaln[100];
+       int posinseq, posinaln;
+       int alnlen;
+       int i;
+       int pos1, pos2;
+       char *pa1, *pa2;
+       char qstr[1000];
+
+       *of1 = -1;
+       *of2 = -1;
+
+       maptoseq1 = AllocateIntVec( sumlen+1 );
+       maptoseq2 = AllocateIntVec( sumlen+1 );
+
+       posinaln = 0; // foldalign ga alingment wo kaesanaitok no tame.
+
+       while( !feof( fp ) )
+       {
+               fgets( gett, 999, fp );
+               if( !strncmp( gett, "; ALIGNING", 10 ) ) break;
+       }
+       sprintf( qstr, "; ALIGNING            %d against %d\n", q1+1, q2+1 );
+       if( strcmp( gett, qstr ) )
+       {
+               fprintf( stderr, "Error in FOLDALIGN\n" );
+               fprintf( stderr, "qstr = %s, but gett = %s\n", qstr, gett );
+               exit( 1 );
+       }
+
+       while( !feof( fp ) )
+       {
+               fgets( gett, 999, fp );
+               if( !strncmp( gett, "; --------", 10 ) ) break;
+       }
+
+
+       while( !feof( fp ) )
+       {
+               fgets( gett, 999, fp );
+               if( !strncmp( gett, "; ********", 10 ) ) break;
+//             fprintf( stderr, "gett = %s\n", gett );
+               sscanf( gett, "%c %c %s %s %d %d", &dumc, &dumc, sinseq, sinaln, &dumi, &dumi );
+               posinaln = atoi( sinaln );
+               posinseq = atoi( sinseq );
+//             fprintf( stderr, "posinseq = %d\n", posinseq );
+//             fprintf( stderr, "posinaln = %d\n", posinaln );
+               maptoseq1[posinaln-1] = posinseq-1;
+       }
+       alnlen = posinaln;
+
+       while( !feof( fp ) )
+       {
+               fgets( gett, 999, fp );
+               if( !strncmp( gett, "; --------", 10 ) ) break;
+       }
+
+       while( !feof( fp ) )
+       {
+               fgets( gett, 999, fp );
+               if( !strncmp( gett, "; ********", 10 ) ) break;
+//             fprintf( stderr, "gett = %s\n", gett );
+               sscanf( gett, "%c %c %s %s %d %d", &dumc, &dumc, sinseq, sinaln, &dumi, &dumi );
+               posinaln = atof( sinaln );
+               posinseq = atof( sinseq );
+//             fprintf( stderr, "posinseq = %d\n", posinseq );
+//             fprintf( stderr, "posinaln = %d\n", posinaln );
+               maptoseq2[posinaln-1] = posinseq-1;
+       }
+       if( alnlen != posinaln )
+       {
+               fprintf( stderr, "Error in foldalign?\n" );
+               exit( 1 );
+       }
+
+       pa1 = aln1;
+       pa2 = aln2;
+       for( i=0; i<alnlen; i++ )
+       {
+               pos1 = maptoseq1[i];
+               pos2 = maptoseq2[i];
+
+               if( pos1 > -1 )
+                       *pa1++ = s1[pos1];
+               else
+                       *pa1++ = '-';
+
+               if( pos2 > -1 )
+                       *pa2++ = s2[pos2];
+               else
+                       *pa2++ = '-';
+       }
+       *pa1 = 0;
+       *pa2 = 0;
+
+       *of1 = 0;
+       for( i=0; i<alnlen; i++ )
+       {
+               *of1 = maptoseq1[i];
+               if( *of1 > -1 ) break;
+       }
+       *of2 = 0;
+       for( i=0; i<alnlen; i++ )
+       {
+               *of2 = maptoseq2[i];
+               if( *of2 > -1 ) break;
+       }
+
+//     fprintf( stderr, "*of1=%d, aln1 = :%s:\n", *of1, aln1 );
+//     fprintf( stderr, "*of2=%d, aln2 = :%s:\n", *of2, aln2 );
+
+       free( maptoseq1 );
+       free( maptoseq2 );
+}
diff --git a/binaries/src/mafft/core/iteration.c b/binaries/src/mafft/core/iteration.c
new file mode 100644 (file)
index 0000000..b24875b
--- /dev/null
@@ -0,0 +1,412 @@
+ /* iteration  ( algorithm C ) */
+#include "mltaln.h"
+
+#define DEBUG 0
+
+static void Writeoptions( FILE *fp )
+{
+    if( scoremtx == 1 )
+        fprintf( fp, "Dayhoff( ... )\n" );
+    else if( scoremtx == -1 )
+        fprintf( fp, "DNA\n" );
+    else if( scoremtx == 2 )
+        fprintf( fp, "Miyata-Yasunaga\n" );
+       else
+               fprintf( fp, "JTT %dPAM\n", pamN );
+
+       if( scoremtx == 0 )
+           fprintf( fp, "Gap Penalty = %+d, %+d\n", penalty, offset );
+       else
+           fprintf( fp, "Gap Penalty = %+d\n", penalty );
+
+    fprintf( fp, "marginal score to search : best - %f\n", cut );
+    if( scmtd == 3 )
+        fprintf( fp, "score of rnd or sco\n" );
+    else if( scmtd == 4 )
+        fprintf( fp, "score = sigma( score for a pair of homologous amino acids ) / ( number of amino acids pairs )\n" );
+    else if( scmtd == 5 )
+        fprintf( fp, "score : SP\n" );
+    if( mix )
+        fprintf( fp, "?\n" );
+    else
+    { 
+        if( weight == 2 )
+            fprintf( fp, "weighted,  geta2 = %f\n", geta2 );
+        else if( weight == 3 )
+        {
+            if( scmtd == 4 )
+                fprintf( fp, "reversely weighted in function 'align', unweighted in function 'score_calc'\n" );
+            else
+                fprintf( fp, "weighted like ClustalW," );
+        }
+        else
+            fprintf( fp, "unweighted\n" );
+    }
+    if( weight && utree )
+    {
+        fprintf( fp, "using tree defined by the file hat2 with simplified UPG method\n" );
+    }
+    if( weight && !utree )
+        fprintf( fp, "using temporary tree by simplified UPG method\n" );
+    fprintf( fp, "Algorithm %c\n", alg );
+}
+
+
+
+
+char **align0( float *wm, char **aseq, char *seq, double effarr[M], int icyc, int ex )
+{
+    char **result;
+
+    if( alg == 'B' )
+    {
+               ErrorExit( "Sorry!" );
+       /*
+        if( outgap == 0 )
+        {
+            result = alignm1_o( wm, aseq, seq, scmx, effarr, icyc, ex );
+        }
+        if( outgap == 1 )
+        {
+            result = alignm1( wm, aseq, seq, scmx, effarr, icyc, ex );
+        }
+       */
+    }
+    else if( alg == 'C' )
+    {
+        result = Calignm1( wm, aseq, seq, effarr, icyc, ex );
+    }
+    return( result );
+}
+    
+
+double score_m_1_0( char **aseq, int locnjob, int s, double **eff, double effarr[M] )
+{
+    double x;
+
+    if( alg == 'B' )
+    {
+               ErrorExit( "Sorry!" );
+    }
+    if( alg == 'C' )
+    {
+        x = Cscore_m_1( aseq, locnjob, s, eff );
+    }
+    fprintf( stderr, "in score_m_1_0 %f\n", x );
+    return( x );
+}
+
+int iteration( int locnjob, char name[M][B], int nlen[M], char **aseq, char **bseq, int ***topol, double **len, double **eff ) 
+{
+    double tscore, mscore;
+    int identity;
+    static char *mseq1, **mseq2 = NULL;
+       static char **result;
+       int i, l;
+       static double effarr[M];
+       int s;
+       int sss[2];
+       char ou;
+       int alloclen; 
+       int resultlen;
+       int nlenmax0 = nlenmax;
+       FILE *prep;
+       char sai[M];
+       char sai1[M];
+       char sai2[M];
+#if 0
+       double his[2][M][MAXITERATION/locnjob+1];
+#else
+       double ***his;
+#endif
+       int cyc[2];
+       char shindou = 0;
+       float wm;
+       int returnvalue;
+
+    for( i=0; i<locnjob; i++ ) 
+    {
+               sai[i] = 1;
+        sai1[i] = 1;
+        sai2[i] = 2;
+    }
+    sai[locnjob] = sai1[locnjob] = sai2[locnjob] = 0;
+
+
+       Writeoptions( trap_g );
+
+       his = AllocateDoubleCub( 2, M, MAXITERATION/locnjob+1 );
+
+       if( mseq2 == NULL )
+       {
+       alloclen = nlenmax * 2.0;
+               AllocateTmpSeqs( &mseq2, &mseq1, alloclen );
+       }
+
+       if( !tbitr && !tbweight )
+       {
+               writePre( locnjob, name, nlen, aseq, 0 );
+
+#if 0
+               prep = fopen( "best", "w" );
+               Write( prep, locnjob, name, nlen, aseq );
+               fclose( prep );
+#endif
+       }
+       
+
+
+
+       treeconstruction( aseq, locnjob, topol, len, eff );
+       tscore = score_calc0( aseq, locnjob, eff, 0 );
+
+#if DEBUG
+    fprintf( stderr, "eff mtx in iteration\n" );
+    for( i=0; i<locnjob; i++ )
+    {
+        for( j=0; j<locnjob; j++ ) 
+        {
+            fprintf( stderr, "%5.3f ", eff[i][j] );
+        }
+        fprintf( stderr, "\n" );
+    }
+#endif
+
+    fprintf( stderr, "\n" );
+       if( disp )
+       {
+       fprintf( stderr, "aseq(initial)\n" );
+               display( aseq, locnjob );
+       }
+       fprintf( stderr, "initial score = %f     \n", tscore );
+       fprintf( stderr, "\n" );
+       for( i=0; i<locnjob; i++ ) strcpy( bseq[i], aseq[i] );
+       mscore = tscore;
+    srand( time(NULL) );
+
+       sss[1] = 0;
+       sss[0] = locnjob-1;
+/*
+       sss[0] = (int)( (float)locnjob/2.0 );
+*/
+       ou = 1;
+       cyc[0] = 0; cyc[1] = 0;
+
+    for( s=-1, l=0; l<MAXITERATION; l++ )
+    {
+        int ss;
+        double tmpscore, tmpscore1;
+
+               if( strlen( aseq[0] ) > nlenmax )
+                       nlenmax = strlen( aseq[0] );
+
+               /*
+        s = ( int )( rnd() * locnjob );
+               s++; 
+               if( s == locnjob ) s = 0;
+               ou = 0;
+               */
+               if( ou == 0 )
+               {
+                       ou = 1;
+                       s = sss[0];
+                       /*
+                       sss[0]++;
+                       if( sss[0] == locnjob )
+                       {
+                               sss[0] = 0;
+                               cyc[0]++;
+                       }
+                       */
+                       sss[0]--;
+                       if( sss[0] == -1 )
+                       {
+                               sss[0] = locnjob-1;
+                               cyc[0]++;
+                       }
+               }
+               else
+               {
+                       ou = 0;
+                       s = sss[1];
+                       sss[1]++;
+                       if( sss[1] == locnjob ) 
+                       {
+                               sss[1] = 0;
+                               cyc[1]++;
+                       }
+               }
+               fprintf( trap_g, "%d  ", weight );
+
+/*
+        for( i=0, count=0; i<strlen( aseq[s] ); i++ ) 
+        {
+            if( aseq[s][i] != '-' )
+            {
+                mseq1[count] = aseq[s][i];
+                count++;
+            }
+        }
+        mseq1[count] = 0;
+*/
+               gappick0( mseq1, aseq[s] );
+
+               if( checkC )
+                       tmpscore = score_m_1_0( aseq, locnjob, s, eff, effarr );
+
+               gappick( locnjob, s, aseq, mseq2, eff, effarr );
+
+        result = align0( &wm, mseq2, mseq1, effarr, locnjob-2, s );
+               resultlen = strlen( result[0] );
+               if( resultlen > alloclen )
+               {
+                       if( resultlen > nlenmax0*3 || resultlen > N )
+                       {
+                               fprintf(stderr, "Error in main1\n");
+                               exit( 1 );
+                       }
+                       FreeTmpSeqs( mseq2, mseq1 );
+                       alloclen = strlen( result[0] ) * 2.0;
+                       fprintf( stderr, "\n\ntrying to allocate TmpSeqs\n\n" );
+                       AllocateTmpSeqs( &mseq2, &mseq1, alloclen );
+               }
+               for( i=0; i<locnjob; i++ ) strcpy( mseq2[i], result[i] ); 
+
+               if( checkC  )
+                       fprintf( stderr, "wm in iteration == %f\n", wm );
+
+               strcpy( mseq1, mseq2[locnjob-1] );
+/*
+               Write( stdout, locnjob, name, nlen, mseq2 );
+*/
+        for( i=locnjob-2; i>=s; i-- ) strcpy( mseq2[i+1], mseq2[i] );
+        strcpy( mseq2[s], mseq1 );
+               if( checkC )
+               {
+                       tmpscore1= score_m_1_0( mseq2, locnjob, s, eff, effarr );
+                       fprintf( stderr, "pick up %d, before ALIGNM1 score_m_1_0 = %f\n", s+1, tmpscore );
+                       fprintf( stderr, "pick up %d,  after ALIGNM1 score_m_1_0 = %f\n", s+1, tmpscore1 );
+                       if( tmpscore1 < tmpscore ) 
+                       {
+                               fprintf( stderr, "\7" );
+                               fprintf( trap_g, ">>>>>>>n\n" );
+                       }
+                       if( fabs( wm - tmpscore1 ) / wm  > 0.001 ) 
+                       {
+                               fprintf( stderr, "\7sorry\n" );
+                               exit( 1 );
+                       }
+               }
+
+        identity = !strcmp( mseq2[s], aseq[s] );
+        if( s == locnjob - 1 ) ss = 0; else ss=s+1;
+
+        identity *= !strcmp( mseq2[ss], aseq[ss] );
+
+           if( !identity ) 
+               {
+                       tmpscore = score_calc0( mseq2, locnjob, eff, s );
+               }
+               else tmpscore = tscore;
+
+               if( disp )
+               {
+                       fprintf( stderr, "% 3d    % 3d / the rest   \n", l+1, s+1 );
+                       display( mseq2, locnjob );
+               }
+               fprintf( stderr, "% 3d    % 3d / the rest   \n", l+1, s+1 );
+               fprintf( stderr, "score = %f    mscore =  %f  ", tmpscore, mscore );
+
+               fprintf( trap_g, "%#4d    %#4d / the rest     ", l+1, s+1 );
+               fprintf( trap_g, "score = %f    mscore =  %f  ", tmpscore, mscore );
+
+               if( identity ) 
+               {
+                       fprintf( stderr, "( identical )\n" );
+                       fprintf( trap_g, "( identical )\n" );
+                       sai[s] = 2;
+               }
+
+        else if( tmpscore > mscore - cut )
+        {
+            fprintf( stderr, "accepted\n" );
+            fprintf( trap_g, "accepted\n" );
+            for( i=0; i<locnjob; i++ ) strcpy( aseq[i], mseq2[i] );
+                       strcpy( sai, sai1 );   /* kokoka ? */
+                       if( !tbitr && !tbweight )
+                       {
+                               writePre( locnjob, name, nlen, aseq, 0 );
+                       }
+                       strcpy( sai, sai1 );
+                       tscore = tmpscore;
+                       /*
+                       tscore = tmpscore = score_calc0( aseq, locnjob, eff, s );   * ? *
+                       */
+               if( tmpscore > mscore ) 
+                       {
+               for( i=0; i<locnjob; i++ ) strcpy( bseq[i], mseq2[i] );
+                               treeconstruction( bseq, locnjob, topol, len, eff );
+                               tscore = mscore = score_calc0( bseq, locnjob, eff, s );
+                               fprintf( trap_g, "                                    -> %f\n", mscore );
+                               strcpy( sai, sai1 );   /* kokoka ? */
+#if 0
+                               if( !tbitr && !tbweight )
+                               {       prep = fopen( "best", "w" );
+                                       Write( prep, locnjob, name, nlen, bseq );
+                                       fclose( prep );
+                               }
+#endif
+                       }
+        }
+
+               else
+               {
+                       if( tmpscore == tscore )
+                       {
+                               fprintf( stderr, "occational coincidence \n" );
+                               fprintf( trap_g, "occational coincidence\n" );
+                       }
+                       else
+                       {
+                               fprintf( stderr, "rejected\n" );
+                   fprintf( trap_g, "rejected\n" );
+                       }
+                       for( i=0; i<locnjob; i++ ) strcpy( aseq[i], bseq[i] );
+                       tscore = mscore;
+                       sai[s] = 2;
+               }
+
+/*
+               prep = fopen( "cur", "w" );
+               Write( prep, locnjob, name, nlen, mseq2 );
+               fclose( prep );
+*/
+
+               his[ou][s][cyc[ou]] = tmpscore;
+               if( !strcmp( sai, sai2 ) )
+               {
+                       returnvalue = 0;
+                       fprintf( trap_g, "converged\n" );
+                       break;
+               }
+               for( i=cyc[ou]-1; i>0; i-- ) 
+               {
+                       if( tmpscore == his[ou][s][i] ) 
+                       {
+                               shindou = 1;
+                               break;
+                       }
+               }
+               fprintf( stderr, "\n" );
+               if( shindou == 1 )
+               {
+                       returnvalue = -1;
+                       fprintf( trap_g, "oscillating\n" );
+                       break;
+               }
+       }
+       if( l == MAXITERATION ) returnvalue = -2;
+       FreeDoubleCub( his );
+       return( returnvalue );
+}
+
diff --git a/binaries/src/mafft/core/mafft-distance.c b/binaries/src/mafft/core/mafft-distance.c
new file mode 100644 (file)
index 0000000..e9e66ce
--- /dev/null
@@ -0,0 +1,401 @@
+#include "mltaln.h"
+#include "mtxutl.h"
+
+#define DEBUG 0
+#define TEST  0
+
+#define END_OF_VEC -1
+
+static int maxl;
+static int tsize;
+static char outputformat;
+static float lenfaca, lenfacb, lenfacc, lenfacd;
+#define PLENFACA 0.01
+#define PLENFACB 10000
+#define PLENFACC 10000
+#define PLENFACD 0.1
+#define DLENFACA 0.01
+#define DLENFACB 2500
+#define DLENFACC 2500
+#define DLENFACD 0.1
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+
+       inputfile = NULL;
+       outputformat = 's';
+       scoremtx = 1;
+       nblosum = 62;
+       dorp = NOTSPECIFIED;
+       alg = 'X';
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'p':
+                                       outputformat = 'p';
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+       if( inputfile == NULL )
+       {
+               argc--;
+               inputfile = *argv;
+               fprintf( stderr, "inputfile = %s\n", inputfile );
+       }
+    if( argc != 0 )
+    {
+        fprintf( stderr, "Usage: mafft-distance [-PD] [-i inputfile] inputfile > outputfile\n" );
+        exit( 1 );
+    }
+}
+
+void seq_grp_nuc( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 4 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       if( grp - grpbk < 6 )
+       {
+               fprintf( stderr, "\n\nWARNING: Too short.\nPlease also consider use mafft-ginsi, mafft-linsi or mafft-ginsi.\n\n\n" );
+//             exit( 1 );
+               *grpbk = -1;
+       }
+}
+
+void seq_grp( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 6 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       if( grp - grpbk < 6 )
+       {
+               fprintf( stderr, "\n\nWARNING: Too short.\nPlease also consider use mafft-ginsi, mafft-linsi or mafft-ginsi.\n\n\n" );
+//             exit( 1 );
+               *grpbk = -1;
+       }
+}
+
+void makecompositiontable_p( short *table, int *pointt )
+{
+       int point;
+
+       while( ( point = *pointt++ ) != END_OF_VEC )
+               table[point]++;
+}
+
+int commonsextet_p( short *table, int *pointt )
+{
+       int value = 0;
+       short tmp;
+       int point;
+       static short *memo = NULL;
+       static int *ct = NULL;
+       static int *cp;
+
+       if( *pointt == -1 )
+               return( 0 );
+
+       if( !memo )
+       {
+               memo = (short *)calloc( tsize, sizeof( short ) );
+               if( !memo ) ErrorExit( "Cannot allocate memo\n" );
+               ct = (int *)calloc( MIN( maxl, tsize)+1, sizeof( int ) );
+               if( !ct ) ErrorExit( "Cannot allocate memo\n" );
+       }
+
+       cp = ct;
+       while( ( point = *pointt++ ) != END_OF_VEC )
+       {
+               tmp = memo[point]++;
+               if( tmp < table[point] )
+                       value++;
+               if( tmp == 0 ) *cp++ = point;
+//             fprintf( stderr, "cp - ct = %d (tsize = %d)\n", cp - ct, tsize );
+       }
+       *cp = END_OF_VEC;
+       
+       cp =  ct;
+       while( *cp != END_OF_VEC )
+               memo[*cp++] = 0;
+
+       return( value );
+}
+
+void makepointtable_nuc( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       if( *n == -1 )
+       {
+               *pointt = -1;
+               return;
+       }
+
+       p = n;
+       point  = *n++ *  1024;
+       point += *n++ *   256;
+       point += *n++ *    64;
+       point += *n++ *    16;
+       point += *n++ *     4;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 1024;
+               point *= 4;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+void makepointtable( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       if( *n == -1 )
+       {
+               *pointt = -1;
+               return;
+       }
+
+       p = n;
+       point  = *n++ *  7776;
+       point += *n++ *  1296;
+       point += *n++ *   216;
+       point += *n++ *    36;
+       point += *n++ *     6;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 7776;
+               point *= 6;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+int main( int argc, char **argv )
+{
+       int i, j, initj;
+       FILE *infp;
+       char **seq;
+       int *grpseq;
+       char *tmpseq;
+       int  **pointt;
+       static char **name;
+       static int *nlen;
+       double *mtxself;
+       float score;
+       static short *table1;
+       float longer, shorter;
+       float lenfac;
+       float bunbo;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( infp );
+#endif
+       rewind( infp );
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob );
+               exit( 1 );
+       }
+
+       tmpseq = AllocateCharVec( nlenmax+1 );
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       grpseq = AllocateIntVec( nlenmax+1 );
+       pointt = AllocateIntMtx( njob, nlenmax+1 );
+       mtxself = AllocateDoubleVec( njob );
+       pamN = NOTSPECIFIED;
+       name = AllocateCharMtx( njob, B );
+       nlen = AllocateIntVec( njob );
+
+#if 0
+       FRead( infp, name, nlen, seq );
+#else
+       readData_pointer( infp, name, nlen, seq );
+#endif
+
+       fclose( infp );
+
+       constants( njob, seq );
+
+       if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
+       else              tsize = (int)pow( 6, 6 );
+
+       if( dorp == 'd' )
+       {
+               lenfaca = DLENFACA;
+               lenfacb = DLENFACB;
+               lenfacc = DLENFACC;
+               lenfacd = DLENFACD;
+       }
+       else    
+       {
+               lenfaca = PLENFACA;
+               lenfacb = PLENFACB;
+               lenfacc = PLENFACC;
+               lenfacd = PLENFACD;
+       }
+
+       maxl = 0;
+       for( i=0; i<njob; i++ ) 
+       {
+               gappick0( tmpseq, seq[i] );
+               nlen[i] = strlen( tmpseq );
+//             if( nlen[i] < 6 )
+//             {
+//                     fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
+//                     exit( 1 );
+//             }
+               if( nlen[i] > maxl ) maxl = nlen[i];
+               if( dorp == 'd' ) /* nuc */
+               {
+                       seq_grp_nuc( grpseq, tmpseq );
+                       makepointtable_nuc( pointt[i], grpseq );
+               }
+               else                 /* amino */
+               {
+                       seq_grp( grpseq, tmpseq );
+                       makepointtable( pointt[i], grpseq );
+               }
+       }
+       fprintf( stderr, "\nCalculating i-i scores ... " );
+       for( i=0; i<njob; i++ )
+       {
+               table1 = (short *)calloc( tsize, sizeof( short ) );
+               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+               makecompositiontable_p( table1, pointt[i] );
+
+               score = commonsextet_p( table1, pointt[i] );
+               mtxself[i] = score;
+               free( table1 );
+       }
+
+       fprintf( stderr, "done.\n" );
+       fprintf( stderr, "\nCalculating i-j scores ... \n" );
+       if( outputformat == 'p' ) fprintf( stdout, "%-5d", njob );
+       for( i=0; i<njob; i++ )
+       {
+               if( outputformat == 'p' ) fprintf( stdout, "\n%-9d ", i+1 );
+               table1 = (short *)calloc( tsize, sizeof( short ) );
+               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+               if( i % 10 == 0 )
+               {
+                       fprintf( stderr, "%4d / %4d\r", i+1, njob );
+               }
+               makecompositiontable_p( table1, pointt[i] );
+
+
+               if( outputformat == 'p' ) initj = 0;
+               else                      initj = i+1;
+               for( j=initj; j<njob; j++ ) 
+               {
+                       if( nlen[i] > nlen[j] )
+                       {
+                               longer=(float)nlen[i];
+                               shorter=(float)nlen[j];
+                       }
+                       else
+                       {
+                               longer=(float)nlen[j];
+                               shorter=(float)nlen[i];
+                       }
+//                     lenfac = 3.0 / ( LENFACA + LENFACB / ( longer + LENFACC ) + shorter / longer * LENFACD );
+                       lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca );
+//                     lenfac = 1.0;
+//                     fprintf( stderr, "lenfac = %f (%.0f,%.0f)\n", lenfac, longer, shorter );
+                       score = commonsextet_p( table1, pointt[j] );
+                       bunbo = MIN( mtxself[i], mtxself[j] );
+                       if( outputformat == 'p' )
+                       {
+                               if( bunbo == 0.0 )
+                                       fprintf( stdout, " %8.6f", 1.0 );
+                               else
+                                       fprintf( stdout, " %8.6f", ( 1.0 - score / bunbo ) * lenfac );
+                               if( j % 7 == 6 ) fprintf( stdout, "\n" );
+                       }
+                       else
+                       {
+                               if( bunbo == 0.0 )
+                                       fprintf( stdout, "%d-%d d=%4.2f l=%d,%d\n", i+1, j+1, 1.0, nlen[i], nlen[j] );
+                               else
+                                       fprintf( stdout, "%d-%d d=%4.2f l=%d,%d\n", i+1, j+1, ( 1.0 - score / bunbo ) * lenfac, nlen[i], nlen[j] );
+                       }
+//                     fprintf( stderr, "##### mtx = %f, mtx[i][0]=%f, mtx[j][0]=%f, bunbo=%f\n", mtx[i][j-i], mtx[i][0], mtx[j][0], bunbo );
+//          score = (double)commonsextet_p( table1, pointt[j] );
+//                     fprintf( stdout, "%d-%d d=%4.2f l=%d,%d\n", i+1, j+1, ( 1.0 - score / MIN( mtxself[i], mtxself[j] ) ) * 3, nlen[i], nlen[j] );
+
+
+               } 
+               free( table1 );
+       }
+               
+       fprintf( stderr, "\n" );
+       if( outputformat == 'p' ) fprintf( stdout, "\n" );
+       SHOWVERSION;
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/mafft-homologs.1 b/binaries/src/mafft/core/mafft-homologs.1
new file mode 100644 (file)
index 0000000..a9c9682
--- /dev/null
@@ -0,0 +1,131 @@
+.\"     Title: MAFFT-HOMOLOGS
+.\"    Author: Kazutaka Katoh <katoh_at_bioreg.kyushu-u.ac.jp.>
+.\" Generator: DocBook XSL Stylesheets v1.72.0 <http://docbook.sf.net/>
+.\"      Date: 2007-08-14
+.\"    Manual: Mafft Manual
+.\"    Source: mafft-homologs 2.1
+.\"
+.TH "MAFFT\-HOMOLOGS" "1" "2007\-06\-09" "mafft\-homologs 2.1" "Mafft Manual"
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.SH "NAME"
+.RS 0
+mafft\-homologs \- aligns sequences together with homologues automatically collected from SwissProt via NCBI BLAST
+.RE
+.SH "SYNOPSIS"
+.RS 0
+\fBmafft\-homologs\fR [\fBoptions\fR] \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.SH "DESCRIPTION"
+.RS 0
+The accuracy of an alignment of a few distantly related sequences is considerably improved when being aligned together with their close homologs. The reason for the improvement is probably the same as that for PSI\-BLAST. That is, the positions of highly conserved residues, those with many gaps and other additional information is brought by close homologs. According to Katoh et al. (2005), the improvement by adding close homologs is 10% or so, which is comparable to the improvement by incorporating structural information of a pair of sequences. Mafft\-homologs in a mafft server works like this:
+.sp
+.RS 4
+\h'-04' 1.\h'+02'Collect a number (50 by default) of close homologs (E=1e\-10 by default) of the input sequences.
+.RE
+.sp
+.RS 4
+\h'-04' 2.\h'+02'Align the input sequences and homologs all together using the L\-INS\-i strategy.
+.RE
+.sp
+.RS 4
+\h'-04' 3.\h'+02'Remove the homologs.
+.RE
+.RE
+.SH "OPTIONS"
+.RS 0
+.PP
+\fB\-a\fR \fI\fIn\fR\fR
+.RS 4
+The number of collected sequences (default: 50).
+.RE
+.PP
+\fB\-e\fR \fI\fIn\fR\fR
+.RS 4
+Threshold value (default: 1e\-10).
+.RE
+.PP
+\fB\-o\fR \fI\fIxxx\fR\fR
+.RS 4
+Options for mafft (default: " \-\-op 1.53 \-\-ep 0.123 \-\-maxiterate 1000 --localpair --reorder").
+.RE
+.PP
+\fB\-l\fR
+.RS 4
+Locally carries out BLAST searches instead of NCBI BLAST (requires locally installed BLAST and a database).
+.RE
+.PP
+\fB\-f\fR
+.RS 4
+Outputs collected homologues also (default: off).
+.RE
+.PP
+\fB\-w\fR
+.RS 4
+entire sequences are subjected to BLAST search (default: well\-aligned region only)
+.RE
+.RE
+.SH "REQUIREMENTS"
+.RS 0
+.PP
+MAFFT version > 5.58.
+.PP
+Either of
+.RS 4
+.PP
+lynx (when remote BLAST server is used)
+.PP
+BLAST and a protein sequence database (when local BLAST is used)
+.RE
+.RE
+.SH "REFERENCES"
+.RS 0
+.PP
+Katoh, Kuma, Toh and Miyata (Nucleic Acids Res. 33:511\-518, 2005) MAFFT version 5: improvement in accuracy of multiple sequence alignment.
+.RE
+.SH "SEE ALSO"
+.RS 0
+.PP
+\fBmafft\fR(1)
+.RE
+.SH "AUTHORS"
+.RS 0
+.PP
+\fBKazutaka Katoh\fR <\&katoh_at_bioreg.kyushu\-u.ac.jp.\&>
+.sp -1n
+.IP "" 4
+Wrote Mafft.
+.PP
+\fBCharles Plessy\fR <\&charles\-debian\-nospam@plessy.org\&>
+.sp -1n
+.IP "" 4
+Wrote this manpage in DocBook XML for the Debian distribution, using Mafft's homepage as a template.
+.RE
+.SH "COPYRIGHT"
+.RS 0
+Copyright \(co 2002\-2007 Kazutaka Katoh (mafft)
+.br
+Copyright \(co 2007 Charles Plessy (this manpage)
+.br
+.PP
+Mafft and its manpage are offered under the following conditions:
+.PP
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+.sp
+.RS 4
+\h'-04' 1.\h'+02'Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+.RE
+.sp
+.RS 4
+\h'-04' 2.\h'+02'Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+.RE
+.sp
+.RS 4
+\h'-04' 3.\h'+02'The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
+.RE
+.PP
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.br
+.RE
diff --git a/binaries/src/mafft/core/mafft-homologs.tmpl b/binaries/src/mafft/core/mafft-homologs.tmpl
new file mode 100644 (file)
index 0000000..c06743c
--- /dev/null
@@ -0,0 +1,374 @@
+#!/usr/bin/env ruby
+
+localdb = "sp"        
+# database name from which homologues are collected 
+# by locally installed blast. Leave this if you do 
+# not use the '-l' option.
+
+mafftpath = "_BINDIR/mafft"   
+# path of mafft. "/usr/local/bin/mafft"
+# if mafft is in your command path, "mafft" is ok.
+
+blastpath = "blastall"   
+# path of blastall. 
+# if blastall is in your command path, "blastall" is ok.
+
+# mafft-homologs.rb  v. 2.1 aligns sequences together with homologues 
+# automatically collected from SwissProt via NCBI BLAST.
+#
+# mafft > 5.58 is required
+#
+# Usage:
+#   mafft-homologs.rb [options] input > output
+# Options:
+#   -a #      the number of collected sequences (default: 50)
+#   -e #      threshold value (default: 1e-10)
+#   -o "xxx"  options for mafft 
+#             (default: " --op 1.53 --ep 0.123 --maxiterate 1000")
+#   -l        locally carries out blast searches instead of NCBI blast
+#             (requires locally installed blast and a database)
+#   -f        outputs collected homologues also (default: off)
+#   -w        entire sequences are subjected to BLAST search 
+#             (default: well-aligned region only)
+
+require 'getopts'
+require 'tempfile'
+
+# mktemp
+GC.disable
+temp_vf = Tempfile.new("_vf").path
+temp_if = Tempfile.new("_if").path
+temp_pf = Tempfile.new("_pf").path
+temp_af = Tempfile.new("_af").path
+temp_qf = Tempfile.new("_qf").path
+temp_bf = Tempfile.new("_bf").path
+temp_rid = Tempfile.new("_rid").path
+temp_res = Tempfile.new("_res").path
+
+
+system( mafftpath + " --help > #{temp_vf} 2>&1" )
+pfp = File.open( "#{temp_vf}", 'r' )
+while pfp.gets
+       break if $_ =~ /MAFFT v/
+end
+pfp.close
+if( $_ ) then
+       mafftversion = sub( /^\D*/, "" ).split(" ").slice(0).strip.to_s
+else
+       mafftversion = "0"
+end
+if( mafftversion < "5.58" ) then
+       puts ""
+       puts "======================================================"
+       puts "Install new mafft (v. >= 5.58)"
+       puts "======================================================"
+       puts ""
+       exit
+end
+
+srand ( 0 )
+
+def readfasta( fp, name, seq )
+       nseq = 0
+       tmpseq = ""
+       while fp.gets
+               if $_ =~ /^>/ then
+                       name.push( $_.sub(/>/,"").strip )
+                       seq.push( tmpseq ) if nseq > 0
+                       nseq += 1
+                       tmpseq = ""
+               else
+                       tmpseq += $_.strip
+               end
+       end
+       seq.push( tmpseq )
+       return nseq
+end
+
+nadd = 50
+eval = 1e-10
+local = 0
+fullout = 0
+entiresearch = 0
+corewin = 50
+corethr = 0.3
+mafftopt = " --op 1.53 --ep 0.123 --localpair --maxiterate 1000 --reorder "
+if getopts( "s", "f", "w", "l", "h", "e:", "a:", "o:", "c:", "d:" ) == nil ||  ARGV.length == 0 || $OPT_h then
+       puts "Usage: #{$0} [-h -l -e# -a# -o\"[options for mafft]\"] input_file"
+       exit
+end
+
+if $OPT_c then
+       corewin = $OPT_c.to_i
+end
+if $OPT_d then
+       corethr = $OPT_d.to_f
+end
+if $OPT_w
+       entiresearch = 1
+end
+if $OPT_f
+       fullout = 1
+end
+if $OPT_s
+       fullout = 0
+end
+if $OPT_l
+       local = 1
+end
+if $OPT_e then
+       eval = $OPT_e.to_f
+end
+if $OPT_a then
+       nadd = $OPT_a.to_i
+end
+if $OPT_o then
+       mafftopt += " " + $OPT_o + " "
+end
+
+system "cat " + ARGV.to_s + " > #{temp_if}"
+ar = mafftopt.split(" ")
+nar = ar.length
+for i in 0..(nar-1)
+       if ar[i] == "--seed" then
+               system "cat #{ar[i+1]} >> #{temp_if}"
+       end
+end
+
+nseq = 0
+ifp = File.open( "#{temp_if}", 'r' )
+       while ifp.gets
+               nseq += 1 if $_ =~ /^>/
+       end
+ifp.close
+
+if nseq >= 100 then
+       STDERR.puts "The number of input sequences must be <100."
+       exit
+elsif nseq == 1 then
+       system( "cp #{temp_if}"  + " #{temp_pf}" )
+else
+       STDERR.puts "Performing preliminary alignment .. "
+       if entiresearch == 1 then
+#              system( mafftpath + " --maxiterate 1000 --localpair #{temp_if} > #{temp_pf}" )
+               system( mafftpath + " --maxiterate 0 --retree 2 #{temp_if} > #{temp_pf}" )
+       else
+               system( mafftpath + " --maxiterate 1000 --localpair --core --coreext --corethr #{corethr.to_s} --corewin #{corewin.to_s} #{temp_if} > #{temp_pf}" )
+       end
+end
+
+pfp = File.open( "#{temp_pf}", 'r' )
+inname = []
+inseq = []
+slen = []
+act = []
+nin = 0
+nin = readfasta( pfp, inname, inseq )
+for i in 0..(nin-1)
+       slen.push( inseq[i].gsub(/-/,"").length )
+       act.push( 1 )
+end
+pfp.close
+
+pfp = File.open( "#{temp_if}", 'r' )
+orname = []
+orseq = []
+nin = 0
+nin = readfasta( pfp, orname, orseq )
+pfp.close
+
+allen = inseq[0].length
+for i in 0..(nin-2)
+       for j in (i+1)..(nin-1)
+               next if act[i] == 0
+               next if act[j] == 0
+               pid = 0.0
+               total = 0
+               for a in 0..(allen-1)
+                       next if inseq[i][a,1] == "-" || inseq[j][a,1] == "-"
+                       total += 1
+                       pid += 1.0 if inseq[i][a,1] == inseq[j][a,1]
+               end
+               pid /= total
+#              puts "#{i.to_s}, #{j.to_s}, #{pid.to_s}"
+               if pid > 0.5 then
+                       if slen[i] < slen[j]
+                               act[i] = 0 
+                       else
+                               act[j] = 0 
+                       end
+               end
+       end
+end
+#p act
+
+
+afp = File.open( "#{temp_af}", 'w' )
+
+STDERR.puts "Searching .. \n"
+ids = []
+add = []
+sco = []
+for i in 0..(nin-1)
+       inseq[i].gsub!(/-/,"")
+       afp.puts ">" + orname[i]
+       afp.puts orseq[i]
+
+#      afp.puts ">" + inname[i]
+#      afp.puts inseq[i]
+
+       STDERR.puts "Query (#{i+1}/#{nin})\n" + inname[i]
+       if act[i] == 0 then
+               STDERR.puts "Skip.\n\n"
+               next 
+       end
+
+       if local == 0 then
+               command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?QUERY=" + inseq[i] + "&DATABASE=swissprot&HITLIST_SIZE=" + nadd.to_s + "&FILTER=L&EXPECT='" + eval.to_s + "'&FORMAT_TYPE=TEXT&PROGRAM=blastp&SERVICE=plain&NCBI_GI=on&PAGE=Proteins&CMD=Put' > #{temp_rid}"
+               system command
+       
+               ridp = File.open( "#{temp_rid}", 'r' )
+               while ridp.gets
+                       break if $_ =~ / RID = (.*)/
+               end
+               ridp.close
+               rid = $1.strip
+               STDERR.puts "Submitted to NCBI. rid = " + rid
+       
+               STDERR.printf "Waiting "
+               while 1 
+                       STDERR.printf "."
+                       sleep 10
+                       command = "lynx -source 'http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?RID=" + rid + "&DESCRIPTIONS=500&ALIGNMENTS=" + nadd.to_s + "&ALIGNMENT_TYPE=Pairwise&OVERVIEW=no&CMD=Get&FORMAT_TYPE=XML' > #{temp_res}"
+                       system command
+                       resp = File.open( "#{temp_res}", 'r' )
+#                      resp.gets
+#                      if $_ =~ /WAITING/ then
+#                              resp.close
+#                              next
+#                      end
+                       while( resp.gets )
+                               break if $_ =~ /QBlastInfoBegin/
+                       end
+                       resp.gets
+                       if $_ =~ /WAITING/ then
+                               resp.close
+                               next
+                       else
+                               resp.close
+                               break
+                       end
+               end
+       else
+#              puts "Not supported"
+#              exit
+               qfp = File.open( "#{temp_qf}", 'w' )
+                       qfp.puts "> "
+                       qfp.puts inseq[i]
+               qfp.close
+               command = blastpath + "  -p blastp  -e #{eval} -b 1000 -m 7 -i #{temp_qf} -d #{localdb} > #{temp_res}"
+               system command
+               resp = File.open( "#{temp_res}", 'r' )
+       end
+       STDERR.puts " Done.\n\n"
+
+       resp = File.open( "#{temp_res}", 'r' )
+       while 1
+               while resp.gets
+                       break if $_ =~ /<Hit_id>(.*)<\/Hit_id>/ || $_ =~ /(<Iteration_stat>)/
+               end
+               id = $1
+               break if $_ =~ /<Iteration_stat>/
+#              p id
+               while resp.gets
+                       break if $_ =~ /<Hsp_bit-score>(.*)<\/Hsp_bit-score>/
+               end
+               score = $1.to_f
+#              p score
+
+               known = ids.index( id )
+               if known != nil then
+                       if sco[known] >= score then
+                               next
+                       else
+                               ids.delete_at( known )
+                               add.delete_at( known )
+                               sco.delete_at( known )
+                       end
+               end
+               while resp.gets
+                       break if $_ =~ /<Hsp_hseq>(.*)<\/Hsp_hseq>/
+               end
+#              break if $1 == nil
+               target = $1.sub( /-/, "" ).sub( /U/, "X" )
+#              p target
+#              STDERR.puts "adding 1 seq"
+               ids.push( id )
+               sco.push( score )
+               add.push( target )
+       end
+       resp.close
+end
+
+n = ids.length
+
+outnum = 0
+while n > 0 && outnum < nadd
+       m = rand( n )
+       afp.puts ">_addedbymaffte_" + ids[m]
+       afp.puts add[m]
+       ids.delete_at( m )
+       add.delete_at( m )
+       n -= 1
+       outnum += 1
+end
+afp.close
+
+STDERR.puts "Performing alignment .. "
+system( mafftpath + mafftopt + " #{temp_af} > #{temp_bf}" )
+STDERR.puts "done."
+
+bfp = File.open( "#{temp_bf}", 'r' )
+outseq = []
+outnam = []
+readfasta( bfp, outnam, outseq )
+bfp.close
+
+outseq2 = []
+outnam2 = []
+
+len = outseq.length
+for i in 0..(len-1)
+#      p outnam[i]
+       if fullout == 0 && outnam[i] =~ /_addedbymaffte_/ then
+               next
+       end
+       outseq2.push( outseq[i] )
+       outnam2.push( outnam[i].sub( /_addedbymaffte_/, "_ho_" ) )
+end
+
+nout = outseq2.length
+len = outseq[0].length
+p = len
+while p>0
+       p -= 1
+    allgap = 1
+    for j in 0..(nout-1)
+               if outseq2[j][p,1] != "-" then
+                       allgap = 0
+                       break
+               end
+    end
+    if allgap == 1 then
+        for j in 0..(nout-1)
+            outseq2[j][p,1] = ""
+        end
+    end
+end
+for i in 0..(nout-1)
+       puts ">" + outnam2[i]
+       puts outseq2[i].gsub( /.{1,60}/, "\\0\n" )
+end
+
+
+system( "rm -rf #{temp_if} #{temp_vf} #{temp_af} #{temp_bf} #{temp_pf} #{temp_qf} #{temp_res} #{temp_rid}" )
diff --git a/binaries/src/mafft/core/mafft-profile.c b/binaries/src/mafft/core/mafft-profile.c
new file mode 100644 (file)
index 0000000..1eb479c
--- /dev/null
@@ -0,0 +1,504 @@
+#include "mltaln.h"
+
+#define DEBUG 0 
+
+#if DEBUG
+#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+double getrusage_sec()
+{
+    struct rusage t;
+    struct timeval tv;
+    getrusage(RUSAGE_SELF, &t);
+    tv = t.ru_utime;
+    return tv.tv_sec + (double)tv.tv_usec*1e-6;
+}
+#endif
+
+
+int intcmp( int *str1, int *str2 )
+{
+       while( *str1 != -1 && *str2 != -1 )
+               if( *str1++ != *str2++ ) return( 1 );
+       if( *str1 != *str2 ) return( 1 );
+       return( 0 );
+}
+
+char **arguments( int argc, char *argv[] )
+{
+    int c = 0;
+       
+       fmodel = 0;
+       nblosum = 62;
+       calledByXced = 0;
+       devide = 0;
+       fftscore = 1;
+       use_fft = 1;
+       alg = 'A';
+    weight = 0;
+    utree = 1;
+       tbutree = 0;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 0;
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+    scoremtx = 1;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = 0; // chokusetsu yobareru kara
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       TMorJTT = JTT;
+       treemethod = 'x';
+
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'N':
+                                       use_fft = 0;
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'Q':
+                                       alg = 'Q';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+                               case 'O':
+                                       outgap = 0;
+                                       break;
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+                               case 'u':
+                                       tbrweight = 0;
+                                       break;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                case 'f':
+                    ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                    fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                    --argc;
+                    goto nextoption;
+                case 'g':
+                    ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                    fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                    --argc;
+                    goto nextoption;
+                case 'h':
+                    poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                    fprintf( stderr, "poffset = %d\n", poffset );
+                    --argc;
+                    goto nextoption;
+                case 'k':
+                    kimuraR = atoi( *++argv );
+                    fprintf( stderr, "kappa = %d\n", kimuraR );
+                    --argc;
+                    goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "tm %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               default:
+                                       fprintf( stderr, "illegal option %c\n", c );
+                                       argc = 0;
+                                       break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 2 ) 
+    {
+        fprintf( stderr, "options: Check source file ! %c ?\n", c );
+        exit( 1 );
+    }
+       fprintf( stderr, "tbitr = %d, tbrweight = %d, tbweight = %d\n", tbitr, tbrweight, tbweight );
+//     readOtherOptions( &ppid, &fftThreshold, &fftWinSize );
+       return( argv ); 
+
+}
+
+void GroupAlign( int nseq1, int nseq2, char **name, int *nlen, char **seq, char **aseq, char **mseq1, char **mseq2, int ***topol, double **len, double *eff, int alloclen )
+{
+       int i;
+       int clus1, clus2;
+       int s1, s2;
+       float pscore;
+       static char **name1, **name2;
+       double *effarr = eff;
+       double *effarr1 = NULL;
+       double *effarr2 = NULL;
+       static char *indication1, *indication2;
+       float dumfl = 0.0;
+       int intdum;
+#if DEBUG
+       double time1, time2;
+#endif
+
+
+//     fprintf( stderr, "in GroupAlign fftWinSize   = %d\n", fftWinSize );
+//     fprintf( stderr, "in GroupAlign fftThreshold = %d\n", fftThreshold );
+
+       if( effarr1 == NULL ) 
+       {
+               name1 = AllocateCharMtx( nseq1, B );
+               name2 = AllocateCharMtx( nseq2, B );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+#if 0
+#else
+#endif
+       }
+
+       for( i=0; i<njob; i++ ) strcpy( aseq[i], seq[i] );
+
+
+               
+       s1 = 0;
+       s2 = nseq1;
+//     fprintf( stdout, "nseq1 = %d\n", nseq1 );
+
+
+
+       clus1 = conjuctionforgaln( 0, nseq1, aseq, mseq1, effarr1, effarr, name, name1, indication1 );
+       clus2 = conjuctionforgaln( nseq1, njob, aseq, mseq2, effarr2, effarr, name, name2, indication2 );
+/*
+       fprintf( stderr, "before align all\n" );
+       display( aseq, njob );
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "before align 1 %s \n", indication1 );
+       display( mseq1, clus1 );
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "before align 2 %s \n", indication2 );
+       display( mseq2, clus2 );
+       fprintf( stderr, "\n" );
+*/
+
+       if( alg == 'Q' )
+               fprintf( stderr, "before realignment, score = %f\n", naiveQpairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
+       else if( alg == 'H' )
+               fprintf( stderr, "before realignment, score = %f\n", naivepairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
+
+       commongappick( nseq1, mseq1 );
+       commongappick( nseq2, mseq2 );
+
+
+#if DEBUG
+       time1 = getrusage_sec();
+       fprintf( stderr, "entering Falign\n" );
+#endif
+       if( use_fft )
+       {
+               if( alg == 'M' )
+                       pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum );
+               else
+                       pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
+       }
+       else
+       {
+               if( alg == 'M' )
+                       pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+               else if( alg == 'H' )
+                       pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+               else if( alg == 'Q' )
+                       pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+               else
+                       pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+       }
+#if DEBUG
+               time2 = getrusage_sec();
+               fprintf( stdout, "### %d - %d,  %f\n", clus1, clus2, time2-time1 );
+               fflush( stdout );
+#endif
+
+       if( alg == 'H' )
+               fprintf( stderr, "before realignment, score = %f\n", naivepairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
+       else if( alg == 'Q' )
+               fprintf( stderr, "after realignment, score = %f\n", naiveQpairscore( nseq1, nseq2, mseq1, mseq2, effarr1, effarr2, penalty ) );
+
+       
+/*
+       fprintf( stderr, "after align 1 %s \n", indication1 );
+       display( mseq1, clus1 );
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "after align 2 %s \n", indication2 );
+       display( mseq2, clus2 );
+       fprintf( stderr, "\n" );
+*/
+
+       fprintf( stderr, "group-to-group %s /%s     %f\n", indication1, indication2, pscore );
+       if( disp ) display( aseq, njob );
+       fprintf( stderr, "\n" );
+
+/*
+       trap = fopen( "pre", "r+" );
+       if( !trap ) ErrorExit( 1 );
+       WriteGapFill( trap, njob, name, nlen, aseq );
+       fclose( trap );
+       fprintf( stdout, "nseq1 = %d\n", nseq1 );
+*/
+}
+
+static void WriteOptions( FILE *fp )
+{
+       fprintf( fp, "tree-base method\n" );
+       if( tbweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbweight == 3 ) fprintf( fp, "reversely weighted\n" );
+       if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+       else if( scoremtx ==  1 ) fprintf( fp, "Dayhoff( machigai ga aru )\n" );
+       else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       else if( scoremtx == -1 ) fprintf( fp, "DNA\n" );
+
+       if( scoremtx )
+               fprintf( fp, "Gap Penalty = %d, %d\n", penalty, offset );
+       else
+               fprintf( fp, "Gap Penalty = %d\n", penalty );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       char **argv2;
+       static int  *nlen;      
+       static char **name, **seq;
+       static char **seq1, **seq2;
+       static char **mseq1, **mseq2;
+       static char **aseq;
+       static char **bseq;
+       static double **pscore;
+       static double *eff;
+       int i, j, len1, len2;
+       static int ***topol;
+       static double **len;
+       FILE *gp1, *gp2;
+       char c;
+       int nlenmax1, nlenmax2, nseq1, nseq2;
+       int alloclen;
+
+       argv2 = arguments( argc, argv );
+
+       fprintf( stderr, "####### in galn\n" );
+
+       initFiles();
+
+       fprintf( stderr, "file1 = %s\n", argv2[0] );
+       fprintf( stderr, "file2 = %s\n", argv2[1] );
+
+       gp1 = fopen( argv2[0], "r" ); if( !gp1 ) ErrorExit( "cannot open file1" );
+       gp2 = fopen( argv2[1], "r" ); if( !gp2 ) ErrorExit( "cannot open file2" );
+
+#if 0
+       PreRead( gp1, &nseq1, &nlenmax1 );
+       PreRead( gp2, &nseq2, &nlenmax2 );
+#else
+    getnumlen( gp1 );
+       nseq1 = njob; nlenmax1 = nlenmax;
+    getnumlen( gp2 );
+       nseq2 = njob; nlenmax2 = nlenmax;
+#endif
+
+       njob = nseq1 + nseq2;
+       nlenmax = MAX( nlenmax1, nlenmax2 );
+
+       rewind( gp1 );
+       rewind( gp2 );
+
+
+       name = AllocateCharMtx( njob, B );
+       nlen = AllocateIntVec( njob );
+       seq1 = AllocateCharMtx( nseq1, nlenmax*3 );
+       seq2 = AllocateCharMtx( nseq2, nlenmax*3 );
+       seq  = AllocateCharMtx( njob, 1 );
+       aseq = AllocateCharMtx( njob, nlenmax*3 );
+       bseq = AllocateCharMtx( njob, nlenmax*3 );
+       mseq1 = AllocateCharMtx( njob, 1 );
+       mseq2 = AllocateCharMtx( njob, 1 );
+       alloclen = nlenmax * 3;
+
+       topol = AllocateIntCub( njob, 2, njob );
+       len = AllocateDoubleMtx( njob, 2 );
+       pscore = AllocateDoubleMtx( njob, njob );
+       eff = AllocateDoubleVec( njob );
+
+#if 0
+    njob=nseq2; FRead( gp2, name+nseq1, nlen+nseq1, seq2 );
+       njob=nseq1; FRead( gp1, name, nlen, seq1 );
+#else
+    njob=nseq2; readDataforgaln( gp2, name+nseq1, nlen+nseq1, seq2 );
+       njob=nseq1; readDataforgaln( gp1, name, nlen, seq1 );
+#endif
+       njob = nseq1 + nseq2;
+
+
+#if 0  // CHUUI
+       commongappick( nseq1, seq1 );
+       commongappick( nseq2, seq2 );
+#endif
+
+       for( i=0; i<nseq1; i++ ) seq[i] = seq1[i];
+       for( i=nseq1; i<njob; i++ ) seq[i] = seq2[i-nseq1];
+/*
+       Write( stdout, njob, name, nlen, seq );
+*/
+
+    constants( njob, seq );
+
+    WriteOptions( trap_g );
+
+    c = seqcheck( seq );
+    if( c )
+    {
+        fprintf( stderr, "Illeagal character %c\n", c );
+        exit( 1 );
+    }
+    for( i=1; i<nseq1; i++ ) 
+    {
+        if( nlen[i] != nlen[0] ) 
+            ErrorExit( "group1 is not aligned." );
+    }
+    for( i=nseq1+1;  i<njob; i++ ) 
+    {
+        if( nlen[i] != nlen[nseq1] ) 
+            ErrorExit( "group2 is not aligned." );
+    }
+    if( tbutree == 0 )
+       {
+               for( i=0; i<nseq1; i++ ) 
+               {
+                       for( j=i+1; j<nseq1; j++ )
+                       {
+                               pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+//                             fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
+                       }
+                       for( j=nseq1; j<njob; j++ )
+                       {
+                               pscore[i][j] = 3.0;
+//                             fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
+                       }
+               }
+               for( i=nseq1; i<njob-1; i++ ) 
+               {
+                       for( j=i+1; j<njob; j++ )
+                       {
+                               pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+//                             fprintf( stderr, "%d-%d, %5.1f \n", i, j, pscore[i][j] );
+                       }
+               }
+//             fprintf( stderr, "\n" );
+
+
+    }
+       else
+       {
+               fprintf( stderr, "Not supported\n" );
+               exit( 1 );
+#if 0
+               prep = fopen( "hat2", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat2." );
+               readhat2( prep, njob, name, pscore );
+               fclose( prep );
+#endif
+       }
+       fprintf( stderr, "Constructing dendrogram ... " );
+       if( treemethod == 'x' )
+               veryfastsupg( njob, pscore, topol, len );
+       else
+               ErrorExit( "Incorrect tree\n" );
+       fprintf( stderr, "done.\n" );
+
+       if( tbrweight )
+       {
+               weight = 3;
+               counteff_simple( njob, topol, len, eff );
+//             for( i=0; i<njob; i++ ) fprintf( stderr, "eff[%d] = %f\n", i, eff[i] );
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) eff[i] = 1.0;
+       }
+
+       len1 = strlen( seq[0] );
+       len2 = strlen( seq[nseq1] );
+       if( len1 > 30000 || len2 > 30000 )
+       {       
+               fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 );
+               alg = 'M';
+       }       
+        
+
+
+
+       GroupAlign( nseq1, nseq2, name, nlen, seq, aseq, mseq1, mseq2, topol, len, eff, alloclen );
+
+#if 0
+       writePre( njob, name, nlen, aseq, 1 );
+#else
+       writeDataforgaln( stdout, njob, name, nlen, aseq );
+#endif
+
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/mafft.1 b/binaries/src/mafft/core/mafft.1
new file mode 100644 (file)
index 0000000..8636334
--- /dev/null
@@ -0,0 +1,479 @@
+.\"     Title: MAFFT
+.\"    Author: Kazutaka Katoh <kazutaka.katoh@aist.go.jp>
+.\" Generator: DocBook XSL Stylesheets v1.72.0 <http://docbook.sf.net/>
+.\"      Date: 2007-08-14
+.\"    Manual: Mafft Manual
+.\"    Source: mafft 6.240
+.\"
+.TH "MAFFT" "1" "2007\-06\-09" "mafft 6.240" "Mafft Manual"
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.SH "THIS MANUAL IS FOR V6.2XX (2007)"
+Recent versions (v6.8xx; 2010 Nov.) have more features than those described below.
+See also the tips page at 
+http://mafft.cbrc.jp/alignment/software/tips0.html
+.SH "NAME"
+.RS 0
+.sp
+mafft \- Multiple alignment program for amino acid or nucleotide sequences
+.RE
+.SH "SYNOPSIS"
+.RS 0
+.HP 6
+\fBmafft\fR [\fBoptions\fR] \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBlinsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBginsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBeinsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 7
+\fBfftnsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBfftns\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 5
+\fBnwns\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBnwnsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 14
+\fBmafft\-profile\fR \fIgroup1\fR \fIgroup2\fR [>\ \fIoutput\fR]
+.HP
+.sp
+\fIinput\fR, \fIgroup1\fR and \fIgroup2\fR must be in FASTA format.
+.RE
+.SH "DESCRIPTION"
+.RS 0
+\fBMAFFT\fR is a multiple sequence alignment program for unix\-like operating systems. It offers a range of multiple alignment methods.
+.SS "Accuracy\-oriented methods:"
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'L\-INS\-i (probably most accurate; recommended for <200 sequences; iterative refinement method incorporating local pairwise alignment information):
+.HP 6
+\fBmafft\fR \fB\-\-localpair\fR \fB\-\-maxiterate\fR\ \fI1000\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBlinsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'G\-INS\-i (suitable for sequences of similar lengths; recommended for <200 sequences; iterative refinement method incorporating global pairwise alignment information):
+.HP 6
+\fBmafft\fR \fB\-\-globalpair\fR \fB\-\-maxiterate\fR\ \fI1000\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBginsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'E\-INS\-i (suitable for sequences containing large unalignable regions; recommended for <200 sequences):
+.HP 6
+\fBmafft\fR \fB\-\-ep\fR\ \fI0\fR \fB\-\-genafpair\fR \fB\-\-maxiterate\fR\ \fI1000\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBeinsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.br
+
+For E\-INS\-i, the
+\fB\-\-ep\fR
+\fI0\fR
+option is recommended to allow large gaps.
+.RE
+.SS "Speed\-oriented methods:"
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'FFT\-NS\-i (iterative refinement method; two cycles only):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI2\fR \fB\-\-maxiterate\fR\ \fI2\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 7
+\fBfftnsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'FFT\-NS\-i (iterative refinement method; max. 1000 iterations):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI2\fR \fB\-\-maxiterate\fR\ \fI1000\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'FFT\-NS\-2 (fast; progressive method):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI2\fR \fB\-\-maxiterate\fR\ \fI0\fR \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBfftns\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'FFT\-NS\-1 (very fast; recommended for >2000 sequences; progressive method with a rough guide tree):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI1\fR \fB\-\-maxiterate\fR\ \fI0\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'NW\-NS\-i (iterative refinement method without FFT approximation; two cycles only):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI2\fR \fB\-\-maxiterate\fR\ \fI2\fR \fB\-\-nofft\fR\ \fIinput\fR [>\ \fIoutput\fR]
+.HP 7
+\fBnwnsi\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'NW\-NS\-2 (fast; progressive method without the FFT approximation):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI2\fR \fB\-\-maxiterate\fR\ \fI0\fR \fB\-\-nofft\fR\ \fIinput\fR [>\ \fIoutput\fR]
+.HP 6
+\fBnwns\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'NW\-NS\-PartTree\-1 (recommended for ~10,000 to ~50,000 sequences; progressive method with the PartTree algorithm):
+.HP 6
+\fBmafft\fR \fB\-\-retree\fR\ \fI1\fR \fB\-\-maxiterate\fR\ \fI0\fR \fB\-\-nofft\fR\ \fB\-\-parttree\fR \fIinput\fR [>\ \fIoutput\fR]
+.RE
+.SS "Group\-to\-group alignments"
+.HP 6
+.RS 4
+\fBmafft\-profile\fR \fIgroup1\fR \fIgroup2\fR [>\ \fIoutput\fR]
+.sp
+or:
+.sp
+\fBmafft\fR \fB\-\-maxiterate\fR\ \fI1000\fR \fB\-\-seed\fR\ \fIgroup1\fR \fB\-\-seed\fR\ \fIgroup2\fR /dev/null [>\ \fIoutput\fR]
+.RE
+.RE
+.RE
+.SH "OPTIONS"
+.SS "Algorithm"
+.RS 0
+.PP
+\fB\-\-auto\fR
+.RS 4
+Automatically selects an appropriate strategy from L\-INS\-i, FFT\-NS\-i and FFT\-NS\-2, according to data 
+size.  Default: off (always FFT\-NS\-2)
+.RE
+.PP
+\fB\-\-6merpair\fR
+.RS 4
+Distance is calculated based on the number of shared 6mers.  Default: on
+.RE
+.PP
+\fB\-\-globalpair\fR
+.RS 4
+All pairwise alignments are computed with the Needleman\-Wunsch
+algorithm.  More accurate but slower 
+than \-\-6merpair.  Suitable for a set of
+globally alignable sequences.  Applicable to 
+up to ~200 sequences.  A combination with \-\-maxiterate 1000 is recommended (G\-INS\-i).  Default: off (6mer distance is used)
+.RE
+.PP
+\fB\-\-localpair\fR
+.RS 4
+All pairwise alignments are computed with the Smith\-Waterman
+algorithm.  More accurate but slower
+than \-\-6merpair.  Suitable for a set of 
+locally alignable sequences.  Applicable to 
+up to ~200 sequences.  A combination with \-\-maxiterate 1000 is recommended (L\-INS\-i).  Default: off (6mer distance is used)
+.RE
+.PP
+\fB\-\-genafpair\fR
+.RS 4
+All pairwise alignments are computed with a local
+algorithm with the generalized affine gap cost
+(Altschul 1998).  More accurate but slower
+than \-\-6merpair.  Suitable when large internal gaps
+are expected.  Applicable to 
+up to ~200 sequences.  A combination with \-\-maxiterate 1000 is recommended (E\-INS\-i).  Default: off (6mer distance is used)
+.RE
+.\".PP
+.\"\fB\-\-fastswpair\fR
+.\".RS 4
+.\"Distance is calculated based on a FASTA alignment. 
+.\"FASTA is required.  Default: off (6mer distance is used)
+.\".RE
+.PP
+\fB\-\-fastapair\fR
+.RS 4
+All pairwise alignments are computed with FASTA (Pearson and Lipman 1988).
+FASTA is required.  Default: off (6mer distance is used)
+.RE
+.\".PP
+.\"\fB\-\-blastpair\fR
+.\".RS 4
+.\"Distance is calculated based on a BLAST alignment.  BLAST is 
+.\"required.  Default: off (6mer distance is used)
+.\".RE
+.PP
+\fB\-\-weighti\fR \fInumber\fR
+.RS 4
+Weighting factor for the consistency term calculated from pairwise alignments.  Valid when 
+either of \-\-globalpair, \-\-localpair,  \-\-genafpair, \-\-fastapair or 
+\-\-blastpair is selected.  Default: 2.7
+.RE
+.PP
+\fB\-\-retree\fR \fInumber\fR
+.RS 4
+Guide tree is built \fInumber\fR times in the 
+progressive stage.  Valid with 6mer distance.  Default: 2
+.RE
+.PP
+\fB\-\-maxiterate\fR \fInumber\fR
+.RS 4
+\fInumber\fR cycles of iterative refinement are performed.  Default: 0
+.RE
+.PP
+\fB\-\-fft\fR
+.RS 4
+Use FFT approximation in group\-to\-group alignment.  Default: on
+.RE
+.PP
+\fB\-\-nofft\fR
+.RS 4
+Do not use FFT approximation in group\-to\-group alignment.  Default: off
+.RE
+.PP
+\fB\-\-noscore\fR
+.RS 4
+Alignment score is not checked in the iterative refinement stage.  Default: off (score is checked)
+.RE
+.PP
+\fB\-\-memsave\fR
+.RS 4
+Use the Myers\-Miller (1988) algorithm.  Default: automatically turned on when the alignment length exceeds 10,000 (aa/nt).
+.RE
+.PP
+\fB\-\-parttree\fR
+.RS 4
+Use a fast tree\-building method (PartTree, Katoh and Toh 2007) with
+the 6mer distance.  Recommended for a large number (> ~10,000) 
+of sequences are input.  Default: off
+.RE
+.PP
+\fB\-\-dpparttree\fR
+.RS 4
+The PartTree algorithm is used with distances based on DP.  Slightly
+more accurate and slower than \-\-parttree.  Recommended for a large
+number (> ~10,000) of sequences are input.   Default: off
+.RE
+.PP
+\fB\-\-fastaparttree\fR
+.RS 4
+The PartTree algorithm is used with distances based on FASTA.  Slightly more accurate and slower than \-\-parttree.  Recommended for a large number (> ~10,000) of sequences are input.  FASTA is required.  Default: off
+.RE
+.PP
+\fB\-\-partsize\fR \fInumber\fR
+.RS 4
+The number of partitions in the PartTree algorithm.  Default: 50
+.RE
+.PP
+\fB\-\-groupsize\fR \fInumber\fR
+.RS 4
+Do not make alignment larger than \fInumber\fR sequences. Valid only with the \-\-*parttree options.  Default: the number of input sequences
+.RE
+.RE
+.SS "Parameter"
+.RS 0
+.PP
+\fB\-\-op\fR \fInumber\fR
+.RS 4
+Gap opening penalty at group\-to\-group alignment.  Default: 1.53
+.RE
+.PP
+\fB\-\-ep\fR \fInumber\fR
+.RS 4
+Offset value, which works like gap extension penalty, for
+group\-to\-group alignment.  Default: 0.123
+.RE
+.PP
+\fB\-\-lop\fR \fInumber\fR
+.RS 4
+Gap opening penalty at local pairwise 
+alignment.  Valid when
+the \-\-localpair or \-\-genafpair option is selected.  Default: \-2.00
+.RE
+.PP
+\fB\-\-lep\fR \fInumber\fR
+.RS 4
+Offset value at local pairwise alignment.  Valid when
+the \-\-localpair or \-\-genafpair option is selected.  Default: 0.1
+.RE
+.PP
+\fB\-\-lexp\fR \fInumber\fR
+.RS 4
+Gap extension penalty at local pairwise alignment.  Valid when
+the \-\-localpair or \-\-genafpair option is selected.  Default: \-0.1
+.RE
+.PP
+\fB\-\-LOP\fR \fInumber\fR
+.RS 4
+Gap opening penalty to skip the alignment.  Valid when the
+\-\-genafpair option is selected.   Default: \-6.00
+.RE
+.PP
+\fB\-\-LEXP\fR \fInumber\fR
+.RS 4
+Gap extension penalty to skip the alignment.  Valid when the
+\-\-genafpair option is selected.   Default: 0.00
+.RE
+.PP
+\fB\-\-bl\fR \fInumber\fR
+.RS 4
+BLOSUM \fInumber\fR matrix (Henikoff and Henikoff 1992) is used.  \fInumber\fR=30, 45, 62 or 80.  Default: 62
+.RE
+.PP
+\fB\-\-jtt\fR \fInumber\fR
+.RS 4
+JTT PAM \fInumber\fR (Jones et al. 1992) matrix is used.  \fInumber\fR>0.  Default: BLOSUM62
+.RE
+.PP
+\fB\-\-tm\fR \fInumber\fR
+.RS 4
+Transmembrane PAM \fInumber\fR (Jones et al. 1994) matrix is used.  \fInumber\fR>0.  Default: BLOSUM62
+.RE
+.PP
+\fB\-\-aamatrix\fR \fImatrixfile\fR
+.RS 4
+Use a user\-defined AA scoring matrix.  The format of \fImatrixfile\fR is
+the same to that of BLAST.  Ignored when nucleotide sequences are input.   Default: BLOSUM62
+.RE
+.PP
+\fB\-\-fmodel\fR
+.RS 4
+Incorporate the AA/nuc composition information into
+the scoring matrix.  Default: off
+.RE
+.RE
+.SS "Output"
+.RS 0
+.PP
+\fB\-\-clustalout\fR
+.RS 4
+Output format: clustal format.  Default: off (fasta format)
+.RE
+.PP
+\fB\-\-inputorder\fR
+.RS 4
+Output order: same as input.  Default: on
+.RE
+.PP
+\fB\-\-reorder\fR
+.RS 4
+Output order: aligned.  Default: off (inputorder)
+.RE
+.PP
+\fB\-\-treeout\fR
+.RS 4
+Guide tree is output to the \fIinput\fR.tree file.  Default: off
+.RE
+.PP
+\fB\-\-quiet\fR
+.RS 4
+Do not report progress.  Default: off
+.RE
+.RE
+.SS "Input"
+.RS 0
+.PP
+\fB\-\-nuc\fR
+.RS 4
+Assume the sequences are nucleotide.  Default: auto
+.RE
+.PP
+\fB\-\-amino\fR
+.RS 4
+Assume the sequences are amino acid.  Default: auto
+.RE
+.PP
+\fB\-\-seed\fR \fIalignment1\fR [\fB--seed\fR \fIalignment2\fR \fB--seed\fR \fIalignment3\fR ...]
+.RS 4
+Seed alignments given in \fIalignment_n\fR (fasta format) are aligned with 
+sequences in \fIinput\fR.  The alignment within every seed is preserved.
+.RE
+.RE
+.SH "FILES"
+.RS 0
+.PP
+Mafft stores the input sequences and other files in a temporary directory, which by default is located in
+\fI/tmp\fR.
+.RE
+.SH "ENVIONMENT"
+.RS 0
+.PP
+\fBMAFFT_BINARIES\fR
+.RS 4
+Indicates the location of the binary files used by mafft. By default, they are searched in
+\fI/usr/local/lib/mafft\fR, but on Debian systems, they are searched in
+\fI/usr/lib/mafft\fR.
+.RE
+.PP
+\fBFASTA_4_MAFFT\fR
+.RS 4
+This variable can be set to indicate to mafft the location to the fasta34 program if it is not in the PATH.
+.RE
+.RE
+.SH "SEE ALSO"
+.RS 0
+.PP
+
+\fBmafft\-homologs\fR(1)
+.RE
+.SH "REFERENCES"
+.RS 0
+.SS "In English"
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'Katoh and Toh (Bioinformatics 23:372\-374, 2007) PartTree: an algorithm to build an approximate tree from a large number of unaligned sequences (describes the PartTree algorithm).
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'Katoh, Kuma, Toh and Miyata (Nucleic Acids Res. 33:511\-518, 2005) MAFFT version 5: improvement in accuracy of multiple sequence alignment (describes [ancestral versions of] the G\-INS\-i, L\-INS\-i and E\-INS\-i strategies)
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'Katoh, Misawa, Kuma and Miyata (Nucleic Acids Res. 30:3059\-3066, 2002) MAFFT: a novel method for rapid multiple sequence alignment based on fast Fourier transform (describes the FFT\-NS\-1, FFT\-NS\-2 and FFT\-NS\-i strategies)
+.RE
+.SS "In Japanese"
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'Katoh and Misawa (Seibutsubutsuri 46:312\-317, 2006) Multiple Sequence Alignments: the Next Generation
+.RE
+.sp
+.RS 4
+\h'-04'\(bu\h'+03'Katoh and Kuma (Kagaku to Seibutsu 44:102\-108, 2006) Jissen\-teki Multiple Alignment
+.RE
+.RE
+.SH "AUTHORS"
+.RS 0
+.PP
+\fBKazutaka Katoh\fR <\&kazutaka.katoh_at_aist.go.jp\&>
+.sp -1n
+.IP "" 4
+Wrote Mafft.
+.PP
+\fBCharles Plessy\fR <\&charles\-debian\-nospam_at_plessy.org\&>
+.sp -1n
+.IP "" 4
+Wrote this manpage in DocBook XML for the Debian distribution, using Mafft's homepage as a template.
+.RE
+.SH "COPYRIGHT"
+.RS 0
+Copyright \(co 2002\-2007 Kazutaka Katoh (mafft)
+.br
+Copyright \(co 2007 Charles Plessy (this manpage)
+.br
+.PP
+Mafft and its manpage are offered under the following conditions:
+.PP
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+.sp
+.RS 4
+\h'-04' 1.\h'+02'Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+.RE
+.sp
+.RS 4
+\h'-04' 2.\h'+02'Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+.RE
+.sp
+.RS 4
+\h'-04' 3.\h'+02'The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
+.RE
+.PP
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.br
+.RE
diff --git a/binaries/src/mafft/core/mafft.bat b/binaries/src/mafft/core/mafft.bat
new file mode 100644 (file)
index 0000000..bce9bde
--- /dev/null
@@ -0,0 +1,17 @@
+@echo off\r
+\r
+setlocal\r
+\r
+if not "x%PROCESSOR_ARCHITECTURE%" == "xAMD64" goto _NotX64\r
+set COMSPEC=%WINDIR%\SysWOW64\cmd.exe\r
+%COMSPEC% /c %0 %*\r
+goto EOF\r
+:_NotX64\r
+\r
+set ROOTDIR="%~d0%~p0\ms"\r
+set PATH=/bin/\r
+set MAFFT_BINARIES=/lib/mafft\r
+\r
+%ROOTDIR%\bin\sh %ROOTDIR%\bin\mafft %*\r
+\r
+:EOF\r
diff --git a/binaries/src/mafft/core/mafft.tmpl b/binaries/src/mafft/core/mafft.tmpl
new file mode 100644 (file)
index 0000000..7368f88
--- /dev/null
@@ -0,0 +1,1658 @@
+#! /bin/sh
+
+
+er=0;
+myself=`dirname "$0"`/`basename "$0"`; export myself
+version="v6.857b (2011/05/30)"; export version
+LANG=C; export LANG
+os=`uname`
+progname=`basename "$0"`
+if [ `echo $os | grep -i cygwin` ]; then
+       os="cygwin"
+elif [ `echo $os | grep -i darwin` ]; then
+       os="darwin"
+elif [ `echo $os | grep -i sunos` ]; then
+       os="sunos"
+elif [ `echo $os | grep -i linux` ]; then
+       os="linux"
+else
+       os="unix"
+fi
+export os
+
+if [ "$MAFFT_BINARIES" ]; then
+       prefix="$MAFFT_BINARIES"
+else
+       prefix=_LIBDIR
+fi
+export prefix
+
+if [ $# -gt 0 ]; then
+       if [ "$1" = "--man" ]; then 
+               man "$prefix/mafft.1"
+               exit 0;
+       fi
+fi
+
+if [ ! -x "$prefix/tbfast" ]; then
+       echo "" 1>&2
+       echo "correctly installed?" 1>&2
+       echo "mafft binaries have to be installed in \$MAFFT_BINARIES" 1>&2
+       echo "or the $prefix directory". 1>&2
+       echo "" 1>&2
+       exit 1
+       er=1
+fi
+
+defaultiterate=0
+defaultcycle=2
+defaultgop="1.53"
+#defaultaof="0.123"
+defaultaof="0.000"
+defaultlaof="0.100"
+defaultlgop="-2.00"
+defaultfft=1
+defaultrough=0
+defaultdistance="sixtuples"
+#defaultdistance="local"
+defaultweighti="2.7"
+defaultweightr="0.0"
+defaultweightm="1.0"
+defaultmccaskill=0
+defaultcontrafold=0
+defaultalgopt="  "
+defaultalgoptit="  "
+defaultsbstmodel=" -b 62 "
+defaultfmodel=" "
+defaultkappa=" "
+if [ $progname = "xinsi" -o $progname = "mafft-xinsi" ]; then
+       defaultfft=1
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="scarna"
+       defaultweighti="3.2"
+       defaultweightr="8.0"
+       defaultweightm="2.0"
+       defaultmccaskill=1
+       defaultcontrafold=0
+       defaultalgopt=" -A "
+       defaultalgoptit=" -AB " ## chui
+       defaultaof="0.0"
+       defaultsbstmodel=" -b 62 "
+       defaultkappa=" "
+       defaultfmodel=" -a "
+elif [ $progname = "qinsi" -o $progname = "mafft-qinsi" ]; then
+       defaultfft=1
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="global"
+       defaultweighti="3.2"
+       defaultweightr="8.0"
+       defaultweightm="2.0"
+       defaultmccaskill=1
+       defaultcontrafold=0
+       defaultalgopt=" -A "
+       defaultalgoptit=" -AB " ## chui
+       defaultaof="0.0"
+       defaultsbstmodel=" -b 62 "
+       defaultkappa=" "
+       defaultfmodel=" -a "
+elif [ $progname = "linsi" -o $progname = "mafft-linsi" ]; then
+       defaultfft=0
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="local"
+elif [ $progname = "ginsi" -o $progname = "mafft-ginsi" ]; then
+       defaultfft=1
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="global"
+elif [ $progname = "einsi" -o $progname = "mafft-einsi" ]; then
+       defaultfft=0
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="localgenaf"
+elif [ $progname = "fftns" -o $progname = "mafft-fftns" ]; then
+       defaultfft=1
+       defaultcycle=2
+       defaultdistance="sixtuples"
+elif [ $progname = "fftnsi" -o $progname = "mafft-fftnsi" ]; then
+       defaultfft=1
+       defaultcycle=2
+       defaultiterate=2
+       defaultdistance="sixtuples"
+elif [ $progname = "nwns" -o $progname = "mafft-nwns" ]; then
+       defaultfft=0
+       defaultcycle=2
+       defaultdistance="sixtuples"
+elif [ $progname = "nwnsi" -o $progname = "mafft-nwnsi" ]; then
+       defaultfft=0
+       defaultcycle=2
+       defaultiterate=2
+       defaultdistance="sixtuples"
+fi
+outputfile=""
+namelength=15
+anysymbol=0
+parallelizationstrategy="BAATARI2"
+kappa=$defaultkappa
+sbstmodel=$defaultsbstmodel
+fmodel=$defaultfmodel
+gop=$defaultgop
+aof=$defaultaof
+cycle=$defaultcycle
+iterate=$defaultiterate
+fft=$defaultfft
+rough=$defaultrough
+distance=$defaultdistance
+forcefft=0
+memopt=" "
+weightopt=" "
+GGOP="-6.00"
+LGOP="-6.00"
+LEXP="-0.000"
+GEXP="-0.000"
+lgop=$defaultlgop
+lexp="-0.100"
+laof=$defaultlaof
+pggop="-2.00"
+pgexp="-0.10"
+pgaof="0.10"
+rgop="-1.530"
+rgep="-0.000"
+seqtype="  "
+weighti=$defaultweighti
+weightr=$defaultweightr
+weightm=$defaultweightm
+rnaalifold=0
+mccaskill=$defaultmccaskill
+contrafold=$defaultcontrafold
+quiet=0
+debug=0
+sw=0
+algopt=$defaultalgopt
+algoptit=$defaultalgoptit
+scorecalcopt=" "
+coreout=0
+corethr="0.5"
+corewin="100"
+coreext=" "
+outputformat="pir"
+outorder="input"
+seed="x"
+seedtable="x"
+auto=0
+groupsize=-1
+partsize=50
+partdist="sixtuples"
+partorderopt=" -x "
+treeout=0
+distout=0
+treein=0
+topin=0
+treeinopt="  "
+seedfiles="/dev/null"
+seedtablefile="/dev/null"
+aamatrix="/dev/null"
+treeinfile="/dev/null"
+rnascoremtx=" "
+laraparams="/dev/null"
+foldalignopt=" "
+treealg=" -X "
+scoreoutarg=" "
+numthreads=0
+randomseed=0
+addfile="/dev/null"
+addarg0=" "
+outnum=" "
+if [ $# -gt 0 ]; then
+       while [ $# -gt 1 ];
+       do
+               if [ "$1" = "--auto" ]; then 
+                       auto=1
+               elif [ "$1" = "--anysymbol" ]; then 
+                       anysymbol=1
+               elif [ "$1" = "--preservecase" ]; then 
+                       anysymbol=1
+               elif [ "$1" = "--clustalout" ]; then 
+                       outputformat="clustal"
+               elif [ "$1" = "--phylipout" ]; then 
+                       outputformat="phylip"
+               elif [ "$1" = "--reorder" ]; then 
+                       outorder="aligned"
+                       partorderopt=" "
+               elif [ "$1" = "--inputorder" ]; then 
+                       outorder="input"
+                       partorderopt=" -x "
+               elif [ "$1" = "--unweight" ]; then 
+                       weightopt=" -u "
+               elif [ "$1" = "--algq" ]; then 
+                       algopt=" -Q "
+                       algoptit=" -QB "
+               elif [ "$1" = "--namelength" ]; then 
+                       shift   
+                       namelength=`expr "$1" - 0`
+               elif [ "$1" = "--groupsize" ]; then 
+                       shift   
+                       groupsize=`expr "$1" - 0`
+               elif [ "$1" = "--partsize" ]; then 
+                       shift   
+                       partsize=`expr "$1" - 0`
+               elif [ "$1" = "--parttree" ]; then 
+                       distance="parttree"
+                       partdist="sixtuples"
+               elif [ "$1" = "--dpparttree" ]; then 
+                       distance="parttree"
+                       partdist="localalign"
+               elif [ "$1" = "--fastaparttree" ]; then 
+                       distance="parttree"
+                       partdist="fasta"
+               elif [ "$1" = "--treeout" ]; then 
+                       treeout=1
+               elif [ "$1" = "--distout" ]; then 
+                       distout=1
+               elif [ "$1" = "--fastswpair" ]; then
+                       distance="fasta"
+                       sw=1
+               elif [ "$1" = "--fastapair" ]; then
+                       distance="fasta"
+                       sw=0
+               elif [ "$1" = "--averagelinkage" ]; then
+                       treealg=" -E "
+               elif [ "$1" = "--minimumlinkage" ]; then
+                       treealg=" -q "
+               elif [ "$1" = "--noscore" ]; then
+                       scorecalcopt=" -Z "
+               elif [ "$1" = "--6merpair" ]; then
+                       distance="sixtuples"
+               elif [ "$1" = "--blastpair" ]; then
+                       distance="blast"
+               elif [ "$1" = "--globalpair" ]; then
+                       distance="global"
+               elif [ "$1" = "--localpair" ]; then
+                       distance="local"
+               elif [ "$1" = "--scarnapair" ]; then
+                       distance="scarna"
+               elif [ "$1" = "--larapair" ]; then
+                       distance="lara"
+               elif [ "$1" = "--slarapair" ]; then
+                       distance="slara"
+               elif [ "$1" = "--foldalignpair" ]; then
+                       distance="foldalignlocal"
+               elif [ "$1" = "--foldalignlocalpair" ]; then
+                       distance="foldalignlocal"
+               elif [ "$1" = "--foldalignglobalpair" ]; then
+                       distance="foldalignglobal"
+               elif [ "$1" = "--globalgenafpair" ]; then
+                       distance="globalgenaf"
+               elif [ "$1" = "--localgenafpair" ]; then
+                       distance="localgenaf"
+               elif [ "$1" = "--genafpair" ]; then
+                       distance="localgenaf"
+               elif [ "$1" = "--memsave" ]; then
+                       memopt=" -M -B "         # -B (bunkatsunashi no riyu ga omoidasenai)
+               elif [ "$1" = "--nomemsave" ]; then
+                       memopt=" -N "
+               elif [ "$1" = "--nuc" ]; then 
+                       seqtype=" -D "
+               elif [ "$1" = "--amino" ]; then 
+                       seqtype=" -P "
+               elif [ "$1" = "--fft" ]; then 
+                       fft=1
+                       forcefft=1
+               elif [ "$1" = "--nofft" ]; then 
+                       fft=0
+               elif [ "$1" = "--quiet" ]; then 
+                       quiet=1
+               elif [ "$1" = "--debug" ]; then 
+                       debug=1
+               elif [ "$1" = "--coreext" ]; then 
+                       coreext=" -c "
+               elif [ "$1" = "--core" ]; then 
+                       coreout=1
+               elif [ "$1" = "--out" ]; then 
+                       shift   
+                       outputfile="$1"
+               elif [ "$1" = "--thread" ]; then 
+                       shift
+                       numthreads=`expr "$1" - 0` 
+               elif [ "$1" = "--randomseed" ]; then 
+                       shift
+                       randomseed=`expr "$1" - 0` 
+               elif [ "$1" = "--bestfirst" ]; then 
+                       parallelizationstrategy="BESTFIRST"
+               elif [ "$1" = "--adhoc0" ]; then 
+                       parallelizationstrategy="BAATARI0"
+               elif [ "$1" = "--adhoc1" ]; then 
+                       parallelizationstrategy="BAATARI1"
+               elif [ "$1" = "--adhoc2" ]; then 
+                       parallelizationstrategy="BAATARI2"
+               elif [ "$1" = "--simplehillclimbing" ]; then 
+                       parallelizationstrategy="BAATARI2"
+               elif [ "$1" = "--scoreout" ]; then 
+                       scoreoutarg="-S -B"
+               elif [ "$1" = "--outnum" ]; then 
+                       scoreoutarg="-n"
+               elif [ "$1" = "--addprofile" ]; then 
+                       shift   
+                       addarg0="-I"
+                       addfile="$1"
+               elif [ "$1" = "--add" ]; then 
+                       shift   
+                       addarg0="-K -I"
+                       addfile="$1"
+               elif [ "$1" = "--maxiterate" ]; then 
+                       shift   
+                       iterate=`expr "$1" - 0` 
+               elif [ "$1" = "--retree" ]; then 
+                       shift   
+                       cycle=`expr "$1" - 0`
+               elif [ "$1" = "--aamatrix" ]; then 
+                       shift   
+                       sbstmodel=" -b -1 "
+                       aamatrix="$1"
+               elif [ "$1" = "--treein" ]; then 
+                       shift   
+                       treeinopt=" -U "
+                       treein=1
+                       treeinfile="$1"
+               elif [ "$1" = "--topin" ]; then 
+                       shift   
+                       treeinopt=" -V "
+                       treein=1
+                       treeinfile="$1"
+                       echo "The --topin option has been disabled." 1>&2
+                       echo "There was a bug in version < 6.530."   1>&2
+                       echo "This bug has not yet been fixed."      1>&2
+                       exit 1
+               elif [ "$1" = "--kappa" ]; then 
+                       shift   
+                       kappa=" -k $1 "
+               elif [ "$1" = "--fmodel" ]; then 
+                       fmodel=" -a "
+               elif [ "$1" = "--jtt" ]; then 
+                       shift   
+                       sbstmodel=" -j $1"
+               elif [ "$1" = "--kimura" ]; then 
+                       shift   
+                       sbstmodel=" -j $1"
+               elif [ "$1" = "--tm" ]; then 
+                       shift   
+                       sbstmodel=" -m $1"
+               elif [ "$1" = "--bl" ]; then 
+                       shift   
+                       sbstmodel=" -b $1"
+               elif [ "$1" = "--weighti" ]; then
+                       shift   
+                       weighti="$1"
+               elif [ "$1" = "--weightr" ]; then
+                       shift   
+                       weightr="$1"
+               elif [ "$1" = "--weightm" ]; then
+                       shift   
+                       weightm="$1"
+               elif [ "$1" = "--rnaalifold" ]; then
+                       rnaalifold=1
+               elif [ "$1" = "--mccaskill" ]; then
+                       mccaskill=1
+                       contrafold=0
+               elif [ "$1" = "--contrafold" ]; then
+                       mccaskill=0
+                       contrafold=1
+               elif [ "$1" = "--ribosum" ]; then
+                       rnascoremtx=" -s "
+               elif [ "$1" = "--op" ]; then 
+                       shift   
+                       gop="$1"
+               elif [ "$1" = "--ep" ]; then 
+                       shift   
+                       aof="$1"
+               elif [ "$1" = "--rop" ]; then 
+                       shift   
+                       rgop="$1"
+               elif [ "$1" = "--rep" ]; then 
+                       shift   
+                       rgep="$1"
+               elif [ "$1" = "--lop" ]; then 
+                       shift   
+                       lgop="$1"
+               elif [ "$1" = "--LOP" ]; then 
+                       shift   
+                       LGOP="$1"
+               elif [ "$1" = "--lep" ]; then 
+                       shift   
+                       laof="$1"
+               elif [ "$1" = "--lexp" ]; then 
+                       shift   
+                       lexp="$1"
+               elif [ "$1" = "--LEXP" ]; then 
+                       shift   
+                       LEXP="$1"
+               elif [ "$1" = "--GEXP" ]; then 
+                       shift   
+                       GEXP="$1"
+               elif [ "$1" = "--GOP" ]; then 
+                       shift   
+                       GGOP="$1"
+               elif [ "$1" = "--gop" ]; then 
+                       shift   
+                       pggop="$1"
+               elif [ "$1" = "--gep" ]; then 
+                       shift   
+                       pgaof="$1"
+               elif [ "$1" = "--gexp" ]; then 
+                       shift   
+                       pgexp="$1"
+               elif [ "$1" = "--laraparams" ]; then 
+                       shift   
+                       laraparams="$1"
+               elif [ "$1" = "--corethr" ]; then 
+                       shift   
+                       corethr="$1"
+               elif [ "$1" = "--corewin" ]; then 
+                       shift   
+                       corewin="$1"
+               elif [ "$1" = "--seedtable" ]; then
+                       shift
+                       seedtable="y"
+                       seedtablefile="$1"
+               elif [ "$1" = "--seed" ]; then
+                       shift
+                       seed="m"
+                       seedfiles="$seedfiles $1"
+               elif [ $progname = "fftns" -o  $progname = "nwns" ]; then
+                       if [ "$1" -gt 0 ]; then
+                               cycle=`expr "$1" - 0`
+                       fi
+               else
+                       echo "Unknown option:  $1" 1>&2
+                       er=1;
+               fi
+               shift   
+       done;
+
+
+
+#      TMPFILE=/tmp/$progname.$$
+       TMPFILE=`mktemp -dt $progname.XXXXXXXXXX`
+       if [ $? -ne 0 ]; then
+               echo "mktemp seems to be obsolete. Re-trying without -t" 1>&2
+               TMPFILE=`mktemp -d /tmp/$progname.XXXXXXXXXX`
+       fi      
+       umask 077
+#      mkdir  $TMPFILE  || er=1
+       if [ $debug -eq 1 ]; then
+               trap "tar cfvz debuginfo.tgz $TMPFILE; rm -rf $TMPFILE " 0
+       else
+               trap "rm -rf $TMPFILE " 0
+       fi
+       if [ $# -eq 1 ]; then
+               if [ -r "$1" -o "$1" = - ]; then
+
+                       if [ -r "$addfile" ]; then
+                               printf '';
+                       else
+                               echo "$0": Cannot open "$addfile". 1>&2
+                               exit 1;
+                       fi
+
+                       cat "$1"              | tr "\r" "\n" > $TMPFILE/infile 
+                       echo ""                             >> $TMPFILE/infile
+                       cat "$addfile"        | tr "\r" "\n" | grep -v "^$" >> $TMPFILE/infile
+                       cat "$addfile"        | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_addfile
+                       cat "$aamatrix"       | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_aamtx
+                       cat "$treeinfile"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_guidetree
+                       cat "$seedtablefile"  | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_seedtablefile
+                       cat "$laraparams"     | tr "\r" "\n" | grep -v "^$" > $TMPFILE/_lara.params
+#                      echo $seedfiles
+                       infilename="$1"
+                       seedfilesintmp="/dev/null"
+                       seednseq="0"
+                       set $seedfiles > /dev/null
+                       while [ $# -gt 1 ];
+                       do
+                               shift
+                               if [ -r "$1" ]; then
+                                       cat "$1" | tr "\r" "\n" >  $TMPFILE/seed$#
+                               else
+                                       echo "$0": Cannot open "$1". 1>&2
+                                       exit 1;
+                               fi
+                               seednseq=$seednseq" "`grep -c '^[>|=]' $TMPFILE/seed$#`
+                               seedfilesintmp=$seedfilesintmp" "seed$#
+                       done
+#                      ls $TMPFILE
+#                      echo $seedfilesintmp
+#                      echo $seednseq
+
+
+               else
+                       echo "$0": Cannot open "$1". 1>&2
+                       er=1
+#                      exit 1;
+               fi
+       else
+               echo '$#'"=$#" 1>&2
+               er=1
+       fi
+
+
+       if [ $os != "linux" ]; then
+               numthreads=0
+       fi
+
+       if [ $numthreads -eq 0 -a $parallelizationstrategy = "BESTFIRST" ]; then
+               echo 'Impossible' 1>&2;
+               exit 1;
+       fi
+
+       if [ $auto -eq 1 ]; then
+               "$prefix/countlen" < $TMPFILE/infile > $TMPFILE/size
+               nseq=`awk '{print $1}' $TMPFILE/size`
+               nlen=`awk '{print $3}' $TMPFILE/size`
+               if [ $nlen -lt 2000 -a $nseq -lt 100 ]; then
+                       distance="local"
+                       iterate=1000
+               elif [ $nlen -lt 10000 -a $nseq -lt 500 ]; then
+                       distance="sixtuples"
+                       iterate=2
+               else
+                       distance="sixtuples"
+                       iterate=0
+               fi
+               if [ $quiet -eq 0 ]; then
+                       echo "nseq = " $nseq              1>&2
+                       echo "nlen = " $nlen              1>&2
+                       echo "distance = " $distance      1>&2
+                       echo "iterate = " $iterate        1>&2
+               fi
+       fi
+
+       if [ $parallelizationstrategy = "BESTFIRST" -o  $parallelizationstrategy = "BAATARI0" ]; then
+               iteratelimit=254
+       else
+               iteratelimit=16
+       fi
+       if [ $iterate -gt $iteratelimit ]; then    #??
+               iterate=$iteratelimit
+       fi
+
+       if [ $rnaalifold -eq 1 ]; then
+               rnaopt=" -e $rgep -o $rgop -c $weightm -r $weightr -R $rnascoremtx "
+#              rnaoptit=" -o $rgop -BT -c $weightm -r $weightr -R "
+               rnaoptit=" -o $rgop -F -c $weightm -r $weightr -R "
+       elif [ $mccaskill -eq 1 -o $contrafold -eq 1 ]; then
+               rnaopt=" -o $rgop -c $weightm -r $weightr "
+#              rnaoptit=" -e $rgep -o $rgop -BT -c $weightm -r $weightr $rnascoremtx "
+               rnaoptit=" -e $rgep -o $rgop -F -c $weightm -r $weightr $rnascoremtx "
+       else
+               rnaopt="  "
+               rnaoptit=" -F "
+       fi
+
+       model="$sbstmodel $kappa $fmodel"
+
+       if [ $er -eq 1 ]; then
+               echo "------------------------------------------------------------------------------" 1>&2
+               echo "  MAFFT" $version 1>&2
+#              echo "" 1>&2
+#              echo "  Input format: fasta" 1>&2
+#              echo ""  1>&2
+#              echo "  Usage: `basename $0` [options] inputfile > outputfile" 1>&2
+           echo "  http://mafft.cbrc.jp/alignment/software/" 1>&2
+               echo "  NAR 30:3059-3066 (2002), Briefings in Bioinformatics 9:286-298 (2008)"        1>&2
+#              echo "------------------------------------------------------------------------------" 1>&2
+#              echo "  % mafft in > out" 1>&2
+               echo "------------------------------------------------------------------------------" 1>&2
+#              echo ""  1>&2
+               echo "High speed:" 1>&2
+               echo "  % mafft in > out" 1>&2
+               echo "  % mafft --retree 1 in > out (fast)" 1>&2
+               echo "" 1>&2
+               echo "High accuracy (for <~200 sequences x <~2,000 aa/nt):" 1>&2
+               echo "  % mafft --maxiterate 1000 --localpair  in > out (% linsi in > out is also ok)" 1>&2
+               echo "  % mafft --maxiterate 1000 --genafpair  in > out (% einsi in > out)" 1>&2
+               echo "  % mafft --maxiterate 1000 --globalpair in > out (% ginsi in > out)" 1>&2
+               echo "" 1>&2
+               echo "If unsure which option to use:" 1>&2
+               echo "  % mafft --auto in > out" 1>&2
+               echo "" 1>&2
+#              echo "Other options:" 1>&2
+               echo "--op # :         Gap opening penalty, default: 1.53" 1>&2
+               echo "--ep # :         Offset (works like gap extension penalty), default: 0.0" 1>&2
+               echo "--maxiterate # : Maximum number of iterative refinement, default: 0" 1>&2
+               echo "--clustalout :   Output: clustal format, default: fasta" 1>&2
+               echo "--reorder :      Outorder: aligned, default: input order" 1>&2
+               echo "--quiet :        Do not report progress" 1>&2
+               echo "--thread # :     Number of threads. (# must be <= number of physical cores - 1)" 1>&2
+#              echo "" 1>&2
+#              echo " % mafft --maxiterate 1000 --localpair in > out (L-INS-i)" 1>&2
+#              echo " most accurate in many cases, assumes only one alignable domain" 1>&2 
+#              echo "" 1>&2
+#              echo " % mafft --maxiterate 1000 --genafpair in > out (E-INS-i)" 1>&2
+#              echo " works well if many unalignable residues exist between alignable domains" 1>&2
+#              echo "" 1>&2
+#              echo " % mafft --maxiterate 1000 --globalpair in > out (G-INS-i)" 1>&2
+#              echo " suitable for globally alignable sequences            " 1>&2
+#              echo "" 1>&2
+#              echo " % mafft --maxiterate 1000 in > out (FFT-NS-i)" 1>&2
+#              echo " accurate and slow, iterative refinement method      " 1>&2
+#              echo "" 1>&2
+#              echo "If the input sequences are long (~1,000,000nt)," 1>&2
+#              echo " % mafft --retree 1 --memsave --fft in > out (FFT-NS-1-memsave, new in v5.8)" 1>&2
+#              echo "" 1>&2
+#              echo "If many (~5,000) sequences are to be aligned," 1>&2
+#              echo "" 1>&2
+#              echo " % mafft --retree 1 [--memsave] --nofft in > out (NW-NS-1, new in v5.8)" 1>&2
+#              echo "" 1>&2
+#              echo " --localpair :      All pairwise local alignment information is included"  1>&2
+#              echo "                    to the objective function, default: off"  1>&2
+#              echo " --globalpair :     All pairwise global alignment information is included"  1>&2
+#              echo "                    to the objective function, default: off"  1>&2
+#              echo " --op # :           Gap opening penalty, default: $defaultgop " 1>&2
+#              echo " --ep # :           Offset (works like gap extension penalty), default: $defaultaof " 1>&2
+#              echo " --bl #, --jtt # :  Scoring matrix, default: BLOSUM62" 1>&2
+#              echo "                    Alternatives are BLOSUM (--bl) 30, 45, 62, 80, " 1>&2
+#              echo "                    or JTT (--jtt) # PAM. " 1>&2
+#              echo " --nuc or --amino : Sequence type, default: auto" 1>&2
+#              echo " --retree # :       The number of tree building in progressive method " 1>&2
+#              echo "                    (see the paper for detail), default: $defaultcycle " 1>&2
+#              echo " --maxiterate # :   Maximum number of iterative refinement, default: $defaultiterate " 1>&2
+#              if [ $defaultfft -eq 1 ]; then
+#                      echo " --fft or --nofft:  FFT is enabled or disabled, default: enabled" 1>&2
+#              else
+#                      echo " --fft or --nofft:  FFT is enabled or disabled, default: disabled" 1>&2
+#              fi
+#              echo " --memsave:         Memory saving mode" 1>&2
+#              echo "                    (for long genomic sequences), default: off" 1>&2
+#              echo " --clustalout :     Output: clustal format, default: fasta" 1>&2
+#              echo " --reorder :        Outorder: aligned, default: input order" 1>&2
+#              echo " --quiet :          Do not report progress" 1>&2
+#              echo "-----------------------------------------------------------------------------" 1>&2
+               exit 1; 
+       fi
+       if [ $sw -eq 1 ]; then
+               swopt=" -A "
+       else
+               swopt=" "
+       fi
+
+       if [ $distance = "fasta" -o $partdist = "fasta" ]; then
+               if [ ! "$FASTA_4_MAFFT" ]; then
+                       FASTA_4_MAFFT=`which fasta34`
+               fi
+
+               if [ ! -x "$FASTA_4_MAFFT" ]; then
+                       echo ""       1>&2
+                       echo "== Install FASTA ========================================================" 1>&2
+                       echo "This option requires the fasta34 program (FASTA version x.xx or higher)"   1>&2
+                       echo "installed in your PATH.  If you have the fasta34 program but have renamed" 1>&2
+                       echo "(like /usr/local/bin/myfasta), set the FASTA_4_MAFFT environment variable" 1>&2
+                       echo "to point your fasta34 (like setenv FASTA_4_MAFFT /usr/local/bin/myfasta)." 1>&2
+                       echo "=========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+       if [ $distance = "lara" -o $distance = "slara" ]; then
+               if [ ! -x "$prefix/mafft_lara" ]; then
+                       echo ""       1>&2
+                       echo "== Install LaRA =========================================================" 1>&2
+                       echo "This option requires LaRA (Bauer et al. http://www.planet-lisa.net/)."     1>&2
+                       echo "The executable have to be renamed to 'mafft_lara' and installed into "     1>&2
+                       echo "the $prefix directory. "                                                   1>&2
+                       echo "A configuration file of LaRA also have to be given"                        1>&2
+                       echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
+                       echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
+                       echo "=========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+               if [ ! -s "$laraparams" ]; then
+                       echo ""       1>&2
+                       echo "== Configure LaRA =======================================================" 1>&2
+                       echo "A configuration file of LaRA have to be given"                             1>&2
+                       echo "mafft-xinsi --larapair --laraparams parameter_file"                        1>&2
+                       echo "mafft-xinsi --slarapair --laraparams parameter_file"                       1>&2
+                       echo "=========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+       if [ $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
+       if [ ! -x "$prefix/foldalign210" ]; then
+                       echo ""       1>&2
+                       echo "== Install FOLDALIGN ====================================================" 1>&2
+                       echo "This option requires FOLDALIGN (Havgaard et al. http://foldalign.ku.dk/)." 1>&2
+                       echo "The executable have to be renamed to 'foldalign210' and installed into "   1>&2
+                       echo "the $prefix directory. "                                                   1>&2
+                       echo "=========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+       if [ $distance = "scarna" ]; then
+               if [ ! -x "$prefix/mxscarnamod" ]; then
+                       echo ""       1>&2
+                       echo "== Install MXSCARNA ======================================================" 1>&2
+                       echo "MXSCARNA (Tabei et al. BMC Bioinformatics 2008 9:33) is required."          1>&2
+                       echo "Please 'make' at the 'extensions' directory of the MAFFT source package,"   1>&2
+                       echo "which contains the modified version of MXSCARNA."                           1>&2
+                       echo "http://align.bmr.kyushu-u.ac.jp/mafft/software/source.html "                1>&2
+                       echo "==========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+       if [ $mccaskill -eq 1 ]; then
+               if [ ! -x "$prefix/mxscarnamod" ]; then
+                       echo ""       1>&2
+                       echo "== Install MXSCARNA ======================================================" 1>&2
+                       echo "MXSCARNA (Tabei et al. BMC Bioinformatics 2008 9:33) is required."          1>&2
+                       echo "Please 'make' at the 'extensions' directory of the MAFFT source package,"   1>&2
+                       echo "which contains the modified version of MXSCARNA."                           1>&2
+                       echo "http://align.bmr.kyushu-u.ac.jp/mafft/software/source.html "                1>&2
+                       echo "==========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+       if [ $contrafold -eq 1 ]; then
+               if [ ! -x "$prefix/contrafold" ]; then
+                       echo ""       1>&2
+                       echo "== Install CONTRAfold ===================================================" 1>&2
+                       echo "This option requires CONTRAfold"                                           1>&2
+                       echo "(Do et al. http://contra.stanford.edu/contrafold/)."                       1>&2
+                       echo "The executable 'contrafold' have to be installed into "                    1>&2
+                       echo "the $prefix directory. "                                                   1>&2
+                       echo "=========================================================================" 1>&2
+                       echo "" 1>&2
+                       exit 1
+               fi
+       fi
+
+#old
+#      if [ $treeout -eq 1 ]; then
+#              parttreeoutopt="-t"
+#              if [ $cycle -eq 0 ]; then
+#                      treeoutopt="-t -T"
+#                      groupsize=1
+#                      iterate=0 
+#                      if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
+#                              distance="distonly"
+#                      fi
+#              else
+#                      treeoutopt="-t"
+#              fi
+#      else
+#              parttreeoutopt=" "
+#              if [ $cycle -eq 0 ]; then
+#                      treeoutopt="-t -T"
+#                      iterate=0 
+#                      if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
+#                              distance="distonly"
+#                      fi
+#              else
+#                      treeoutopt=" "
+#              fi
+#      fi
+
+#new
+       if [ $cycle -eq 0 ]; then
+               treeoutopt="-t -T"
+               iterate=0 
+               if [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
+                       distance="distonly"
+               fi
+               if [ $treeout -eq 1 ]; then
+                       parttreeoutopt="-t"
+                       groupsize=1
+               else
+                       parttreeoutopt=" "
+               fi
+               if [ $distout -eq 1 ]; then
+                       distoutopt="-y -T"
+               fi
+       else
+               if [ $treeout -eq 1 ]; then
+                       parttreeoutopt="-t"
+                       treeoutopt="-t"
+               else
+                       parttreeoutopt=" "
+                       treeoutopt=" "
+               fi
+               if [ $distout -eq 1 ]; then
+                       distoutopt="-y"
+               fi
+       fi
+#
+
+       formatcheck=`grep -c '^[[:blank:]]\+>' $TMPFILE/infile | head -1 `
+       if [ $formatcheck -gt 0 ]; then
+               echo "The first character of a description line must be " 1>&2
+               echo "the greater-than (>) symbol, not a blank."           1>&2
+               echo "Please check the format around the following line(s):"  1>&2
+               grep -n '^[[:blank:]]\+>' $TMPFILE/infile  1>&2
+               exit 1
+       fi
+
+       nseq=`grep -c '^[>|=]' $TMPFILE/infile | head -1 ` 
+       if [ $nseq -eq 2 ]; then
+               cycle=1
+       fi
+       if [ $cycle -gt 3 ]; then
+               cycle=3
+       fi
+
+       if [ $nseq -gt 4000 -a $iterate -gt 1 ]; then
+               echo "Too many sequences to perform iterative refinement!" 1>&2
+               echo "Please use a progressive method." 1>&2
+               exit 1
+       fi
+
+
+       if [ $distance = "sixtuples" -a \( $seed = "x" -a $seedtable = "x" \) ]; then
+               localparam=" "
+       elif [ $distance = "sixtuples" -a \( $seed != "x" -o $seedtable != "x" \) ]; then
+               if [ $cycle -lt 2 ]; then
+                       cycle=2                # nazeda
+               fi
+               if [ $iterate -lt 2 ]; then
+                       echo "############################################################################" 1>&2
+                       echo "# Warning:" 1>&2
+                       echo "#   Progressive alignment method is incompatible with the --seed option." 1>&2
+                       echo "#   Automatically switched to the iterative refinement method." 1>&2
+                       echo "#   " 1>&2
+                       echo "# Also consider using the '--add' option, which is compatible with" 1>&2
+                       echo "#   the progressive method and FASTER than the '--seed' option." 1>&2
+                       echo "#   Usage is:" 1>&2
+                       echo "#   % mafft --add newSequences existingAlignment > output" 1>&2
+                       echo "############################################################################" 1>&2
+                       iterate=2
+               fi
+               localparam="-l "$weighti
+       elif [ $distance = "parttree" ]; then
+               localparam=" "
+               if [ $groupsize -gt -1 ]; then
+                       cycle=1
+               fi
+       else
+               localparam=" -l "$weighti
+               if [ $cycle -gt 1 ]; then  # 09/01/08
+                       cycle=1
+               fi
+       fi
+
+       if [ $distance = "localgenaf" -o $distance = "globalgenaf" ]; then
+               aof="0.000"
+       fi
+
+       if [ "$memopt" = " -M -B " -a "$distance" != "sixtuples" ]; then
+               echo "Impossible" 1>&2
+               exit 1
+       fi
+#exit
+
+       if [ $distance = "parttree" ]; then
+               if [ $seed != "x" -o $seedtable != "x" ]; then
+                       echo "Impossible" 1>&2
+                       exit 1
+               fi
+               if [ $iterate -gt 1 ]; then
+                       echo "Impossible" 1>&2
+                       exit 1
+               fi
+               if [ $outorder = "aligned" ]; then
+                       outorder="input"
+               fi
+               outorder="input"   # partorder ga kiku
+               if [ $partdist = "localalign" ]; then
+                       splitopt=" -L "    # -L -l -> fast 
+               elif [ $partdist = "fasta" ]; then
+                       splitopt=" -S "
+               else
+                       splitopt="  "
+               fi
+       fi
+
+
+#      if [ $nseq -gt 5000 ]; then
+#              fft=0
+#      fi
+       if [ $forcefft -eq 1 ]; then
+               param_fft=" -G "
+               fft=1
+       elif [ $fft -eq 1 ]; then
+               param_fft=" -F "
+       else
+               param_fft=" "
+       fi
+
+       if [ $seed != "x" -a $seedtable != "x" ]; then
+                       echo 'Use either one of seedtable and seed.  Not both.' 1>&2
+                       exit 1
+       fi
+#      if [ $seedtable != "x" -a $anysymbol -gt 0 ]; then
+#                      echo 'The combination of --seedtable and --anysymbol is not supported.' 1>&2
+#                      exit 1
+#      fi
+
+       if [ $treein -eq 1 ]; then
+#              if [ $iterate -gt 0 ]; then
+#                      echo 'Not supported yet.' 1>&2
+#                      exit 1
+#              fi
+               cycle=1
+       fi
+
+       if [ "$addarg0" != " " ]; then
+               "$prefix/countlen" < $TMPFILE/_addfile > $TMPFILE/addsize
+               nadd=`awk '{print $1}' $TMPFILE/addsize`
+               if [ $nadd -eq "0" ]; then
+                       echo Check $addfile 1>&2
+                       exit 1;
+               fi
+               addarg="$addarg0 $nadd"
+               cycle=1
+               iterate=0
+               if [ $seed != "x" -o $seedtable != "x" ]; then
+                       echo 'Impossible' 1>&2;
+                       echo 'Use either ONE of --seed, --seedtable, --addprofile and --add.' 1>&2
+                       exit 1;
+               fi
+       fi
+
+       if [ $mccaskill -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
+               if [ $distance = "sixtuples" ]; then
+                       echo 'Not supported.' 1>&2
+                       echo 'Please add --globalpair, --localpair, --scarnapair,' 1>&2
+                       echo '--larapair, --slarapair, --foldalignlocalpair or --foldalignglobalpair' 1>&2
+                       exit 1
+               fi
+       fi
+
+       if [ $mccaskill -eq 1 -o $rnaalifold -eq 1 -o $contrafold -eq 1 ]; then
+               if [ $distance = "scarna" -o $distance = "lara" -o $distance = "slara" -o $distance = "foldalignlocal" -o $distance = "foldalignglobal" ]; then
+                       strategy="X-I"
+               elif [ $distance = "global" -o $distance = "local" -o $distance = "localgenaf" -o "globalgenaf" ]; then
+                       strategy="Q-I"
+               fi
+       elif [ $distance = "fasta" -a $sw -eq 0 ]; then
+               strategy="F-I"
+       elif [ $distance = "fasta" -a $sw -eq 1 ]; then
+               strategy="H-I"
+       elif [ $distance = "blast" ]; then
+               strategy="B-I"
+       elif [ $distance = "global" -o $distance = "distonly" ]; then
+               strategy="G-I"
+       elif [ $distance = "local" ]; then
+               strategy="L-I"
+       elif [ $distance = "localgenaf" ]; then
+               strategy="E-I"
+       elif [ $distance = "globalgenaf" ]; then
+               strategy="K-I"
+       elif [ $fft -eq 1 ]; then
+               strategy="FFT-"
+       else
+               strategy="NW-"
+       fi
+       strategy=$strategy"NS-"
+       if [ $iterate -gt 0 ]; then
+               strategy=$strategy"i"
+       elif [ $distance = "parttree" ]; then
+               if [ $partdist = "fasta" ]; then
+                       strategy=$strategy"FastaPartTree-"$cycle
+               elif [ $partdist = "localalign" ]; then
+                       strategy=$strategy"DPPartTree-"$cycle
+               else
+                       strategy=$strategy"PartTree-"$cycle
+               fi
+       else
+               strategy=$strategy$cycle
+       fi
+
+       explanation='?'
+       performance='Not tested.'
+       if [ $strategy = "F-INS-i" ]; then
+               explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
+               performance='Most accurate, but very slow'
+       elif [ $strategy = "L-INS-i" ]; then
+               explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment information'
+               performance='Probably most accurate, very slow'
+       elif [ $strategy = "E-INS-i" ]; then
+               explanation='Iterative refinement method (<'$iterate') with LOCAL pairwise alignment with generalized affine gap costs (Altschul 1998)'
+               performance='Suitable for sequences with long unalignable regions, very slow'
+       elif [ $strategy = "G-INS-i" ]; then
+               explanation='Iterative refinement method (<'$iterate') with GLOBAL pairwise alignment information'
+               performance='Suitable for sequences of similar lengths, very slow'
+       elif [ $strategy = "X-INS-i" ]; then
+               explanation='RNA secondary structure information is taken into account.'
+               performance='For short RNA sequences only, extremely slow'
+       elif [ $strategy = "F-INS-1" ]; then
+               explanation='Progressive method incorporating LOCAL pairwise alignment information'
+       elif [ $strategy = "L-INS-1" ]; then
+               explanation='Progressive method incorporating LOCAL pairwise alignment information'
+       elif [ $strategy = "G-INS-1" ]; then
+               explanation='Progressive method incorporating GLOBAL pairwise alignment information'
+       elif [ $strategy = "FFT-NS-i" -o $strategy = "NW-NS-i" ]; then
+               explanation='Iterative refinement method (max. '$iterate' iterations)'
+               if [ $iterate -gt 2 ]; then
+                       performance='Accurate but slow'
+               else
+                       performance='Standard'
+               fi
+       elif [ $strategy = "FFT-NS-2" -o $strategy = "NW-NS-2" ]; then
+               explanation='Progressive method (guide trees were built '$cycle' times.)'
+               performance='Fast but rough'
+       elif [ $strategy = "FFT-NS-1" -o $strategy = "NW-NS-1" ]; then
+               explanation='Progressive method (rough guide tree was used.)'
+               performance='Very fast but very rough'
+       fi
+
+       if [ $outputformat = "clustal" -a $outorder = "aligned" ]; then
+               outputopt=" -c $strategy -r $TMPFILE/order  "
+       elif [ $outputformat = "clustal" -a $outorder = "input" ]; then
+               outputopt=" -c $strategy  "
+       elif [ $outputformat = "phylip" -a $outorder = "aligned" ]; then
+               outputopt=" -y -r $TMPFILE/order "
+       elif [ $outputformat = "phylip" -a $outorder = "input" ]; then
+               outputopt=" -y "
+       elif [ $outputformat = "pir" -a $outorder = "aligned" ]; then
+               outputopt=" -f -r $TMPFILE/order "
+       else
+               outputopt="null"
+       fi
+       
+       (
+               cd $TMPFILE;
+
+               if [ $quiet -gt 0 ]; then
+
+                       if [ $anysymbol -eq 1 ]; then
+                               mv infile orig
+                               "$prefix/replaceu" -i orig > infile 2>/dev/null || exit 1
+                       fi
+
+                       if [ $seed != "x" ]; then
+                               mv infile infile2
+                               if [ $anysymbol -eq 1 ]; then
+                                       mv orig orig2
+                                       cat /dev/null > orig
+                               fi
+                               cat /dev/null > infile
+                               cat /dev/null > hat3.seed
+                               seedoffset=0
+#                              echo "seednseq="$seednseq
+#                              echo "seedoffset="$seedoffset
+                               set $seednseq > /dev/null
+#                              echo $#
+                               while [ $# -gt 1 ]
+                               do
+                                       shift
+#                                      echo "num="$#
+
+                                       if [ $anysymbol -eq 1 ]; then
+                                               cat seed$# >> orig
+                                               "$prefix/replaceu" -i seed$# -o $seedoffset > clean 2>/dev/null || exit 1
+                                               mv clean seed$#
+                                       fi
+                                       "$prefix/multi2hat3s" -t $nseq -o $seedoffset -i seed$# >> infile 2>/dev/null || exit 1
+                                       cat hat3 >> hat3.seed
+#                                      echo "$1"
+                                       seedoffset=`expr $seedoffset + $1`
+#                                      echo "$1"
+#                                      echo "seedoffset="$seedoffset
+                               done;
+#                              echo "seedoffset="$seedoffset
+                               if [ $anysymbol -eq 1 ]; then
+                                       "$prefix/replaceu" -i orig2 -o $seedoffset >> infile 2>/dev/null || exit 1  # yarinaoshi
+                                       cat orig2 >> orig
+                               else
+                                       cat infile2 >> infile
+                               fi
+                       elif [ $seedtable != "x" ]; then
+                               cat _seedtablefile > hat3.seed
+                       else
+                               cat /dev/null > hat3.seed
+                       fi
+#                      cat hat3.seed
+
+
+                       if [ $mccaskill -eq 1 ]; then
+                               "$prefix/mccaskillwrap" -C $numthreads -d "$prefix" -i infile > hat4 2>/dev/null || exit 1
+                       elif [ $contrafold -eq 1 ]; then
+                               "$prefix/contrafoldwrap" -d "$prefix" -i infile > hat4 2>/dev/null || exit 1
+                       fi
+                       if [ $distance = "fasta" ]; then
+                               "$prefix/dndfast7" $swopt < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "blast" ]; then
+                               "$prefix/dndblast" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "foldalignlocal" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $lexp -f $lgop -h $laof -H -d "$prefix" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "foldalignglobal" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $pgexp -f $pggop -h $pgaof -H -o -global -d "$prefix" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "slara" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -T -d "$prefix" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "lara" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -B -d "$prefix" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "scarna" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -f $pggop  -s -d "$prefix" < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "global" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -F < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "local" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -L < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "globalgenaf" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $pgexp -f $pggop  -h $pgaof -O $GGOP -E $GEXP -K  < infile > /dev/null 2>&1    || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "localgenaf" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N < infile > /dev/null  2>&1      || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "distonly" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -t < infile > /dev/null  2>&1      || exit 1
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "parttree" ]; then
+                               "$prefix/splittbfast" -Q $splitopt $partorderopt $parttreeoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre 2>/dev/null || exit 1
+                               mv hat3.seed hat3
+                       else
+                               "$prefix/disttbfast" -O $outnum $addarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $algopt $treealg $scoreoutarg < infile   > pre 2>/dev/null || exit 1
+                               mv hat3.seed hat3
+                       fi
+                       while [ $cycle -gt 1 ]
+                       do
+                               if [ $distance = "parttree" ]; then
+                                       mv pre infile
+                                       "$prefix/splittbfast" -Z -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre 2>/dev/null || exit 1
+                               else
+                                       "$prefix/tbfast" -O $outnum -C $numthreads $rnaopt $weightopt $treeoutopt $distoutopt $memopt $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft  $localparam $algopt -J $treealg $scoreoutarg < pre > /dev/null 2>&1 || exit 1
+                               fi
+                               cycle=`expr $cycle - 1`
+                       done
+                       if [ $iterate -gt 0 ]; then
+                               if [ $distance = "sixtuples" ]; then
+                                   "$prefix/dndpre" -C $numthreads < pre     > /dev/null 2>&1 || exit 1
+                               fi
+                               "$prefix/dvtditr" -C $numthreads -t $randomseed $rnaoptit $memopt $scorecalcopt $localparam -z 50 $seqtype $model -f "-"$gop -h "-"$aof  -I $iterate $weightopt $treeinopt $algoptit $treealg -p $parallelizationstrategy  $scoreoutarg < pre     > /dev/null 2>&1 || exit 1
+                       fi
+               else
+
+                       if [ $anysymbol -eq 1 ]; then
+                               mv infile orig
+                               "$prefix/replaceu" -i orig > infile || exit 1
+                       fi
+
+                       if [ $seed != "x" ]; then
+                               mv infile infile2
+                               if [ $anysymbol -eq 1 ]; then
+                                       mv orig orig2
+                                       cat /dev/null > orig
+                               fi
+                               cat /dev/null > infile
+                               cat /dev/null > hat3.seed
+                               seedoffset=0
+#                              echo "seednseq="$seednseq
+#                              echo "seedoffset="$seedoffset
+                               set $seednseq > /dev/null
+#                              echo $#
+                               while [ $# -gt 1 ]
+                               do
+                                       shift
+#                                      echo "num="$#
+
+                                       if [ $anysymbol -eq 1 ]; then
+                                               cat seed$# >> orig
+                                               "$prefix/replaceu" -i seed$# -o $seedoffset > clean || exit 1
+                                               mv clean seed$#
+                                       fi
+                                       "$prefix/multi2hat3s" -t $nseq -o $seedoffset -i seed$# >> infile || exit 1
+                                       cat hat3 >> hat3.seed
+#                                      echo "$1"
+                                       seedoffset=`expr $seedoffset + $1`
+#                                      echo "$1"
+#                                      echo "seedoffset="$seedoffset
+                               done;
+#                              echo "seedoffset="$seedoffset
+                               if [ $anysymbol -eq 1 ]; then
+                                       "$prefix/replaceu" -i orig2 -o $seedoffset >> infile || exit 1 # yarinaoshi
+                                       cat orig2 >> orig
+                               else
+                                       cat infile2 >> infile
+                               fi
+                       elif [ $seedtable != "x" ]; then
+                               cat _seedtablefile > hat3.seed
+                       else
+                               cat /dev/null > hat3.seed
+                       fi
+#                      cat hat3.seed
+
+                       if [ $mccaskill -eq 1 ]; then
+                               "$prefix/mccaskillwrap" -C $numthreads -d "$prefix" -i infile > hat4  || exit 1
+                       elif [ $contrafold -eq 1 ]; then
+                               "$prefix/contrafoldwrap" -d "$prefix" -i infile > hat4  || exit 1
+                       fi
+                       if [ $distance = "fasta" ]; then
+                               "$prefix/dndfast7" $swopt < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "blast" ]; then
+                               "$prefix/dndblast" < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "foldalignlocal" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $lexp -f $lgop -h $laof -H -d "$prefix" < infile > /dev/null || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "foldalignglobal" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads $seqtype $foldalignopt $model -g $pgexp -f $pggop  -h $pgaof -H -o -global -d "$prefix" < infile > /dev/null || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "slara" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -T -d "$prefix" < infile > /dev/null || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "lara" ]; then
+                               "$prefix/pairlocalalign" -C $numthreads -p $laraparams  $seqtype $model  -f $lgop  -B -d "$prefix" < infile > /dev/null || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "scarna" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -f $pggop  -s -d "$prefix" < infile > /dev/null   || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   $algopt $treealg $scoreoutarg < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "global" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof   -F  < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "local" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -L  < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "globalgenaf" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $pgexp -f $pggop  -h $pgaof -O $GGOP -E $GEXP -K  < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "localgenaf" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N  < infile > /dev/null     || exit 1
+                               cat hat3.seed hat3 > hatx
+                               mv hatx hat3
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "distonly" ]; then
+                               "$prefix/pairlocalalign"   -C $numthreads $seqtype $model -g $pgexp -f $pggop  -h $pgaof  -t < infile > /dev/null            || exit 1
+                               "$prefix/tbfast" $outnum $addarg -C $numthreads $rnaopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  $algopt $treealg $scoreoutarg < infile   > /dev/null || exit 1
+                       elif [ $distance = "parttree" ]; then
+                               "$prefix/splittbfast" -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile   > pre || exit 1
+                               mv hat3.seed hat3
+                       else
+                               "$prefix/disttbfast" -O $outnum $addarg -C $numthreads $memopt $weightopt $treeinopt $treeoutopt $distoutopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  $algopt $treealg $scoreoutarg < infile   > pre || exit 1
+                               mv hat3.seed hat3
+                       fi
+
+                       while [ $cycle -gt 1 ]
+                       do
+                               if [ $distance = "parttree" ]; then
+                                       mv pre infile
+                                       "$prefix/splittbfast" -Z -Q $splitopt $partorderopt $parttreeoutopt $memopt $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -p $partsize -s $groupsize $treealg -i infile  > pre || exit 1
+                               else
+                                       "$prefix/tbfast" -O $outnum -C $numthreads $rnaopt $weightopt $treeoutopt $distoutopt $memopt $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft $localparam $algopt -J $treealg $scoreoutarg < pre > /dev/null || exit 1
+                               fi
+                               cycle=`expr $cycle - 1`
+                       done
+                       if [ $iterate -gt 0 ]; then
+                               if [ $distance = "sixtuples" ]; then
+                               "$prefix/dndpre" -C $numthreads < pre     > /dev/null 2>&1 || exit 1
+                               fi
+                               "$prefix/dvtditr" -C $numthreads -t $randomseed $rnaoptit $memopt $scorecalcopt $localparam -z 50 $seqtype $model -f "-"$gop -h "-"$aof -I $iterate $weightopt $treeinopt $algoptit $treealg -p $parallelizationstrategy  $scoreoutarg < pre     > /dev/null || exit 1
+                       fi
+               fi
+
+               if [ $coreout -eq 1 ]; then
+                       "$prefix/setcore" -w $corewin -i $corethr $coreext < pre > pre2
+                       mv pre2 pre
+               elif [ $anysymbol -eq 1 ]; then
+                       "$prefix/restoreu" -a pre -i orig > restored || exit 1
+                       mv restored pre
+               fi
+
+               if [ $quiet -eq 0 ]; then
+                       echo '' 1>&2
+                       if [ $mccaskill -eq 1 ]; then
+                               echo "RNA base pairing probaility was calculated by the McCaskill algorithm (1)" 1>&2
+                               echo "implemented in Vienna RNA package (2) and MXSCARNA (3), and then" 1>&2
+                               echo "incorporated in the iterative alignment process (4)." 1>&2
+                               echo "(1) McCaskill, 1990, Biopolymers 29:1105-1119" 1>&2
+                               echo "(2) Hofacker et al., 2002, J. Mol. Biol. 319:3724-3732" 1>&2
+                               echo "(3) Tabei et al., 2008, BMC Bioinformatics 9:33" 1>&2
+                               echo "(4) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>&2
+                               echo "" 1>&2
+                       elif [ $contrafold -eq 1 ]; then
+                               echo "RNA base pairing probaility was calculated by the CONTRAfold algorithm (1)" 1>&2
+                               echo "and then incorporated in the iterative alignment process (4)." 1>&2
+                               echo "(1) Do et al., 2006, Bioinformatics 22:e90-98" 1>&2
+                               echo "(2) Katoh and Toh, 2008, BMC Bioinformatics 9:212" 1>&2
+                               echo "" 1>&2
+                       fi
+                       if [ $distance = "fasta" -o $partdist = "fasta" ]; then
+                               echo "Pairwise alignments were computed by FASTA" 1>&2
+                               echo "(Pearson & Lipman, 1988, PNAS 85:2444-2448)" 1>&2
+                       fi
+                       if [ $distance = "blast" ]; then
+                               echo "Pairwise alignments were computed by BLAST" 1>&2
+                               echo "(Altschul et al., 1997, NAR 25:3389-3402)" 1>&2
+                       fi
+                       if [ $distance = "scarna" ]; then
+                               echo "Pairwise alignments were computed by MXSCARNA" 1>&2
+                               echo "(Tabei et al., 2008, BMC Bioinformatics 9:33)." 1>&2
+                       fi
+                       if [ $distance = "lara" -o $distance = "slara" ]; then
+                               echo "Pairwise alignments were computed by LaRA" 1>&2
+                               echo "(Bauer et al., 2007, BMC Bioinformatics 8:271)." 1>&2
+                       fi
+                       if [ $distance = "foldalignlocal" ]; then
+                               echo "Pairwise alignments were computed by FOLDALIGN (local)" 1>&2
+                               echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>&2
+                       fi
+                       if [ $distance = "foldalignglobal" ]; then
+                               echo "Pairwise alignments were computed by FOLDALIGN (global)" 1>&2
+                               echo "(Havgaard et al., 2007, PLoS Computational Biology 3:e193)." 1>&2
+                       fi
+                       printf "\n" 1>&2
+                       echo 'Strategy:' 1>&2
+                       printf ' '$strategy 1>&2
+                       echo ' ('$performance')' 1>&2
+                       echo ' '$explanation 1>&2
+                       echo '' 1>&2
+                       echo "If unsure which option to use, try 'mafft --auto input > output'." 1>&2
+#                      echo "If long gaps are expected, try 'mafft --ep 0.0 --auto input > output'." 1>&2
+                       echo "If the possibility of long gaps can be excluded, add '--ep 0.123'." 1>&2
+                       echo "For more information, see 'mafft --help', 'mafft --man' and the mafft page." 1>&2
+                       echo '' 1>&2
+               fi
+       )
+
+       if [ "$outputfile" = "" ]; then
+               if [ "$outputopt" = "null" ]; then
+                       cat < $TMPFILE/pre || exit 1
+               else
+                       "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre || exit 1
+               fi
+       else
+               if [ "$outputopt" = "null" ]; then
+                       cat < $TMPFILE/pre > "$outputfile" || exit 1
+               else
+                       "$prefix/f2cl" -n $namelength $outputopt < $TMPFILE/pre > "$outputfile" || exit 1
+               fi
+       fi
+
+       if [ $treeout -eq 1 ]; then
+               cp $TMPFILE/infile.tree "$infilename.tree"
+       fi
+
+       if [ $distout -eq 1 ]; then
+               cp $TMPFILE/hat2 "$infilename.hat2"
+       fi
+
+       exit 0;
+fi
+
+prog="awk"
+
+tmpawk=`which nawk 2>/dev/null | awk '{print $1}'`
+if [ -x "$tmpawk" ]; then
+       prog="$tmpawk"
+fi
+
+tmpawk=`which gawk 2>/dev/null | awk '{print $1}'`
+if [ -x "$tmpawk" ]; then
+       prog="$tmpawk"
+fi
+
+#echo "prog="$prog 1>&2
+
+umask 077
+(
+$prog '
+BEGIN {
+       prefix = ENVIRON["prefix"];
+       version = ENVIRON["version"];
+       myself = ENVIRON["myself"];
+       while( 1 )
+       {
+               options = ""
+               printf( "\n" ) > "/dev/tty";
+               printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
+               printf( "\n" )                                                                           > "/dev/tty";
+               printf( "   MAFFT %s\n", version )                                                       > "/dev/tty";
+               printf( "\n" )                                                                           > "/dev/tty";
+               printf( "        Copyright (c) 2011 Kazutaka Katoh\n" )                                  > "/dev/tty";
+               printf( "        NAR 30:3059-3066, NAR 33:511-518\n" )                                   > "/dev/tty";
+               printf( "        http://mafft.cbrc.jp/alignment/software/\n" )       > "/dev/tty";
+               printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
+               printf( "\n" ) > "/dev/tty";
+       
+               while( 1 )
+               {
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Input file? (fasta format)\n@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" )
+                       if( res == 0 || NF == 0 )
+                               continue;
+                       infile = sprintf( "%s", $0 );
+       
+                       res = getline < infile;
+                       close( infile );
+                       if( res == -1 )
+                       {
+                               printf( "%s: No such file.\n\n", infile ) > "/dev/tty";
+                               printf( "Filename extension (eg., .txt) must be typed, if any.\n\n" ) > "/dev/tty";
+                       }
+                       else if( res == 0 )
+                               printf( "%s: Empty.\n", infile ) > "/dev/tty";
+                       else
+                       {
+                               printf( "OK. infile = %s\n\n", infile ) > "/dev/tty";
+                               break;
+                       }
+               }
+               nseq = 0;
+       
+               while( 1 )
+               {
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Output file?\n" ) > "/dev/tty";
+                       printf( "@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 || NF == 0 )
+                               continue;
+                       else
+                       {
+                               outfile = sprintf( "%s", $0 );
+                               printf( "OK. outfile = %s\n\n", outfile ) > "/dev/tty";
+                               break;
+                       }
+               }
+       
+               while( 1 )
+               {
+                       outargs = "";
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Output format?\n" ) > "/dev/tty";
+                       printf( "  1. Clustal format / Sorted\n" ) > "/dev/tty";
+                       printf( "  2. Clustal format / Input order\n" ) > "/dev/tty";
+                       printf( "  3. Fasta format   / Sorted\n" ) > "/dev/tty";
+                       printf( "  4. Fasta format   / Input order\n" ) > "/dev/tty";
+                       printf( "  5. Phylip format  / Sorted\n" ) > "/dev/tty";
+                       printf( "  6. Phylip format  / Input order\n" ) > "/dev/tty";
+                       printf( "@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+#                      printf( "res=%d, NF=%d\n", res, NF );
+
+                       resnum = 0 + $1;
+#                      printf( "resnum=%d\n", resnum );
+
+                       if( resnum < 1 || 6 < resnum )
+                               continue;
+                       else
+                       {
+                               if( resnum == 1 )
+                                       outargs = "--clustalout --reorder";
+                               else if( resnum == 2 )
+                                       outargs = "--clustalout --inputorder";
+                               else if( resnum == 3 )
+                                       outargs = "--reorder";
+                               else if( resnum == 4 )
+                                       outargs = "--inputorder";
+                               else if( resnum == 5 )
+                                       outargs = "--phylipout --reorder";
+                               else if( resnum == 6 )
+                                       outargs = "--phylipout --inputorder";
+                               else
+                                       continue;
+                               printf( "OK. arguments = %s\n\n", outargs ) > "/dev/tty";
+                               break;
+                       }
+               }
+       
+               while( 1 )
+               {
+                       arguments = "";
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Strategy?\n" ) > "/dev/tty";
+                       printf( "  1. --auto\n" ) > "/dev/tty";
+                       printf( "  2. FFT-NS-1 (fast)\n" ) > "/dev/tty";
+                       printf( "  3. FFT-NS-2 (default)\n" ) > "/dev/tty";
+                       printf( "  4. G-INS-i  (accurate)\n" ) > "/dev/tty";
+                       printf( "  5. L-INS-i  (accurate)\n" ) > "/dev/tty";
+                       printf( "  6. E-INS-i  (accurate)\n" ) > "/dev/tty";
+                       printf( "@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+#                      printf( "res=%d, NF=%d\n", res, NF );
+
+                       resnum = 0 + $1;
+#                      printf( "resnum=%d\n", resnum );
+
+                       if( resnum < 1 || 6 < resnum )
+                               continue;
+                       else
+                       {
+                               if( resnum == 1 )
+                                       arguments = "--auto";
+                               else if( resnum == 2 )
+                                       arguments = "--retree 1";
+                               else if( resnum == 3 )
+                                       arguments = "--retree 2";
+                               else if( resnum == 4 )
+                                       arguments = "--globalpair --maxiterate 16";
+                               else if( resnum == 5 )
+                                       arguments = "--localpair  --maxiterate 16";
+                               else if( resnum == 6 )
+                                       arguments = "--genafpair  --maxiterate 16";
+                               else
+                                       arguments = sprintf( "%s", $0 );
+                               printf( "OK. arguments = %s %s\n\n", arguments, outargs ) > "/dev/tty";
+                               break;
+                       }
+               }
+
+
+               while( 1 )
+               {
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Additional arguments? (--ep #, --op #, --kappa #, etc)\n" ) > "/dev/tty";
+                       printf( "@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 || NF == 0 )
+                       {
+                               break;
+                       }
+                       else
+                       {
+                               addargs = sprintf( "%s", $0 );
+                               printf( "OK. arguments = %s %s %s\n\n", addargs, arguments, outargs ) > "/dev/tty";
+                               break;
+                       }
+               }
+
+               arguments = sprintf( "%s %s %s", addargs, arguments, outargs );
+
+               print ""
+               command = sprintf( "\"%s\" %s \"%s\" > \"%s\"", myself, arguments, infile, outfile );
+               gsub( /\\/, "/", command );
+
+
+               printf( "command=\n%s\n", command ) > "/dev/tty";
+       
+       
+               while( 1 )
+               {
+                       go = 0;
+                       printf( "OK?\n" ) > "/dev/tty";
+                       printf( "@ [Y] " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 || $0 ~ /^[Yy]/ )
+                       {
+                               go=1;
+                               break;
+                       }
+                       else
+                               break;
+               }
+               if( go ) break;
+               printf( "\n" ) > "/dev/tty";
+               printf( "\n" ) > "/dev/tty";
+       }
+       system( command );
+       command = sprintf( "less \"%s\"", outfile );
+       system( command );
+       printf( "Press Enter to exit." ) > "/dev/tty";
+       res = getline < "/dev/tty";
+}
+'
+)
+exit 0;
diff --git a/binaries/src/mafft/core/mafft.tmpl.subopt b/binaries/src/mafft/core/mafft.tmpl.subopt
new file mode 100644 (file)
index 0000000..9096897
--- /dev/null
@@ -0,0 +1,788 @@
+#! /bin/sh
+er=0;
+myself=`dirname $0`/`basename $0`; export myself
+version="version 6.00 (2005/05/01)"; export version
+LANG=C; export LANG
+os=`uname`
+progname=`basename $0`
+if [ `echo $os | grep -i cygwin` ]; then
+       os="cygwin"
+elif [ `echo $os | grep -i darwin` ]; then
+       os="darwin"
+elif [ `echo $os | grep -i sunos` ]; then
+       os="sunos"
+else
+       os="unix"
+fi
+export os
+
+if [ $MAFFT_BINARIES ]; then
+       prefix=$MAFFT_BINARIES
+else
+       prefix=_PREFIX
+fi
+export prefix
+if [ ! -x $prefix/tbfast ]; then
+       echo ""
+       echo "correctly installed?" 2>&1
+       echo "mafft binaries have to be installed in" $prefix.
+       echo ""
+       exit 1
+       er=1
+fi
+
+defaultiterate=0
+defaultcycle=2
+defaultmodel=" -b 62 "
+defaultgop="1.53"
+defaultaof="0.123"
+defaultfft=1
+defaultrough=0
+defaultdistance="sixtuples"
+if [ $progname = "linsi" ]; then
+       defaultfft=0
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="local"
+elif [ $progname = "ginsi" ]; then
+       defaultfft=1
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="global"
+elif [ $progname = "einsi" ]; then
+       defaultfft=0
+       defaultcycle=1
+       defaultiterate=1000
+       defaultdistance="genaf"
+elif [ $progname = "fftns" ]; then
+       defaultfft=1
+       defaultcycle=2
+elif [ $progname = "fftnsi" ]; then
+       defaultfft=1
+       defaultcycle=2
+       defaultiterate=2
+elif [ $progname = "nwns" ]; then
+       defaultfft=0
+       defaultcycle=2
+elif [ $progname = "nwnsi" ]; then
+       defaultfft=0
+       defaultcycle=2
+       defaultiterate=2
+fi
+model=$defaultmodel
+gop=$defaultgop
+aof=$defaultaof
+cycle=$defaultcycle
+iterate=$defaultiterate
+fft=$defaultfft
+rough=$defaultrough
+distance=$defaultdistance
+LGOP="-6.00"
+LEXP="-0.000"
+lgop="-2.00"
+lexp="-0.100"
+laof="0.100"
+seqtype="  "
+param_it=" -x "
+weighti="2.7"
+quiet=0
+sw=0
+scorecalcopt=" "
+coreout=0
+corethr="0.5"
+corewin="100"
+coreext=" "
+outputformat="pir"
+outorder="input"
+if [ $# -gt 0 ]; then
+       while [ $# -gt 1 ];
+       do
+               if [ $1 = "--clustalout" ]; then 
+                       outputformat="clustal"
+               elif [ $1 = "--reorder" ]; then 
+                       outorder="aligned"
+               elif [ $1 = "--rough" ]; then 
+                       rough=1
+               elif [ $1 = "--noscore" ]; then
+                       scorecalcopt=" -Z "
+               elif [ $1 = "--fastswpair" ]; then
+                       distance="fasta"
+                       sw=1
+               elif [ $1 = "--fastapair" ]; then
+                       distance="fasta"
+                       sw=0
+               elif [ $1 = "--suboptpair" ]; then
+                       distance="subopt"
+               elif [ $1 = "--blastpair" ]; then
+                       distance="blast"
+               elif [ $1 = "--globalpair" ]; then
+                       distance="global"
+               elif [ $1 = "--localpair" ]; then
+                       distance="local"
+               elif [ $1 = "--genafpair" ]; then
+                       distance="genaf"
+               elif [ $1 = "--nuc" ]; then 
+                       seqtype=" -D "
+               elif [ $1 = "--amino" ]; then 
+                       seqtype=" -P "
+               elif [ $1 = "--fft" ]; then 
+                       fft=1
+               elif [ $1 = "--nofft" ]; then 
+                       fft=0
+               elif [ $1 = "--quiet" ]; then 
+                       quiet=1
+               elif [ $1 = "--nj" ]; then 
+                       param_it=" -n "
+               elif [ $1 = "--coreext" ]; then 
+                       coreext=" -c "
+               elif [ $1 = "--core" ]; then 
+                       coreout=1
+               elif [ $1 = "--maxiterate" ]; then 
+                       shift   
+                       iterate=`expr $1 - 0`
+               elif [ $1 = "--retree" ]; then 
+                       shift   
+                       cycle=`expr $1 - 0`          || er=1
+               elif [ $1 = "--jtt" ]; then 
+                       shift   
+                       model=" -j "$1
+               elif [ $1 = "--tm" ]; then 
+                       shift   
+                       model=" -m "$1
+               elif [ $1 = "--bl" ]; then 
+                       shift   
+                       model=" -b "$1
+               elif [ $1 = "--weighti" ]; then
+                       shift   
+                       weighti=$1
+               elif [ $1 = "--op" ]; then 
+                       shift   
+                       gop=$1
+               elif [ $1 = "--ep" ]; then 
+                       shift   
+                       aof=$1
+               elif [ $1 = "--lop" ]; then 
+                       shift   
+                       lgop=$1
+               elif [ $1 = "--LOP" ]; then 
+                       shift   
+                       LGOP=$1
+               elif [ $1 = "--lep" ]; then 
+                       shift   
+                       laof=$1
+               elif [ $1 = "--lexp" ]; then 
+                       shift   
+                       lexp=$1
+               elif [ $1 = "--LEXP" ]; then 
+                       shift   
+                       LEXP=$1
+               elif [ $1 = "--corethr" ]; then 
+                       shift   
+                       corethr=$1
+               elif [ $1 = "--corewin" ]; then 
+                       shift   
+                       corewin=$1
+               elif [ $1 -gt 0 -a $progname = "fftns" -o $1 -gt 0 -a $progname = "nwns" ]; then
+                       cycle=`expr $1 - 0`
+               else
+                       echo "Unknown option: " $1 2>&1
+                       er=1;
+               fi
+               shift   
+       done;
+       if [ $fft -eq 1 ]; then
+               param_fft=" -F "
+       else
+               param_fft=" "
+       fi
+       if [ $sw -eq 1 ]; then
+               swopt=" -A "
+       else
+               swopt=" "
+       fi
+
+       if [ $distance = "fasta" ]; then
+               if [ ! $FASTA_4_MAFFT ]; then
+                       FASTA_4_MAFFT=`which fasta34`
+               fi
+
+               if [ ! -x $FASTA_4_MAFFT ]; then
+                       echo ""
+                       echo "== Install FASTA ========================================================"
+                       echo "This option requires the fasta34 program (FASTA version x.xx or higher)"
+                       echo "installed in your PATH.  If you have the fasta34 program but have renamed"
+                       echo "(like /usr/local/bin/myfasta), set the FASTA_4_MAFFT environment variable"
+                       echo "to point your fasta34 (like setenv FASTA_4_MAFFT /usr/local/bin/myfasta)."
+                       echo "========================================================================="
+                       echo ""
+                       exit
+               fi
+       fi
+       if [ $distance = "sixtuples" ]; then
+               localparam=" "
+       else
+               cycle=1
+               localparam=" -l "$weighti
+       fi
+
+       if [ $distance = "fasta" -a $sw -eq 0 ]; then
+               strategy="F-I"
+       elif [ $distance = "fasta" -a $sw -eq 1 ]; then
+               strategy="H-I"
+       elif [ $distance = "subopt" ]; then
+               strategy="S-I"
+       elif [ $distance = "blast" ]; then
+               strategy="B-I"
+       elif [ $distance = "global" ]; then
+               strategy="G-I"
+       elif [ $distance = "local" ]; then
+               strategy="L-I"
+       elif [ $distance = "genaf" ]; then
+               strategy="E-I"
+       elif [ $fft -eq 1 ]; then
+               strategy="FFT-"
+       else
+               strategy="NW-"
+       fi
+       strategy=$strategy"NS-"
+       if [ $iterate -gt 0 ]; then
+               strategy=$strategy"i"
+       elif [ $rough -eq 1 ]; then
+               strategy=$strategy"ROUGH"
+       else
+               strategy=$strategy$cycle
+       fi
+
+       explanation='?'
+       performance='Not tested.'
+       if [ $strategy = "F-INS-i" ]; then
+               explanation='Iterative refinement method incorporating LOCAL pairwise alignment information'
+               performance='Most accurate, but very slow'
+       elif [ $strategy = "L-INS-i" ]; then
+               explanation='Iterative refinement method incorporating LOCAL pairwise alignment information'
+               performance='Probably most accurate, very slow'
+       elif [ $strategy = "E-INS-i" ]; then
+               explanation='Iterative refinement method incorporating LOCAL pairwise alignment with generalized affine gap costs (Altshul 1998)'
+               performance='Suitable for sequences with long unalignable regions, very slow'
+       elif [ $strategy = "G-INS-i" ]; then
+               explanation='Iterative refinement method incorporating GLOBAL pairwise alignment information'
+               performance='Suitable for sequences of similar lengths, very slow'
+       elif [ $strategy = "F-INS-1" ]; then
+               explanation='Progressive method incorporating LOCAL pairwise alignment information'
+       elif [ $strategy = "L-INS-1" ]; then
+               explanation='Progressive method incorporating LOCAL pairwise alignment information'
+       elif [ $strategy = "G-INS-1" ]; then
+               explanation='Progressive method incorporating GLOBAL pairwise alignment information'
+       elif [ $strategy = "FFT-NS-i" -o $strategy = "NW-NS-i" ]; then
+               explanation='Iterative refinement method (max. '$iterate' iterations)'
+               if [ $iterate -gt 2 ]; then
+                       performance='Accurate but slow'
+               else
+                       performance='Standard'
+               fi
+       elif [ $strategy = "FFT-NS-2" -o $strategy = "NW-NS-2" ]; then
+               explanation='Progressive method (guide trees were built '$cycle' times.)'
+               performance='Fast but rough'
+       elif [ $strategy = "FFT-NS-1" -o $strategy = "NW-NS-1" ]; then
+               explanation='Progressive method (rough guide tree was used.)'
+               performance='Very fast but very rough'
+       fi
+
+       if [ $outputformat = "clustal" -a $outorder = "aligned" ]; then
+               outputcommand="$prefix/f2cl -c $strategy -r order  "
+       elif [ $outputformat = "clustal" -a $outorder = "input" ]; then
+               outputcommand="$prefix/f2cl -c $strategy  "
+       elif [ $outputformat = "pir" -a $outorder = "aligned" ]; then
+               outputcommand="$prefix/f2cl -f -r order "
+       else
+               outputcommand=" cat "
+       fi
+
+       TMPFILE=/tmp/`basename $0`.`whoami`.$$.`date +%y%m%d%H%M%S`
+       TMPFILE=/tmp/$progname.$$
+       umask 077
+       mkdir  $TMPFILE  || er=1
+       trap "rm -r $TMPFILE " 0
+       if [ $# -eq 1 ]; then
+               if [ -s "$1" -o "$1" = - ]; then
+                       cat "$1" | tr "\r" "\n" > $TMPFILE/infile 
+               else
+                       echo "Cannot open $1." 2>&1
+                       er=1
+               fi
+       else
+               echo '$#'"=$#" 2>&1
+               er=1
+       fi
+       
+
+       if [ $er -eq 1 ]; then
+               echo "" 2>&1
+               echo "MAFFT" $version 2>&1
+               echo ""  2>&1
+               echo "    References: " 2>&1
+               echo "      Katoh et al., 2002, NAR 30: 3059-3066" 2>&1
+               echo "      Katoh et al., 2005, NAR 33: 511-518" 2>&1
+           echo "      http://www.biophys.kyoto-u.ac.jp/~katoh/programs/align/mafft" 2>&1
+               echo "" 2>&1
+#              echo "Usage: `basename $0` [options] inputfile > outputfile" 2>&1
+               echo "    Options: " 2>&1
+               echo "      --globalpair :      All pairwise global alignment information is included."  2>&1
+               echo "                          default: off"  2>&1
+               echo "      --localpair :       All pairwise local alignment information is included."  2>&1
+               echo "                          default: off"  2>&1
+               echo "      --op # :            Gap opening penalty (>0). default: $defaultgop " 2>&1
+               echo "      --ep # :            Offset (>0, works like gap extension penalty). " 2>&1
+               echo "                          default: $defaultaof " 2>&1
+               echo "      --bl #, --jtt # :   Scoring matrix. default: BLOSUM62" 2>&1
+               echo "                          Alternatives are BLOSUM (--bl) 30, 45, 62, 80, " 2>&1
+               echo "                          or JTT (--jtt) # PAM. " 2>&1
+               echo "      --nuc or --amino :  Sequence type. default: auto" 2>&1
+               echo "      --retree # :        The number of tree building in progressive method " 2>&1
+               echo "                          (see the paper for detail). default: $defaultcycle " 2>&1
+               echo "      --maxiterate # :    Maximum number of iterative refinement. default: $defaultiterate " 2>&1
+               echo "      --nj :              Tree dependent iterative refinement is performed" 2>&1
+               echo "                          on an NJ tree. default: UPG tree" 2>&1
+               if [ $defaultfft -eq 1 ]; then
+                       echo "      --fft or --nofft:   FFT is enabled or disabled. default: enabled" 2>&1
+               else
+                       echo "      --fft or --nofft:   FFT is enabled or disabled. default: disabled" 2>&1
+               fi
+#              if [ $defaultrough -eq 1 ]; then 
+#                      echo "      --rough :           Rough alignment, for >1,000 sequences. default: enabled" 2>&1
+#              else
+#                      echo "      --rough :           Rough alignment, for >1,000 sequences. default: disabled" 2>&1
+#              i
+               echo "      --clustalout:       Output: clustal format (not tested). default: fasta" 2>&1
+               echo "      --reorder:          Outorder: aligned (not tested). default: input order" 2>&1
+               echo "      --quiet :           Do not report progress." 2>&1
+               echo ""  2>&1
+               echo "    Input format: fasta format" 2>&1
+               echo ""  2>&1
+               echo "    Typical usages:" 2>&1
+               echo "      % mafft --maxiterate 1000 --localpair input > output" 2>&1
+               echo "           L-INS-i (most accurate and very slow, iterative refinement" 2>&1
+               echo "           method incorporating LOCAL alignment information)" 2>&1
+               echo "" 2>&1
+               echo "      % mafft --maxiterate 1000 --globalpair input > output" 2>&1
+               echo "           G-INS-i (slightly less accurate than L-INS-i and very slow," 2>&1
+               echo "           iterative refinement method incorporating GLOBAL alignment" 2>&1
+               echo "           information, suitable for sequences of similar lengths) " 2>&1
+               echo "" 2>&1
+               echo "      % mafft --maxiterate 1000 input > output" 2>&1
+               echo "           FFT-NS-i (accurate and slow, iterative refinement method)" 2>&1
+               echo "" 2>&1
+               echo "      % mafft --retree 2 input > output (DEFAULT; same as mafft input > output)" 2>&1
+               echo "           FFT-NS-2 (rough and fast, default, progressive method)" 2>&1
+               echo "" 2>&1
+               echo "      % mafft --retree 1 input > output" 2>&1
+               echo "           FFT-NS-1 (very rough and very fast, progressive method with" 2>&1
+               echo "           a rough guide tree)" 2>&1
+               echo "" 2>&1
+               exit 1; 
+       fi
+       
+       (
+       cd $TMPFILE;
+       if [ $rough -gt 0 ]; then
+               $prefix/splitseq infile 500
+               for spfile in sp-[0-9]*[0-9]
+               do
+                       echo $spfile  > /dev/tty
+                       nseq=`grep -c '^[>|=]' $spfile`
+                       echo $nseq  > /dev/tty
+                       if [ $nseq -eq 1 ]; then
+                               cp $spfile $spfile.aln
+                       else
+                               $prefix/sextet5 $seqtype < $spfile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  -Ax < $spfile  > /dev/null  2>&1 || exit 1
+                               cat pre > $spfile.aln
+                       fi
+               done
+               ngroup=0
+               for alfile in sp-[0-9]*[0-9].aln
+               do
+                       ngroup=`expr $ngroup + 1`
+                       echo $alfile > /dev/tty
+                       if [ $ngroup -eq 1 ]; then
+                               cp $alfile alall
+                       else
+                               $prefix/galn -A alall $alfile > altmp
+                               mv altmp alall
+                       fi
+               done
+               cat alall
+       else
+               if [ $quiet -gt 0 ]; then
+                       if [ $distance = "subopt" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -S < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "fasta" ]; then
+                               $prefix/dndfast7 $swopt < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "blast" ]; then
+                               $prefix/dndblast < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "global" ]; then
+                               $prefix/pairlocalalign   $seqtype $model -f "-"$gop  -h "-"$aof  -F < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "local" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -L < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       elif [ $distance = "genaf" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N < infile > /dev/null  2>&1      || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null 2>&1 || exit 1
+                       else
+                               $prefix/disttbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft -Ax < infile   > pre 2>/dev/null || exit 1
+                       fi
+                       while [ $cycle -gt 1 ]
+                       do
+                               $prefix/tbfast $seqtype $model  -f "-"$gop  -h "-"$aof  $param_fft   -JAx < pre > /dev/null 2>&1 || exit 1
+                               cycle=`expr $cycle - 1`
+                       done
+                       if [ $iterate -gt 0 ]; then
+                               if [ $distance == "sixtuples" ]; then
+                                   $prefix/dndpre       < pre     > /dev/null 2>&1 || exit 1
+                               fi
+                               $prefix/dvtditr $scorecalcopt $localparam -F -z 50 $seqtype $model -f "-"$gop -h "-"$aof -A -c -I $iterate $param_it < pre     > /dev/null 2>&1 || exit 1
+                       fi
+               else
+                       if [ $distance = "subopt" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -S < infile > /dev/null  || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam   -Ax < infile   > /dev/null || exit 1
+                       elif [ $distance = "fasta" ]; then
+                               $prefix/dndfast7 $swopt < infile > /dev/null     || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
+                       elif [ $distance = "blast" ]; then
+                               $prefix/dndblast < infile > /dev/null     || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
+                       elif [ $distance = "global" ]; then
+                               $prefix/pairlocalalign   $seqtype $model -f "-"$gop  -h "-"$aof -F  < infile > /dev/null     || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
+                       elif [ $distance = "local" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -L  < infile > /dev/null     || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
+                       elif [ $distance = "genaf" ]; then
+                               $prefix/pairlocalalign   $seqtype -b 62  -g $lexp -f $lgop  -h $laof -O $LGOP -E $LEXP -N  < infile > /dev/null     || exit 1
+                               $prefix/tbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft $localparam  -Ax < infile   > /dev/null || exit 1
+                       else
+                               $prefix/disttbfast $seqtype $model -f "-"$gop  -h "-"$aof  $param_fft  -Ax < infile   > pre || exit 1
+                       fi
+                       while [ $cycle -gt 1 ]
+                       do
+                               $prefix/tbfast $seqtype $model  -f "-"$gop  -h "-"$aof $param_fft  -JAx < pre > /dev/null || exit 1
+                               cycle=`expr $cycle - 1`
+                       done
+                       if [ $iterate -gt 0 ]; then
+                               if [ $distance = "sixtuples" ]; then
+                               $prefix/dndpre       < pre     > /dev/null 2>&1 || exit 1
+                               fi
+                               $prefix/dvtditr $scorecalcopt $localparam -F -z 50 $seqtype $model -f "-"$gop -h "-"$aof -A -c -I $iterate $param_it < pre     > /dev/null || exit 1
+                       fi
+               fi
+#              cat  < pre             || exit 1
+               if [ $coreout -eq 0 ]; then
+                       $outputcommand < pre   || exit 1
+               else
+                       $prefix/setcore -w $corewin -i $corethr $coreext < pre > pre2
+                       $outputcommand < pre2 || exit 1
+               fi
+       fi
+       )
+       echo '' >/dev/tty
+       if [ $distance = "fasta" ]; then
+               echo "Pairwise alignments were computed by FASTA" >/dev/tty
+               echo "(Pearson & Lipman, 1988, PNAS 85:2444-2448)" >/dev/tty
+       fi
+       if [ $distance = "blast" ]; then
+               echo "Pairwise alignments were computed by BLAST">/dev/tty
+               echo "(Altschul et al., 1997, NAR 25:3389-3402)">/dev/tty
+       fi
+       printf "\n" >/dev/tty
+       echo 'Strategy:' >/dev/tty
+       printf ' '$strategy >/dev/tty
+       echo ' ('$performance')' >/dev/tty
+       echo ' '$explanation >/dev/tty
+       echo '' >/dev/tty
+       echo "Type '$0 --help' for other options." >/dev/tty
+       echo '' >/dev/tty
+       exit 0;
+fi
+
+prog="awk"
+
+if [ $os != "darwin" ]; then
+       echo "checking nawk"
+       tmpawk=`which nawk 2>/dev/null | awk '{print $1}'`
+       if [ -x $tmpawk ]; then
+               prog=$tmpawk
+       fi
+
+       echo "checking gawk"
+       tmpawk=`which gawk 2>/dev/null | awk '{print $1}'`
+       if [ -x $tmpawk ]; then
+               prog=$tmpawk
+       fi
+fi
+
+echo "prog="$prog
+
+umask 077
+export defaultaof
+export defaultgop
+export defaultfft
+export defaultcycle
+export defaultiterate
+(
+$prog '
+BEGIN {
+       prefix = ENVIRON["prefix"];
+       version = ENVIRON["version"];
+       myself = ENVIRON["myself"];
+       defaultgop = ENVIRON["defaultgop"]
+       defaultaof = ENVIRON["defaultaof"]
+       defaultfft = ENVIRON["defaultfft"]
+       defaultcycle = ENVIRON["defaultcycle"]
+       defaultiterate = ENVIRON["defaultiterate"]
+       while( 1 )
+       {
+               options = ""
+               printf( "\n" ) > "/dev/tty";
+               printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
+               printf( "\n" )                                                                           > "/dev/tty";
+               printf( "   MAFFT %s\n", version )                                                       > "/dev/tty";
+               printf( "\n" )                                                                           > "/dev/tty";
+               printf( "        K. Katoh, K. Misawa, K. Kuma and T. Miyata (2002)\n" )                  > "/dev/tty";
+               printf( "        Nucleic Acids Research 30: 3059-3066.\n" )                              > "/dev/tty";
+               printf( "        http://www.biophys.kyoto-u.ac.jp/~katoh/programs/align/mafft\n" )       > "/dev/tty";
+               printf( "---------------------------------------------------------------------\n" )      > "/dev/tty";
+               printf( "\n" );
+       
+               while( 1 )
+               {
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Input file? (fasta format)\n@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" )
+                       if( res == 0 || NF == 0 )
+                               continue;
+                       infile0 = sprintf( "%s", $1 );
+                       infile = sprintf( "%s", $1 );
+       
+                       res = getline < infile;
+                       close( infile );
+                       if( res == -1 )
+                               printf( "%s: No such file.\n\n", infile );
+                       else if( res == 0 )
+                               printf( "%s: Empty.\n", infile );
+                       else
+                       {
+                               printf( "OK. infile = %s\n\n", infile );
+                               break;
+                       }
+               }
+               nseq = 0;
+       
+               while( 1 )
+               {
+                       printf( "\n" ) > "/dev/tty";
+                       printf( "Output file?\n" ) > "/dev/tty";
+                       printf( "@ " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 || NF == 0 )
+                               continue;
+                       else
+                       {
+                               outfile = sprintf( "%s", $1 );
+                               printf( "OK. outfile = %s\n\n", outfile );
+                               break;
+                       }
+               }
+       
+       
+               while( 1 )
+               {
+                       retree = defaultcycle
+                       printf( "\n" );
+                       printf( "Number of tree-rebuilding?\n" ) > "/dev/tty";
+                       printf( "@ [%d] ", retree ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 )
+                               ;
+                       else
+                               retree = 0 + $1;
+                       if( retree < 1 || 10 < retree )
+                               ;
+                       else
+                       {
+                               printf( "OK. %d\n\n", retree );
+                               break;
+                       }
+               }
+       
+               while( 1 )
+               {
+                       niterate = defaultiterate;
+                       printf( "\n" );
+                       printf( "Maximum number of iterations?\n" ) > "/dev/tty";
+                       printf( "@ [%d] ", niterate ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 )
+                               ;
+                       else
+                               niterate = 0 + $1;
+                       if( niterate < 0 || 1000 < niterate )
+                               ;
+                       else
+                       {
+                               printf( "OK. %d\n\n", niterate );
+                               break;
+                       }
+               }
+
+               while( 1 )
+               {
+                       fft = defaultfft;
+                       printf( "\n" );
+                       printf( "Use fft?\n" ) > "/dev/tty";
+                       printf( "@ [%s] ", fft?"Yes":"No" ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 )
+                       {
+                               break;
+                       }
+                       else if( NF == 0 || $0 ~ /^[Yy]/ )
+                       {
+                               fft = 1;
+                               break;
+                       }
+                       else if( NF == 0 || $0 ~ /^[Nn]/ )
+                       {
+                               fft = 0;
+                               break;
+                       }
+               }
+               if( fft )
+               {
+                               printf( "OK. FFT is enabled.\n\n" );
+                               fftparam = " --fft ";
+               }
+               else
+               {
+                               printf( "OK. FFT is disabled.\n\n" );
+                               fftparam = " --nofft ";
+               }
+
+               while( 1 )
+               {
+                       scoringmatrix = 3;
+                       printf( "\n" );
+                       printf( "Scoring matrix? (ignored when DNA sequence is input.)\n" ) > "/dev/tty";
+                       printf( " 1. BLOSUM 30\n" ) > "/dev/tty";
+                       printf( " 2. BLOSUM 45\n" ) > "/dev/tty";
+                       printf( " 3. BLOSUM 62\n" ) > "/dev/tty";
+                       printf( " 4. BLOSUM 80\n" ) > "/dev/tty";
+                       printf( " 5. JTT 200\n" ) > "/dev/tty";
+                       printf( " 6. JTT 100\n" ) > "/dev/tty";
+                       printf( "@ [%d] ", scoringmatrix ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 )
+                               ;
+                       else
+                               scoringmatrix = 0 + $1;
+                       if( scoringmatrix < 1 || 6 < scoringmatrix )
+                               ;
+                       else
+                       {
+                               break;
+                       }
+               }
+               if( scoringmatrix == 1 )
+                       scoringparam = " --bl 30 ";
+               else if( scoringmatrix == 2 )
+                       scoringparam = " --bl 45 ";
+               else if( scoringmatrix == 3 )
+                       scoringparam = " --bl 62 ";
+               else if( scoringmatrix == 4 )
+                       scoringparam = " --bl 80 ";
+               else if( scoringmatrix == 5 )
+                       scoringparam = " --jtt 200 ";
+               else if( scoringmatrix == 6 )
+                       scoringparam = " --jtt 100 ";
+               printf( "OK. %s\n\n",scoringparam );
+       
+               while( 1 )
+               {
+                       penalty = 0.0 + defaultgop;
+                       offset = 0.0 + defaultaof;
+                       printf( "\n" );
+                       printf( "Parameters (gap opening penalty, offset)?\n", penalty, offset ) > "/dev/tty";
+                       printf( "@ [%5.3f, %5.3f] ", penalty, offset ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 2 )
+                       {
+                               penalty = 0.0 + $1;
+                               offset = 0.0 + $2;
+                       }
+                       else if( NF == 0 )
+                               ;
+                       else
+                               continue;
+                       if( penalty <= 0.0 || 10.0 < penalty )
+                               ;
+                       else if( offset <= 0.0 || 10.0 < offset )
+                               ;
+                       else
+                       {
+                               printf( "OK. %5.3f %5.3f\n\n", penalty, offset );
+                               break;
+                       }
+               }
+       
+               command = sprintf( "%s %s --retree %d --maxiterate %d %s --op %f --ep %f %s > %s", myself, fftparam, retree, niterate, scoringparam, penalty, offset, infile, outfile );
+               printf( "%s\n\n", command );
+       
+       
+               while( 1 )
+               {
+                       go = 0;
+                       printf( "\n" );
+                       printf( "OK?\n" );
+                       printf( "@ [Y] " ) > "/dev/tty";
+                       res = getline < "/dev/tty";
+                       close( "/dev/tty" );
+                       if( res == 0 )
+                               continue;
+                       else if( NF == 0 || $0 ~ /^[Yy]/ )
+                       {
+                               go=1;
+                               break;
+                       }
+                       else
+                               break;
+               }
+               if( go ) break;
+               printf( "\n" );
+               printf( "\n" );
+       }
+       system( command );
+}
+'
+)
+exit 0;
diff --git a/binaries/src/mafft/core/mccaskillwrap.c b/binaries/src/mafft/core/mccaskillwrap.c
new file mode 100644 (file)
index 0000000..a7ea4ea
--- /dev/null
@@ -0,0 +1,423 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+static char *whereismccaskillmea;
+
+#ifdef enablemultithread
+typedef struct _thread_arg
+{
+       int thread_no;
+       int njob;
+       int *jobpospt;
+       int **gapmap;
+       char **nogap;
+       int nlenmax;
+       RNApair ***pairprob;
+       pthread_mutex_t *mutex;
+} thread_arg_t;
+#endif
+
+void outmccaskill( FILE *fp, RNApair **pairprob, int length )
+{
+       int i;
+       RNApair *pt;
+       for( i=0; i<length; i++ ) for( pt=pairprob[i]; pt->bestpos!=-1; pt++ )
+       {
+               if( pt->bestpos > i ) 
+                       fprintf( fp, "%d %d %50.40f\n", i, pt->bestpos, pt->bestscore );
+       }
+}
+
+#if 1
+static void readrawmccaskill( FILE *fp, RNApair **pairprob, int length )
+{
+       char gett[1000];
+       int *pairnum;
+       int i;
+       int left, right;
+       float prob;
+
+       pairnum = (int *)calloc( length, sizeof( int ) );
+       for( i=0; i<length; i++ ) pairnum[i] = 0;
+
+       while( 1 )
+       {
+               fgets( gett, 999, fp );
+               if( feof( fp ) ) break;
+               if( gett[0] == '>' ) continue;
+               sscanf( gett, "%d %d %f", &left, &right, &prob );
+               if( prob < 0.01 ) continue; // mxscarna to mafft ryoho ni eikyou
+//fprintf( stderr, "gett = %s\n", gett );
+
+               if( left != right && prob > 0.0 )
+               {
+                       pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) );
+                       pairprob[left][pairnum[left]].bestscore = prob;
+                       pairprob[left][pairnum[left]].bestpos = right;
+                       pairnum[left]++;
+                       pairprob[left][pairnum[left]].bestscore = -1.0;
+                       pairprob[left][pairnum[left]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+
+                       pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) );
+                       pairprob[right][pairnum[right]].bestscore = prob;
+                       pairprob[right][pairnum[right]].bestpos = left;
+                       pairnum[right]++;
+                       pairprob[right][pairnum[right]].bestscore = -1.0;
+                       pairprob[right][pairnum[right]].bestpos = -1;
+//                     fprintf( stderr, "%d-%d, %f\n", right, left, prob );
+               }
+       }
+       free( pairnum );
+}
+#endif
+
+#ifdef enablemultithread
+static void *athread( void *arg )
+{
+       thread_arg_t *targ = (thread_arg_t *)arg;
+       int thread_no = targ->thread_no;
+       int njob = targ->njob;
+       int *jobpospt = targ->jobpospt;
+       int **gapmap = targ->gapmap;
+       char **nogap = targ->nogap;
+       int nlenmax = targ->nlenmax;
+       RNApair ***pairprob = targ->pairprob;
+
+       int i, res;
+       FILE *infp;
+       char *com;
+       char *dirname;
+
+       dirname = calloc( 100, sizeof( char ) );
+       com = calloc( 1000, sizeof( char ) );
+       
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               i = *jobpospt;
+               if( i == njob )
+               {
+                       pthread_mutex_unlock( targ->mutex );
+                       return( NULL );
+               }
+               *jobpospt = i+1;
+               pthread_mutex_unlock( targ->mutex );
+
+
+               sprintf( dirname, "_%d", i );
+               sprintf( com, "rm -rf %s", dirname );
+               system( com );
+               sprintf( com, "mkdir %s", dirname );
+               system( com );
+
+               fprintf( stderr, "%d / %d (by thread %4d)\n", i+1, njob, thread_no );
+               commongappick_record( 1, nogap+i, gapmap[i] );
+               sprintf( com, "%s/_mccaskillinorg", dirname );
+               infp = fopen( com, "w" );
+//             fprintf( infp, ">in\n%s\n", nogap[i] );
+               fprintf( infp, ">in\n" );
+               write1seq( infp, nogap[i] );
+               fclose( infp );
+
+               sprintf( com, "tr -d '\\r' < %s/_mccaskillinorg > %s/_mccaskillin", dirname, dirname );
+               system( com ); // for cygwin, wakaran
+               sprintf( com, "cd %s; %s/mxscarnamod -m -writebpp  _mccaskillin > _mccaskillout 2>_dum", dirname, whereismccaskillmea );
+               res = system( com );
+
+               if( res )
+               {
+                       fprintf( stderr, "ERROR IN mccaskill_mea\n" );
+                       exit( 1 );
+               }
+
+               sprintf( com, "%s/_mccaskillout", dirname );
+               infp = fopen( com, "r" );
+               readrawmccaskill( infp, pairprob[i], nlenmax );
+               fclose( infp );
+
+               sprintf( com, "rm -rf %s > /dev/null 2>&1", dirname );
+               if( system( com ) )
+               {
+                       fprintf( stderr, "retrying to rmdir\n" );
+//                     nanosleep( 100000 );
+                       sleep( 1 );
+                       system( com );
+               }
+       }
+       free( dirname );
+       free( com );
+}
+#endif
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+       nthread = 1;
+       inputfile = NULL;
+       dorp = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       whereismccaskillmea = NULL;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'd':
+                                       whereismccaskillmea = *++argv;
+                                       fprintf( stderr, "whereismccaskillmea = %s\n", whereismccaskillmea );
+                                       --argc;
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+int main( int argc, char *argv[] )
+{
+       static char com[10000];
+       static int  *nlen;      
+       int left, right;
+       int res;
+       static char **name, **seq, **nogap;
+       static int **gapmap;
+       static int *order;
+       int i, j;
+       FILE *infp;
+       RNApair ***pairprob;
+       RNApair **alnpairprob;
+       RNApair *pairprobpt;
+       RNApair *pt;
+       int *alnpairnum;
+       float prob;
+       int adpos;
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       if( !whereismccaskillmea )
+               whereismccaskillmea = "";
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( dorp != 'd' )
+       {
+               fprintf( stderr, "nuc only\n" );
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*2+1 );
+       nogap = AllocateCharMtx( njob, nlenmax*2+1 );
+       gapmap = AllocateIntMtx( njob, nlenmax*2+1 );
+       order = AllocateIntVec( njob );
+       name = AllocateCharMtx( njob, B+1 );
+       nlen = AllocateIntVec( njob );
+       pairprob = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       alnpairprob = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) );
+       alnpairnum = AllocateIntVec( nlenmax );
+
+       for( i=0; i<nlenmax; i++ ) alnpairnum[i] = 0;
+
+       readData_pointer( infp, name, nlen, seq );
+       fclose( infp );
+
+       for( i=0; i<njob; i++ )
+       {
+               pairprob[i] = (RNApair **)calloc( nlenmax, sizeof( RNApair * ) );
+               for( j=0; j<nlenmax; j++ )
+               {
+                       pairprob[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+                       pairprob[i][j][0].bestpos = -1;
+                       pairprob[i][j][0].bestscore = -1.0;
+               }
+               strcpy( nogap[i], seq[i] );
+               order[i] = i;
+       }
+       for( j=0; j<nlenmax; j++ )
+       {
+               alnpairprob[j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+               alnpairprob[j][0].bestpos = -1;
+               alnpairprob[j][0].bestscore = -1.0;
+       }
+
+
+       constants( njob, seq );
+
+       fprintf( stderr, "Running mxscarna with the mccaskill_mea mode.\n" );
+#ifdef enablemultithread
+       if( nthread > 0 )
+       {
+               int jobpos;
+               pthread_t *handle;
+               pthread_mutex_t mutex;
+               thread_arg_t *targ;
+               jobpos = 0;
+
+               targ = calloc( nthread, sizeof( thread_arg_t ) );
+               handle = calloc( nthread, sizeof( pthread_t ) );
+               pthread_mutex_init( &mutex, NULL );
+
+               for( i=0; i<nthread; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].njob = njob;
+                       targ[i].jobpospt = &jobpos;
+                       targ[i].gapmap = gapmap;
+                       targ[i].nogap = nogap;
+                       targ[i].nlenmax = nlenmax;
+                       targ[i].pairprob = pairprob;
+                       targ[i].mutex = &mutex;
+
+//                     athread( targ );
+                       pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
+                       
+               }
+
+               for( i=0; i<nthread; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+               pthread_mutex_destroy( &mutex );
+
+
+               for( i=0; i<njob; i++ )
+               {
+                       fprintf( stdout, ">%d\n", i );
+                       outmccaskill( stdout, pairprob[i], nlenmax );
+               }
+       }
+       else
+#endif
+       {
+               for( i=0; i<njob; i++ )
+               {
+                       fprintf( stderr, "%d / %d\n", i+1, njob );
+                       commongappick_record( 1, nogap+i, gapmap[i] );
+                       infp = fopen( "_mccaskillinorg", "w" );
+//                     fprintf( infp, ">in\n%s\n", nogap[i] );
+                       fprintf( infp, ">in\n" );
+                       write1seq( infp, nogap[i] );
+                       fclose( infp );
+       
+                       system( "tr -d '\\r' < _mccaskillinorg > _mccaskillin" ); // for cygwin, wakaran
+                       sprintf( com, "env PATH=%s mxscarnamod -m -writebpp  _mccaskillin > _mccaskillout 2>_dum", whereismccaskillmea );
+                       res = system( com );
+       
+                       if( res )
+                       {
+                               fprintf( stderr, "ERROR IN mccaskill_mea\n" );
+                               exit( 1 );
+                       }
+       
+                       infp = fopen( "_mccaskillout", "r" );
+                       readrawmccaskill( infp, pairprob[i], nlenmax );
+                       fclose( infp );
+                       fprintf( stdout, ">%d\n", i );
+                       outmccaskill( stdout, pairprob[i], nlenmax );
+               }
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               for( j=0; j<nlen[i]; j++ ) for( pairprobpt=pairprob[i][j]; pairprobpt->bestpos!=-1; pairprobpt++ )
+               {
+                       left = gapmap[i][j];
+                       right = gapmap[i][pairprobpt->bestpos];
+                       prob = pairprobpt->bestscore;
+
+                       for( pt=alnpairprob[left]; pt->bestpos!=-1; pt++ )
+                               if( pt->bestpos == right ) break;
+
+                       if( pt->bestpos == -1 )
+                       {
+                               alnpairprob[left] = (RNApair *)realloc( alnpairprob[left], (alnpairnum[left]+2) * sizeof( RNApair ) );
+                               adpos = alnpairnum[left];
+                               alnpairnum[left]++;
+                               alnpairprob[left][adpos].bestscore = 0.0;
+                               alnpairprob[left][adpos].bestpos = right;
+                               alnpairprob[left][adpos+1].bestscore = -1.0;
+                               alnpairprob[left][adpos+1].bestpos = -1;
+                               pt = alnpairprob[left]+adpos;
+                       }
+                       else
+                               adpos = pt-alnpairprob[left];
+
+                       pt->bestscore += prob;
+                       if( pt->bestpos != right )
+                       {
+                               fprintf( stderr, "okashii!\n" );
+                               exit( 1 );
+                       }
+//                     fprintf( stderr, "adding %d-%d, %f\n", left, right, prob );
+               }
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               for( j=0; j<nlenmax; j++ ) free( pairprob[i][j] );
+               free( pairprob[i] );
+       }
+       free( pairprob );
+       for( j=0; j<nlenmax; j++ ) free( alnpairprob[j] );
+       free( alnpairprob );
+       free( alnpairnum );
+       fprintf( stderr, "%d thread(s)\n", nthread );
+       return( 0 );
+
+#if 0
+       fprintf( stdout, "result=\n" );
+
+       for( i=0; i<nlenmax; i++ ) for( pairprobpt=alnpairprob[i]; pairprobpt->bestpos!=-1; pairprobpt++ )
+       {
+               pairprobpt->bestscore /= (float)njob;
+               left = i;
+               right = pairprobpt->bestpos;
+               prob = pairprobpt->bestscore;
+               fprintf( stdout, "%d-%d, %f\n", left, right, prob );
+       }
+
+       return( 0 );
+#endif
+}
diff --git a/binaries/src/mafft/core/mingw64mingw32 b/binaries/src/mafft/core/mingw64mingw32
new file mode 100644 (file)
index 0000000..6c8110a
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env bash
+make clean
+make
+rm -rf binaries32
+mkdir binaries32
+mv ../binaries/* binaries32/
+
+export PATH=/MinGW64/mingw-w64-1.0-bin_i686-mingw_20100702/bin:$PATH
+export C_INCLUDE_PATH=/MinGW64/mingw-w64-1.0-bin_i686-mingw_20100702/include
+export LIBRARY_PATH=/MinGW64/mingw-w64-1.0-bin_i686-mingw_20100702/lib
+make clean
+make
+rm -rf binaries64
+mkdir binaries64
+mv ../binaries/* binaries64/
diff --git a/binaries/src/mafft/core/miyata.h b/binaries/src/mafft/core/miyata.h
new file mode 100644 (file)
index 0000000..cddb624
--- /dev/null
@@ -0,0 +1,47 @@
+double polarity_[] =
+{
+        8.1,  /* A */
+       10.5,  /* R */
+       11.6,  /* N */
+       13.0,  /* D */
+        5.5,  /* C */
+       10.5,  /* Q */
+       12.3,  /* E */
+        9.0,  /* G */
+       10.4,  /* H */
+        5.2,  /* I */
+        4.9,  /* L */
+       11.3,  /* K */
+        5.7,  /* M */
+        5.2,  /* F */
+        8.0,  /* P */
+        9.2,  /* S */
+        8.6,  /* T */
+        5.4,  /* W */
+        6.2,  /* Y */
+        5.9,  /* V */
+};
+
+double volume_[] =
+{
+        31.0,  /* A */
+       124.0,  /* R */
+        56.0,  /* N */
+        54.0,  /* D */
+        55.0,  /* C */
+        85.0,  /* Q */
+        83.0,  /* E */
+         3.0,  /* G */
+        96.0,  /* H */
+       111.0,  /* I */
+       111.0,  /* L */
+       119.0,  /* K */
+       105.0,  /* M */
+       132.0,  /* F */
+        32.5,  /* P */
+        32.0,  /* S */
+        61.0,  /* T */
+       170.0,  /* W */
+       136.0,  /* Y */
+        84.0,  /* V */
+};
diff --git a/binaries/src/mafft/core/miyata5.h b/binaries/src/mafft/core/miyata5.h
new file mode 100644 (file)
index 0000000..3ddf2c0
--- /dev/null
@@ -0,0 +1,166 @@
+int locpenaltym = -1440;
+int exgpm = +0;  /* != 0 nisuruto kowareru. exgp ha constants.c de kurikomu */
+char locaminom[] = "ARNDCQEGHILKMFPSTWYVBZX.-J";
+char locgrpm[] = 
+{
+       0, 3, 2, 2, 5, 2, 2, 0, 3, 1, 1, 3, 1, 4, 0, 0, 0, 4, 4, 1, 2, 2,
+       6, 6, 6, 1,
+};
+int locn_dism[26][26] = 
+    {
+       {
+  600, -235,   91,  -78,  202,   51, -103,  340,  -21, -169,
+ -189, -246,  -92, -323,  582,  454,  342, -400, -309,   71,
+    7,  -26,  -15, -400,    0,-1400,
+       },
+
+       {
+ -235,  600,   17,  -69, -275,  277,  185, -400,  365, -112,
+ -149,  485,  -55, -106, -229, -183,   20, -178,   22,  -95,
+  -26,  231,  -15, -400,    0,-1400,
+       },
+
+       {
+   91,   17,  600,  414, -209,  317,  357,   39,  231, -363,
+ -398,   74, -280, -400,   85,  225,  200, -400, -378, -189,
+  507,  337,  -15, -400,    0,-1400,
+       },
+
+       {
+  -78,  -69,  414,  600, -395,  179,  342,  -78,  108, -400,
+ -400,   14, -400, -400,  -86,   65,   14, -400, -400, -372,
+  507,  261,  -15, -400,    0,-1400,
+       },
+
+       {
+  202, -275, -209, -395,  600, -109, -332,  -35, -132,  134,
+  128, -335,  182,  -40,  220,   74,  185, -355,  -81,  354,
+ -302, -220,  -15, -400,    0,-1400,
+       },
+
+       {
+   51,  277,  317,  179, -109,  600,  360, -109,  508, -135,
+ -172,  297,  -58, -203,   51,  128,  280, -378, -109,   -9,
+  248,  480,  -15, -400,    0,-1400,
+       },
+
+       {
+ -103,  185,  357,  342, -332,  360,  600, -195,  325, -369,
+ -400,  274, -295, -400, -109,   11,   77, -400, -321, -249,
+  350,  480,  -15, -400,    0,-1400,
+       },
+
+       {
+  340, -400,   39,  -78,  -35, -109, -195,  600, -195, -400,
+ -400, -400, -355, -400,  322,  357,  114, -400, -400, -189,
+  -19, -152,  -15, -400,    0,-1400,
+       },
+
+       {
+  -21,  365,  231,  108, -132,  508,  325, -195,  600, -100,
+ -141,  374,  -26, -152,  -15,   45,  222, -303,  -49,   -3,
+  169,  417,  -15, -400,    0,-1400,
+       },
+
+       {
+ -169, -112, -363, -400,  134, -135, -369, -400, -100,  600,
+  560, -212,  517,  425, -149, -243,  -12,  108,  354,  357,
+ -400, -252,  -15, -400,    0,-1400,
+       },
+
+       {
+ -189, -149, -398, -400,  128, -172, -400, -400, -141,  560,
+  600, -252,  482,  420, -172, -269,  -43,  105,  331,  340,
+ -400, -290,  -15, -400,    0,-1400,
+       },
+
+       {
+ -246,  485,   74,   14, -335,  297,  274, -400,  374, -212,
+ -252,  600, -152, -215, -240, -175,   -1, -289,  -92, -172,
+   44,  285,  -15, -400,    0,-1400,
+       },
+
+       {
+  -92,  -55, -280, -400,  182,  -58, -295, -355,  -26,  517,
+  482, -152,  600,  365,  -75, -163,   68,   59,  334,  422,
+ -368, -176,  -15, -400,    0,-1400,
+       },
+
+       {
+ -323, -106, -400, -400,  -40, -203, -400, -400, -152,  425,
+  420, -215,  365,  600, -306, -386, -143,  282,  462,  191,
+ -400, -315,  -15, -400,    0,-1400,
+       },
+
+       {
+  582, -229,   85,  -86,  220,   51, -109,  322,  -15, -149,
+ -172, -240,  -75, -306,  600,  440,  351, -400, -292,   88,
+    0,  -29,  -15, -400,    0,-1400,
+       },
+
+       {
+  454, -183,  225,   65,   74,  128,   11,  357,   45, -243,
+ -269, -175, -163, -386,  440,  600,  345, -400, -352,  -15,
+  145,   70,  -15, -400,    0,-1400,
+       },
+
+       {
+  342,   20,  200,   14,  185,  280,   77,  114,  222,  -12,
+  -43,   -1,   68, -143,  351,  345,  600, -400, -100,  194,
+  107,  178,  -15, -400,    0,-1400,
+       },
+
+       {
+ -400, -178, -400, -400, -355, -378, -400, -400, -303,  108,
+  105, -289,   59,  282, -400, -400, -400,  600,  297, -118,
+ -400, -400,  -15, -400,    0,-1400,
+       },
+
+       {
+ -309,   22, -378, -400,  -81, -109, -321, -400,  -49,  354,
+  331,  -92,  334,  462, -292, -352, -100,  297,  600,  165,
+ -400, -215,  -15, -400,    0,-1400,
+       },
+
+       {
+   71,  -95, -189, -372,  354,   -9, -249, -189,   -3,  357,
+  340, -172,  422,  191,   88,  -15,  194, -118,  165,  600,
+ -280, -129,  -15, -400,    0,-1400,
+       },
+
+       {
+    7,  -26,  507,  507, -302,  248,  350,  -19,  169, -400,
+ -400,   44, -368, -400,    0,  145,  107, -400, -400, -280,
+  507,  299, -400, -400,    0,-1400,
+       },
+
+       {
+  -26,  231,  337,  261, -220,  480,  480, -152,  417, -252,
+ -290,  285, -176, -315,  -29,   70,  178, -400, -215, -129,
+  299,  480, -400, -400,    0,-1400,
+       },
+
+       {
+  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,
+  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,  -15,
+ -400, -400, -400, -400,    0,-1400,
+       },
+
+       {
+ -400, -400, -400, -400, -400, -400, -400, -400, -400, -400,
+ -400, -400, -400, -400, -400, -400, -400, -400, -400, -400,
+ -400, -400, -400, -400,    0,-1400,
+       },
+
+       {
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,
+       },
+
+       {
+-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,
+-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,-1400,
+-1400,-1400,-1400,-1400,    0, 1600,
+       },
+    };
diff --git a/binaries/src/mafft/core/mltaln.h b/binaries/src/mafft/core/mltaln.h
new file mode 100644 (file)
index 0000000..459b917
--- /dev/null
@@ -0,0 +1,302 @@
+#define USE_XCED 0
+
+#if USE_XCED
+#include "config.h"
+#include "share.h"
+#else
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+#include <ctype.h>
+#include "mtxutl.h"
+#include <float.h>
+#ifdef enablemultithread
+#include <pthread.h>
+#endif
+
+#define VERSION "6.857b"
+#define SHOWVERSION fprintf( stderr, "%s (%s) Version " VERSION " alg=%c, model=%s\n%d thread(s)\n", progName( argv[0] ), (dorp=='d')?"nuc":"aa", alg, modelname, nthread )
+
+#define FFT_THRESHOLD  80
+#define FFT_WINSIZE_P   20
+#define FFT_WINSIZE_D   100
+#define DISPSEQF  60
+#define DISPSITEI    0
+#define MAXITERATION 500
+#define M   50000       /* njob no saidaiti */
+#define N 5000000       /* nlen no saidaiti */
+#define MAXSEG 100000
+#define B     256
+#define C     60       /*  1 gyou no mojisuu */
+#define D      6
+#define rnd() ( ( 1.0 / ( RAND_MAX + 1.0 ) ) * rand() )
+#define MAX(X,Y)    ( ((X)>(Y))?(X):(Y) )
+#define MIN(X,Y)    ( ((X)<(Y))?(X):(Y) )
+#define G(X)        ( ((X)>(0))?(X):(0) )
+#define BEFF   1.0   /* 0.6 ni suruto zureru */
+#define WIN   3
+#define SGAPP -1000
+#define GETA2 0.001
+#define GETA3 0.001
+#define NOTSPECIFIED  100009
+#define SUEFF   0.1  /* upg/(spg+upg)  -> sueff.sed */ 
+#define DIVLOCAL 0
+#define INTMTXSCALE 1000000.0
+#define JTT 201
+#define TM  202
+
+extern char modelname[100];
+extern int njob, nlenmax;
+extern int amino_n[0x80];
+extern char amino_grp[0x80];
+extern int amino_dis[0x80][0x80];
+extern int amino_disLN[0x80][0x80];
+extern double amino_dis_consweight_multi[0x80][0x80];
+extern int n_dis[26][26];
+extern int n_disFFT[26][26];
+extern float n_dis_consweight_multi[26][26];
+extern char amino[26];
+extern double polarity[20];
+extern double volume[20];
+extern int ribosumdis[37][37];
+
+extern int ppid;
+extern double thrinter;
+extern double fastathreshold;
+extern int pslocal, ppslocal;
+extern int constraint;
+extern int divpairscore;
+extern int fmodel; // 1-> fmodel 0->default -1->raw
+extern int nblosum; // 45, 50, 62, 80
+extern int kobetsubunkatsu;
+extern int bunkatsu;
+extern int dorp;
+extern int niter;
+extern int contin;
+extern int calledByXced;
+extern int devide;
+extern int scmtd;
+extern int weight;
+extern int utree;
+extern int tbutree;
+extern int refine;
+extern int check;
+extern double cut;
+extern int cooling;
+extern int penalty, ppenalty, penaltyLN;
+extern int RNApenalty, RNAppenalty;
+extern int RNApenalty_ex, RNAppenalty_ex;
+extern int penalty_ex, ppenalty_ex, penalty_exLN;
+extern int penalty_EX, ppenalty_EX;
+extern int penalty_OP, ppenalty_OP;
+extern int offset, poffset, offsetLN, offsetFFT;
+extern int RNAthr, RNApthr;
+extern int scoremtx;
+extern int TMorJTT;
+extern char use_fft;
+extern char force_fft;
+extern int nevermemsave;
+extern int fftscore;
+extern int fftWinSize;
+extern int fftThreshold;
+extern int fftRepeatStop;
+extern int fftNoAnchStop;
+extern int divWinSize;
+extern int divThreshold;
+extern int disp;
+extern int outgap;
+extern char alg;
+extern int cnst;
+extern int mix;
+extern int tbitr;
+extern int tbweight;
+extern int tbrweight;
+extern int disopt;
+extern int pamN;
+extern int checkC;
+extern float geta2;
+extern int treemethod;
+extern int kimuraR;
+extern char *swopt;
+extern int fftkeika;
+extern int score_check;
+extern char *inputfile;
+extern char *addfile;
+extern int addprofile;
+extern float consweight_multi;
+extern float consweight_rna;
+extern char RNAscoremtx;
+
+extern char *signalSM;
+extern FILE *prep_g;
+extern FILE *trap_g;
+extern char **seq_g;
+extern char **res_g;
+extern int rnakozo;
+extern char rnaprediction;
+
+/* sengen no ichi ha koko dake de ha nai */
+extern void constants();
+extern char **Calignm1();
+extern char **Dalignm1();
+extern char **align0();
+extern double Cscore_m_1( char **, int, int, double ** );
+extern double score_m_1(  char **, int, int, double ** );
+extern double score_calc0( char **, int, double **, int );
+extern char seqcheck( char ** );
+extern float substitution( char *, char * );
+extern float substitution_score( char *, char * );
+extern float substitution_nid( char *, char * );
+extern float substitution_hosei( char *, char * );
+extern double ipower( double, int );
+extern float translate_and_Calign();
+extern float A__align();
+extern float A__align11();
+extern float A__align_gapmap();
+extern float partA__align();
+extern float L__align11();
+extern float G__align11();
+extern float Falign();
+extern float Falign_localhom();
+extern float Conalign();
+extern float Aalign();
+extern float imp_match_out_sc( int, int );
+extern float part_imp_match_out_sc( int, int );
+extern void ErrorExit();
+extern void cpmx_calc();
+extern void intergroup_score( char **, char **, double *, double *, int, int, int, double * );
+extern int conjuctionfortbfast();
+extern int fastconjuction();
+extern char seqcheck( char ** );
+
+typedef struct _LocalHom
+{
+       int nokori;
+       struct _LocalHom *next;
+       struct _LocalHom *last;
+       int start1;
+       int end1;
+       int start2;
+       int end2;
+       double opt;
+       int overlapaa;
+       int extended;
+       double importance;
+       float fimportance;
+       double wimportance;
+       char korh;
+} LocalHom;
+
+typedef struct _NodeInCub
+{
+       int step;
+       int LorR;
+} NodeInCub;
+
+typedef struct _Node
+{
+       struct _Node *children[3];
+       int tmpChildren[3];
+       double length[3];
+       double *weightptr[3];
+       int top[3];
+       int *members[3];
+} Node;
+
+typedef struct _Segment
+{
+       int start;
+       int end;
+       int center;
+       double score;
+       int skipForeward;
+       int skipBackward;
+       struct _Segment *pair;
+       int  number;
+} Segment;
+
+typedef struct _Segments
+{
+       Segment group1;
+       Segment group2;
+       int number1;
+       int number2;
+} Segments;
+
+typedef struct _Bchain
+{
+       struct _Bchain *next;
+       struct _Bchain *prev;
+       int pos;
+} Bchain;
+
+typedef struct _Achain
+{
+       int next;
+       int prev;
+//     int curr;
+} Achain;
+
+
+typedef struct _Fukusosuu
+{
+    double R;
+    double I;
+} Fukusosuu;
+
+typedef struct _Gappattern
+{
+       int len;
+       float freq;
+} Gappat;
+
+typedef struct _RNApair
+{
+       int uppos;
+       float upscore;
+       int downpos;
+       float downscore;
+       int bestpos;
+       float bestscore;
+} RNApair;
+
+typedef struct _Treedep
+{
+       int child0;
+       int child1;
+       int done;
+} Treedep;
+
+
+#include "fft.h"
+#include "dp.h"
+#include "functions.h"
+
+#ifdef enablemultithread
+#define TLS __thread
+#else
+#define TLS 
+#endif
+
+extern TLS int commonAlloc1;
+extern TLS int commonAlloc2;
+extern TLS int **commonIP;
+extern TLS int **commonJP;
+extern int nthread;
+extern int randomseed;
+extern int parallelizationstrategy;
+#define BESTFIRST 0
+#define BAATARI0 1
+#define BAATARI1 2
+#define BAATARI2 3
+
+extern int scoreout;
+extern int outnumber;
+
+extern char *newgapstr;
diff --git a/binaries/src/mafft/core/mltaln9.c b/binaries/src/mafft/core/mltaln9.c
new file mode 100644 (file)
index 0000000..5e736f2
--- /dev/null
@@ -0,0 +1,7281 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+#if 0
+int seqlen( char *seq )
+{
+       int val = 0;
+       while( *seq )
+               if( *seq++ != '-' ) val++;
+       return( val );
+}
+#else
+int seqlen( char *seq )
+{
+       int val = 0;
+       if( *newgapstr == '-' )
+       {
+               while( *seq )
+                       if( *seq++ != '-' ) val++;
+       }
+       else
+       {
+               while( *seq )
+               {
+                       if( *seq != '-' && *seq != *newgapstr ) val++;
+                       seq++;
+               }
+       }
+       return( val );
+}
+#endif
+
+int intlen( int *num )
+{
+       int value = 0;
+       while( *num++ != -1 ) value++;
+       return( value );
+}
+
+char seqcheck( char **seq )
+{
+       int i, len;
+       char **seqbk = seq;
+       while( *seq )   
+       {
+               len = strlen( *seq );
+               for( i=0; i<len; i++ ) 
+               {
+                       if( amino_n[(int)(*seq)[i]] == -1 ) 
+                       {
+
+                               fprintf( stderr, "========================================================================= \n" );
+                               fprintf( stderr, "========================================================================= \n" );
+                               fprintf( stderr, "=== \n" );
+                               fprintf( stderr, "=== Alphabet '%c' is unknown.\n", (*seq)[i] );
+                               fprintf( stderr, "=== Please check site %d in sequence %d.\n", i+1, (int)(seq-seqbk+1) );
+                               fprintf( stderr, "=== \n" );
+                               fprintf( stderr, "=== To make an alignment having unusual characters (U, @, #, etc), try\n" );
+                               fprintf( stderr, "=== %% mafft --anysymbol input > output\n" );
+                               fprintf( stderr, "=== \n" );
+                               fprintf( stderr, "========================================================================= \n" );
+                               fprintf( stderr, "========================================================================= \n" );
+                               return( (int)(*seq)[i] );
+                       }
+               }
+               seq++;
+       }
+       return( 0 );
+}
+       
+void scmx_calc( int icyc, char **aseq, double *effarr, float **scmx )
+{
+       int  i, j, lgth;
+        
+       lgth = strlen( aseq[0] );
+       for( j=0; j<lgth; j++ )
+       {
+               for( i=0; i<26; i++ )
+               {
+                       scmx[i][j] = 0;
+               }
+       }
+       for( i=0; i<icyc+1; i++ )
+       {
+               int id;
+               id = amino_n[(int)aseq[i][0]];
+               scmx[id][0] += (float)effarr[i];
+       }
+       for( j=1; j<lgth-1; j++ )
+       {
+               for( i=0; i<icyc+1; i++ )
+               {
+                       int id;
+                       id = amino_n[(int)aseq[i][j]];
+                       scmx[id][j] += (float)effarr[i];
+               }
+       }
+       for( i=0; i<icyc+1; i++ )
+       {
+               int id;
+               id = amino_n[(int)aseq[i][lgth-1]];
+               scmx[id][lgth-1] += (float)effarr[i];
+       }
+}
+
+void exitall( char arr[] )
+{
+       fprintf( stderr, "%s\n", arr );
+       exit( 1 );
+}
+
+void display( char **seq, int nseq )
+{
+       int i, imax;
+       char b[121];
+
+       if( !disp ) return;
+               if( nseq > DISPSEQF ) imax = DISPSEQF;
+               else                  imax = nseq;
+               fprintf( stderr, "    ....,....+....,....+....,....+....,....+....,....+....,....+....,....+....,....+....,....+....,....+....,....+....,....+\n" );
+               for( i=0; i<+imax; i++ )
+               {
+                       strncpy( b, seq[i]+DISPSITEI, 120 );
+                       b[120] = 0;
+                       fprintf( stderr, "%3d %s\n", i+1, b );
+               }
+}
+#if 0
+double intergroup_score( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len )
+{
+       int i, j, k;
+       double score;
+       double tmpscore;
+       char *mseq1, *mseq2;
+       double efficient;
+       char xxx[100];
+
+//     totaleff1 = 0.0; for( i=0; i<clus1; i++ ) totaleff1 += eff1[i];
+//     totaleff2 = 0.0; for( i=0; i<clus2; i++ ) totaleff2 += eff2[i];
+
+       score = 0.0;
+       for( i=0; i<clus1; i++ ) for( j=0; j<clus2; j++ ) 
+       {
+               efficient = eff1[i] * eff2[j];
+               mseq1 = seq1[i];
+               mseq2 = seq2[j];
+               tmpscore = 0.0;
+               for( k=0; k<len; k++ ) 
+               {
+                       if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                       tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+
+                       if( mseq1[k] == '-' ) 
+                       {
+                               tmpscore += penalty;
+                               tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                               while( mseq1[++k] == '-' )
+                                       tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                               k--;
+                               if( k >len-2 ) break;
+                               continue;
+                       }
+                       if( mseq2[k] == '-' )
+                       {
+                               tmpscore += penalty;
+                               tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                               while( mseq2[++k] == '-' )
+                                       tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                               k--;
+                               if( k > len-2 ) break;
+                               continue;
+                       }
+               }
+               score += (double)tmpscore * efficient;
+#if 1
+               sprintf( xxx, "%f", score );
+//             fprintf( stderr, "## score in intergroup_score = %f\n", score );
+#endif
+       }
+#if 0
+               fprintf( stderr, "###score = %f\n", score );
+#endif
+#if 0
+       fprintf( stderr, "## score in intergroup_score = %f\n", score );
+#endif
+       return( score );
+}
+#endif
+
+void intergroup_score_consweight( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value )
+{
+       int i, j, k;
+       int len2 = len - 2;
+       int ms1, ms2;
+       double tmpscore;
+       char *mseq1, *mseq2;
+       double efficient;
+
+//     totaleff1 = 0.0; for( i=0; i<clus1; i++ ) totaleff1 += eff1[i];
+//     totaleff2 = 0.0; for( i=0; i<clus2; i++ ) totaleff2 += eff2[i];
+
+
+
+       *value = 0.0;
+       for( i=0; i<clus1; i++ ) 
+       {
+               for( j=0; j<clus2; j++ ) 
+               {
+                       efficient = eff1[i] * eff2[j]; /* \e$B$J$<$+G[Ns$r;H$o$J$$$H$*$+$7$/$J$k\e(B, \e$BB?J,%P%0\e(B */
+                       mseq1 = seq1[i];
+                       mseq2 = seq2[j];
+                       tmpscore = 0.0;
+                       for( k=0; k<len; k++ ) 
+                       {
+                               ms1 = (int)mseq1[k];
+                               ms2 = (int)mseq2[k];
+                               if( ms1 == (int)'-' && ms2 == (int)'-' ) continue;
+                               tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+       
+                               if( ms1 == (int)'-' ) 
+                               {
+                                       tmpscore += (double)penalty;
+                                       tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       while( (ms1=(int)mseq1[++k]) == (int)'-' )
+                                               ;
+//                                             tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       k--;
+                                       if( k >len2 ) break;
+                                       continue;
+                               }
+                               if( ms2 == (int)'-' )
+                               {
+                                       tmpscore += (double)penalty;
+                                       tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       while( (ms2=(int)mseq2[++k]) == (int)'-' )
+                                               ;
+//                                             tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       k--;
+                                       if( k > len2 ) break;
+                                       continue;
+                               }
+                       }
+                       *value += (double)tmpscore * (double)efficient;
+//                     fprintf( stderr, "val in _gapnomi = %f\n", *value );
+               }
+       }
+#if 0
+       fprintf( stdout, "###score = %f\n", score );
+#endif
+#if DEBUG
+       fprintf( stderr, "score in intergroup_score = %f\n", score );
+#endif
+//     return( score );
+}
+void intergroup_score_gapnomi( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value )
+{
+       int i, j, k;
+       int len2 = len - 2;
+       int ms1, ms2;
+       double tmpscore;
+       char *mseq1, *mseq2;
+       double efficient;
+
+//     totaleff1 = 0.0; for( i=0; i<clus1; i++ ) totaleff1 += eff1[i];
+//     totaleff2 = 0.0; for( i=0; i<clus2; i++ ) totaleff2 += eff2[i];
+
+
+
+       *value = 0.0;
+       for( i=0; i<clus1; i++ ) 
+       {
+               for( j=0; j<clus2; j++ ) 
+               {
+                       efficient = eff1[i] * eff2[j]; /* \e$B$J$<$+G[Ns$r;H$o$J$$$H$*$+$7$/$J$k\e(B, \e$BB?J,%P%0\e(B */
+                       mseq1 = seq1[i];
+                       mseq2 = seq2[j];
+                       tmpscore = 0.0;
+                       for( k=0; k<len; k++ ) 
+                       {
+                               ms1 = (int)mseq1[k];
+                               ms2 = (int)mseq2[k];
+                               if( ms1 == (int)'-' && ms2 == (int)'-' ) continue;
+//                             tmpscore += (double)amino_dis[ms1][ms2];
+       
+                               if( ms1 == (int)'-' ) 
+                               {
+                                       tmpscore += (double)penalty;
+//                                     tmpscore += (double)amino_dis[ms1][ms2];
+                                       while( (ms1=(int)mseq1[++k]) == (int)'-' )
+                                               ;
+//                                             tmpscore += (double)amino_dis[ms1][ms2];
+                                       k--;
+                                       if( k >len2 ) break;
+                                       continue;
+                               }
+                               if( ms2 == (int)'-' )
+                               {
+                                       tmpscore += (double)penalty;
+//                                     tmpscore += (double)amino_dis[ms1][ms2];
+                                       while( (ms2=(int)mseq2[++k]) == (int)'-' )
+                                               ;
+//                                             tmpscore += (double)amino_dis[ms1][ms2];
+                                       k--;
+                                       if( k > len2 ) break;
+                                       continue;
+                               }
+                       }
+                       *value += (double)tmpscore * (double)efficient;
+//                     fprintf( stderr, "val in _gapnomi = %f\n", *value );
+               }
+       }
+#if 0
+       fprintf( stdout, "###score = %f\n", score );
+#endif
+#if DEBUG
+       fprintf( stderr, "score in intergroup_score = %f\n", score );
+#endif
+//     return( score );
+}
+
+void intergroup_score( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value )
+{
+       int i, j, k;
+       int len2 = len - 2;
+       int ms1, ms2;
+       double tmpscore;
+       char *mseq1, *mseq2;
+       double efficient;
+
+       double gaptmpscore;
+       double gapscore = 0.0;
+
+//     fprintf( stderr, "#### in intergroup_score\n" );
+
+//     totaleff1 = 0.0; for( i=0; i<clus1; i++ ) totaleff1 += eff1[i];
+//     totaleff2 = 0.0; for( i=0; i<clus2; i++ ) totaleff2 += eff2[i];
+
+       *value = 0.0;
+       for( i=0; i<clus1; i++ ) 
+       {
+               for( j=0; j<clus2; j++ ) 
+               {
+                       efficient = eff1[i] * eff2[j]; /* \e$B$J$<$+G[Ns$r;H$o$J$$$H$*$+$7$/$J$k\e(B, \e$BB?J,%P%0\e(B */
+                       mseq1 = seq1[i];
+                       mseq2 = seq2[j];
+                       tmpscore = 0.0;
+                       gaptmpscore = 0.0;
+                       for( k=0; k<len; k++ ) 
+                       {
+                               ms1 = (int)mseq1[k];
+                               ms2 = (int)mseq2[k];
+                               if( ms1 == (int)'-' && ms2 == (int)'-' ) continue;
+//                             tmpscore += (double)amino_dis[ms1][ms2];
+                               tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+       
+                               if( ms1 == (int)'-' ) 
+                               {
+                                       tmpscore += (double)penalty;
+                                       gaptmpscore += (double)penalty;
+//                                     tmpscore += (double)amino_dis[ms1][ms2];
+                                       tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       while( (ms1=(int)mseq1[++k]) == (int)'-' )
+//                                             tmpscore += (double)amino_dis[ms1][ms2];
+                                               tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       k--;
+                                       if( k >len2 ) break;
+                                       continue;
+                               }
+                               if( ms2 == (int)'-' )
+                               {
+                                       tmpscore += (double)penalty;
+                                       gaptmpscore += (double)penalty;
+//                                     tmpscore += (double)amino_dis[ms1][ms2];
+                                       tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       while( (ms2=(int)mseq2[++k]) == (int)'-' )
+//                                             tmpscore += (double)amino_dis[ms1][ms2];
+                                               tmpscore += (double)amino_dis_consweight_multi[ms1][ms2];
+                                       k--;
+                                       if( k > len2 ) break;
+                                       continue;
+                               }
+                       }
+                       *value += (double)tmpscore * (double)efficient;
+                       gapscore += (double)gaptmpscore * (double)efficient;
+               }
+       }
+#if 0
+       fprintf( stderr, "###gapscore = %f\n", gapscore );
+#endif
+#if DEBUG
+       fprintf( stderr, "score in intergroup_score = %f\n", score );
+#endif
+//     return( score );
+}
+void intergroup_score_new( char **seq1, char **seq2, double *eff1, double *eff2, int clus1, int clus2, int len, double *value )
+{
+       int i, j, k;
+       int len2 = len - 2;
+       int ms1, ms2;
+       double tmpscore;
+       char *mseq1, *mseq2;
+       static double efficient[1];
+
+//     totaleff1 = 0.0; for( i=0; i<clus1; i++ ) totaleff1 += eff1[i];
+//     totaleff2 = 0.0; for( i=0; i<clus2; i++ ) totaleff2 += eff2[i];
+
+       *value = 0.0;
+       for( i=0; i<clus1; i++ ) 
+       {
+               for( j=0; j<clus2; j++ ) 
+               {
+                       *efficient = eff1[i] * eff2[j]; /* \e$B$J$<$+G[Ns$r;H$o$J$$$H$*$+$7$/$J$k\e(B, \e$BB?J,%P%0\e(B */
+                       mseq1 = seq1[i];
+                       mseq2 = seq2[j];
+                       tmpscore = 0.0;
+                       for( k=0; k<len; k++ ) 
+                       {
+                               ms1 = (int)mseq1[k];
+                               ms2 = (int)mseq2[k];
+                               if( ms1 == (int)'-' && ms2 == (int)'-' ) continue;
+                               tmpscore += (double)amino_dis[ms1][ms2];
+       
+                               if( ms1 == (int)'-' ) 
+                               {
+                                       tmpscore += (double)penalty;
+                                       tmpscore += (double)amino_dis[ms1][ms2];
+                                       while( (ms1=(int)mseq1[++k]) == (int)'-' )
+                                               tmpscore += (double)amino_dis[ms1][ms2];
+                                       k--;
+                                       if( k >len2 ) break;
+                                       continue;
+                               }
+                               if( ms2 == (int)'-' )
+                               {
+                                       tmpscore += (double)penalty;
+                                       tmpscore += (double)amino_dis[ms1][ms2];
+                                       while( (ms2=(int)mseq2[++k]) == (int)'-' )
+                                               tmpscore += (double)amino_dis[ms1][ms2];
+                                       k--;
+                                       if( k > len2 ) break;
+                                       continue;
+                               }
+                       }
+                       *value += (double)tmpscore * (double)*efficient;
+               }
+       }
+#if 0
+       fprintf( stdout, "###score = %f\n", score );
+#endif
+#if DEBUG
+       fprintf( stderr, "score in intergroup_score = %f\n", score );
+#endif
+//     return( score );
+}
+
+
+double score_calc5( char **seq, int s, double **eff, int ex )  /* method 3 deha nai */
+{
+    int i, j, k;
+    double c;
+    int len = strlen( seq[0] );
+    double score;
+    double tmpscore;
+    char *mseq1, *mseq2;
+    double efficient;
+#if DEBUG
+       FILE *fp;
+#endif
+
+    score = 0.0;
+    c = 0.0;
+
+       for( i=0; i<s; i++ ) 
+       {
+               
+                       if( i == ex ) continue;
+            efficient = eff[i][ex];
+            mseq1 = seq[i];
+            mseq2 = seq[ex];
+            tmpscore = 0.0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq1[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq2[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+            score += (double)tmpscore * efficient;
+/*
+                       fprintf( stdout, "%d-%d tmpscore = %f, eff = %f, tmpscore*eff = %f\n", i, ex, tmpscore, efficient, tmpscore*efficient );
+*/
+       }
+       /*
+       fprintf( stdout, "total score = %f\n", score );
+       */
+
+    for( i=0; i<s-1; i++ )
+    {
+        for( j=i+1; j<s; j++ )
+        {
+                       if( i == ex || j == ex ) continue;
+
+            efficient = eff[i][j];
+            mseq1 = seq[i];
+            mseq2 = seq[j];
+            tmpscore = 0.0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq1[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq2[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+            score += (double)tmpscore * efficient;
+        }
+    }
+/*
+       fprintf( stderr, "score in score_calc5 = %f\n", score );
+*/
+    return( (double)score );
+/*
+
+fprintf( trap_g, "score by fast = %f\n", (float)score );
+
+tmpscore = score = 0.0;
+       for( i=0; i<s; i++ ) 
+       {
+               if( i == ex ) continue;
+               tmpscore = Cscore_m_1( seq, i, eff );
+               fprintf( stdout, "%d %f\n", i, tmpscore );
+
+               score += tmpscore;
+       }
+       tmpscore = Cscore_m_1( seq, ex, eff );
+       fprintf( stdout, "ex%d %f\n", i, tmpscore );
+       score += tmpscore;
+
+       return( score );
+*/
+}
+
+
+       
+double score_calc4( char **seq, int s, double **eff, int ex )  /* method 3 deha nai */
+{
+    int i, j, k;
+       double c;
+    int len = strlen( seq[0] );
+    double score;
+    long tmpscore;
+       char *mseq1, *mseq2;
+       double efficient;
+
+    score = 0.0;
+       c = 0.0;
+/*
+       printf( "in score_calc4\n" );
+       for( i=0; i<s; i++ )
+       {
+               for( j=0; j<s; j++ ) 
+               {
+                       printf( "% 5.3f", eff[i][j] ); 
+               }
+               printf( "\n" );
+               
+       }
+*/
+    for( i=0; i<s-1; i++ )
+    {
+        for( j=i+1; j<s; j++ )
+        {
+                       efficient = eff[i][j];
+                       if( mix == 1 ) efficient = 1.0;
+                       /*
+                       printf( "weight for %d v.s. %d = %f\n", i, j, efficient );
+                       */
+            mseq1 = seq[i];
+            mseq2 = seq[j];
+            tmpscore = 0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]] + 400 * !scoremtx ;
+
+                               c += efficient;
+
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty - n_dis[24][0];
+                    while( mseq1[++k] == '-' )
+                                               ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty - n_dis[24][0];
+                    while( mseq2[++k] == '-' )
+                                               ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+                       /*
+                       if( x == 65 ) printf( "i=%d j=%d tmpscore=%d l=%d\n", i, j, tmpscore, len );
+                       */
+            score += (double)tmpscore * efficient;
+        }
+    }
+    score /= c;
+    return( (double)score );
+}
+
+
+
+void upg2( int nseq, double **eff, int ***topol, double **len )
+{
+    int i, j, k;
+       double tmplen[M];
+
+    static char **pair = NULL;
+
+       if( !pair )
+       {
+               pair = AllocateCharMtx( njob, njob );
+       }
+
+       for( i=0; i<nseq; i++ ) tmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) pair[i][j] = 0;
+    for( i=0; i<nseq; i++ ) pair[i][i] = 1;
+
+    for( k=0; k<nseq-1; k++ )
+    {
+        float minscore = 9999.0;
+        int im = -1, jm = -1;
+        int count;
+
+        for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+        {
+            if( eff[i][j] < minscore )
+            {
+                minscore = eff[i][j];
+                im = i; jm = j;
+            }
+        }
+        for( i=0, count=0; i<nseq; i++ )
+            if( pair[im][i] > 0 )
+            {
+                topol[k][0][count] = i;
+                count++;
+            }
+        topol[k][0][count] = -1;
+        for( i=0, count=0; i<nseq; i++ )
+            if( pair[jm][i] > 0 )
+            {
+                topol[k][1][count] = i;
+                count++;
+            }
+        topol[k][1][count] = -1;
+
+               len[k][0] = minscore / 2.0 - tmplen[im];
+               len[k][1] = minscore / 2.0 - tmplen[jm];
+
+               tmplen[im] = minscore / 2.0;
+
+        for( i=0; i<nseq; i++ ) pair[im][i] += ( pair[jm][i] > 0 );
+        for( i=0; i<nseq; i++ ) pair[jm][i] = 0;
+
+        for( i=0; i<nseq; i++ )
+        {
+            if( i != im && i != jm )
+            {
+                eff[MIN(i,im)][MAX(i,im)] =
+                ( eff[MIN(i,im)][MAX(i,im)] + eff[MIN(i,jm)][MAX(i,jm)] ) / 2.0;
+                eff[MIN(i,jm)][MAX(i,jm)] = 9999.0;
+            }
+            eff[im][jm] = 9999.0;
+        }
+#if DEBUG
+        printf( "STEP-%03d:\n", k+1 );
+               printf( "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) printf( " %03d", topol[k][0][i] );
+        printf( "\n" );
+               printf( "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) printf( " %03d", topol[k][1][i] );
+        printf( "\n" );
+#endif
+    }
+}
+
+static void setnearest( int nseq, Bchain *acpt, float **eff, float *mindisfrompt, int *nearestpt, int pos )
+{
+       int j;
+       float tmpfloat;
+       float **effptpt;
+       Bchain *acptj;
+
+       *mindisfrompt = 999.9;
+       *nearestpt = -1;
+
+//     if( (acpt+pos)->next ) effpt = eff[pos]+(acpt+pos)->next->pos-pos;
+
+//     for( j=pos+1; j<nseq; j++ )
+       for( acptj=(acpt+pos)->next; acptj!=NULL; acptj=acptj->next )
+       {
+               j = acptj->pos;
+//             if( (tmpfloat=*effpt++) < *mindisfrompt )
+               if( (tmpfloat=eff[pos][j-pos]) < *mindisfrompt )
+               {
+                       *mindisfrompt = tmpfloat;
+                       *nearestpt = j;
+               }
+       }
+       effptpt = eff;
+//     for( j=0; j<pos; j++ )
+       for( acptj=acpt; (acptj&&acptj->pos!=pos); acptj=acptj->next )
+       {
+               j = acptj->pos;
+//             if( (tmpfloat=(*effptpt++)[pos-j]) < *mindisfrompt )
+               if( (tmpfloat=eff[j][pos-j]) < *mindisfrompt )
+               {
+                       *mindisfrompt = tmpfloat;
+                       *nearestpt = j;
+               }
+       }
+}
+
+static void setnearest_double_fullmtx( int nseq, Bchain *acpt, double **eff, double *mindisfrompt, int *nearestpt, int pos )
+{
+       int j;
+       double tmpfloat;
+       double **effptpt;
+       Bchain *acptj;
+
+       *mindisfrompt = 999.9;
+       *nearestpt = -1;
+
+//     if( (acpt+pos)->next ) effpt = eff[pos]+(acpt+pos)->next->pos-pos;
+
+//     for( j=pos+1; j<nseq; j++ )
+       for( acptj=(acpt+pos)->next; acptj!=NULL; acptj=acptj->next )
+       {
+               j = acptj->pos;
+//             if( (tmpfloat=*effpt++) < *mindisfrompt )
+               if( (tmpfloat=eff[pos][j]) < *mindisfrompt )
+               {
+                       *mindisfrompt = tmpfloat;
+                       *nearestpt = j;
+               }
+       }
+       effptpt = eff;
+//     for( j=0; j<pos; j++ )
+       for( acptj=acpt; (acptj&&acptj->pos!=pos); acptj=acptj->next )
+       {
+               j = acptj->pos;
+//             if( (tmpfloat=(*effptpt++)[pos-j]) < *mindisfrompt )
+               if( (tmpfloat=eff[j][pos]) < *mindisfrompt )
+               {
+                       *mindisfrompt = tmpfloat;
+                       *nearestpt = j;
+               }
+       }
+}
+
+
+
+static void loadtreeoneline( int *ar, float *len, FILE *fp )
+{
+       static char gett[1000];
+
+       fgets( gett, 999, fp );
+
+//     fprintf( stderr, "gett=%s\n", gett );
+
+
+       sscanf( gett, "%d %d %f %f", ar, ar+1, len, len+1 );
+
+       ar[0]--;
+       ar[1]--;
+
+       if( ar[0] >= ar[1] )
+       {
+               fprintf( stderr, "Incorrect guide tree\n" );
+               exit( 1 );
+       }
+
+
+//     fprintf( stderr, "ar[0] = %d, ar[1] = %d\n", ar[0], ar[1] );
+//     fprintf( stderr, "len[0] = %f, len[1] = %f\n", len[0], len[1] );
+}
+
+void loadtree( int nseq, int ***topol, float **len, char **name, int *nlen, Treedep *dep )
+{
+       int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       static int *hist = NULL;
+       static Bchain *ac = NULL;
+       int im = -1, jm = -1;
+       Bchain *acjmnext, *acjmprev;
+       int prevnode;
+       Bchain *acpti;
+       int *pt1, *pt2, *pt11, *pt22;
+       static int *nmemar;
+       int nmemim, nmemjm;
+       float minscore;
+       int *nearest = NULL; // by D.Mathog, a guess
+       float *mindisfrom = NULL; // by D.Mathog, a guess
+       static char **tree;
+       static char *treetmp;
+       static char *nametmp;
+       FILE *fp;
+       int node[2];
+
+       fp = fopen( "_guidetree", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "cannot open _guidetree\n" );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               hist = AllocateIntVec( njob );
+               ac = (Bchain *)malloc( njob * sizeof( Bchain ) );
+               nmemar = AllocateIntVec( njob );
+               mindisfrom = AllocateFloatVec( njob );
+               nearest = AllocateIntVec( njob );
+               treetmp = AllocateCharVec( njob*50 );
+               nametmp = AllocateCharVec( 31 );
+               tree = AllocateCharMtx( njob, njob*50 );
+       }
+
+       
+    for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<30; j++ ) nametmp[j] = 0;
+               for( j=0; j<30; j++ ) 
+               {
+                       if( isalnum( name[i][j] ) )
+                               nametmp[j] = name[i][j];
+                       else
+                               nametmp[j] = '_';
+               }
+               nametmp[30] = 0;
+//             sprintf( tree[i], "%d_l=%d_%.20s", i+1, nlen[i], nametmp+1 );
+               sprintf( tree[i], "%d_%.20s", i+1, nametmp+1 );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = ac+i+1;
+               ac[i].prev = ac+i-1;
+               ac[i].pos = i;
+       }
+       ac[nseq-1].next = NULL;
+
+
+       for( i=0; i<nseq; i++ ) 
+       {
+               hist[i] = -1;
+               nmemar[i] = 1;
+       }
+
+       fprintf( stderr, "\n" );
+       for( k=0; k<nseq-1; k++ )
+       {
+               if( k % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", k, nseq );
+#if 0
+               minscore = 999.9;
+               for( acpti=ac; acpti->next!=NULL; acpti=acpti->next ) 
+               {
+                       i = acpti->pos;
+//                     fprintf( stderr, "k=%d i=%d\n", k, i );
+                       if( mindisfrom[i] < minscore ) // muscle
+                       {
+                               im = i;
+                               minscore = mindisfrom[i];
+                       }
+               }
+               jm = nearest[im];
+               if( jm < im ) 
+               {
+                       j=jm; jm=im; im=j;
+               }
+#else
+               minscore = 0.0;
+               len[k][0] = len[k][1] = -1.0;
+               loadtreeoneline( node, len[k], fp );
+               im = node[0];
+               jm = node[1];
+
+               if( len[k][0] == -1.0 || len[k][1] == -1.0 )
+               {
+                       fprintf( stderr, "\n\nERROR: Branch length is not given.\n" );
+                       exit( 1 );
+               }
+
+               if( len[k][0] < 0.0 ) len[k][0] = 0.0;
+               if( len[k][1] < 0.0 ) len[k][1] = 0.0;
+
+#endif
+
+               prevnode = hist[im];
+               if( dep ) dep[k].child0 = prevnode;
+               nmemim = nmemar[im];
+
+//             fprintf( stderr, "prevnode = %d, nmemim = %d\n", prevnode, nmemim );
+
+               intpt = topol[k][0] = (int *)realloc( topol[k][0], ( nmemim + 1 ) * sizeof( int ) );
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+
+               nmemjm = nmemar[jm];
+               prevnode = hist[jm];
+               if( dep ) dep[k].child1 = prevnode;
+
+//             fprintf( stderr, "prevnode = %d, nmemjm = %d\n", prevnode, nmemjm );
+
+               intpt = topol[k][1] = (int *)realloc( topol[k][1], ( nmemjm + 1 ) * sizeof( int ) );
+               if( !intpt )
+               {
+                       fprintf( stderr, "Cannot reallocate topol\n" );
+                       exit( 1 );
+               }
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+//             len[k][0] = ( minscore - tmptmplen[im] );
+//             len[k][1] = ( minscore - tmptmplen[jm] );
+//             len[k][0] = -1;
+//             len[k][1] = -1;
+
+
+               hist[im] = k;
+               nmemar[im] = nmemim + nmemjm;
+
+               mindisfrom[im] = 999.9;
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+        {
+                       i = acpti->pos;
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+            }
+        }
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+
+//             fprintf( stderr, "im,jm=%d,%d\n", im, jm );
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               acjmprev->next = acjmnext;
+               if( acjmnext != NULL )
+                       acjmnext->prev = acjmprev;
+//             free( (void *)eff[jm] ); eff[jm] = NULL;
+
+#if 0 // muscle seems to miss this.
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+               {
+                       i = acpti->pos;
+                       if( nearest[i] == im ) 
+                       {
+//                             fprintf( stderr, "calling setnearest\n" );
+//                             setnearest( nseq, ac, eff, mindisfrom+i, nearest+i, i );
+                       }
+               }
+#endif
+
+
+#if 0
+        fprintf( stdout, "vSTEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i]+1 );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i]+1 );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fclose( fp );
+       fp = fopen( "infile.tree", "w" );
+               fprintf( fp, "%s\n", treetmp );
+               fprintf( fp, "#by loadtree\n" );
+       fclose( fp );
+
+       FreeCharMtx( tree );
+       free( treetmp );
+       free( nametmp );
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       free( (void *)nmemar ); nmemar = NULL;
+       free( mindisfrom );
+       free( nearest );
+
+
+}
+
+static float sueff1, sueff05;
+static double sueff1_double, sueff05_double;
+
+static float cluster_mix_float( float d1, float d2 )
+{
+       return( MIN( d1, d2 ) * sueff1 + ( d1 + d2 ) * sueff05 ); 
+}
+static float cluster_average_float( float d1, float d2 )
+{
+       return( ( d1 + d2 ) * 0.5 ); 
+}
+static float cluster_minimum_float( float d1, float d2 )
+{
+       return( MIN( d1, d2 ) ); 
+}
+static double cluster_mix_double( double d1, double d2 )
+{
+       return( MIN( d1, d2 ) * sueff1_double + ( d1 + d2 ) * sueff05_double ); 
+}
+static double cluster_average_double( double d1, double d2 )
+{
+       return( ( d1 + d2 ) * 0.5 ); 
+}
+static double cluster_minimum_double( double d1, double d2 )
+{
+       return( MIN( d1, d2 ) ); 
+}
+
+void loadtop( int nseq, float **eff, int ***topol, float **len ) // computes branch length BUG!!
+{
+       int i, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       static Bchain *ac = NULL;
+       float eff1, eff0;
+       static float *tmptmplen = NULL;
+       static int *hist = NULL;
+       int im = -1, jm = -1;
+       Bchain *acjmnext, *acjmprev;
+       int prevnode;
+       Bchain *acpti;
+       int *pt1, *pt2, *pt11, *pt22;
+       static int *nmemar;
+       int nmemim, nmemjm;
+       float minscore;
+       static char **tree;
+       static char *treetmp;
+       FILE *fp;
+       int node[2];
+       float dumfl[2];
+       float (*clusterfuncpt[1])(float,float);
+
+
+       sueff1 = 1 - SUEFF;
+       sueff05 = SUEFF * 0.5;
+       if ( treemethod == 'X' )
+               clusterfuncpt[0] = cluster_mix_float;
+       else if ( treemethod == 'E' )
+               clusterfuncpt[0] = cluster_average_float;
+       else if ( treemethod == 'q' )
+               clusterfuncpt[0] = cluster_minimum_float;
+       else
+       {
+               fprintf( stderr, "Unknown treemethod, %c\n", treemethod );
+               exit( 1 );
+       }
+
+       fp = fopen( "_guidetree", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "cannot open _guidetree\n" );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               treetmp = AllocateCharVec( njob*50 );
+               tree = AllocateCharMtx( njob, njob*50 );
+               hist = AllocateIntVec( njob );
+               tmptmplen = AllocateFloatVec( njob );
+               ac = (Bchain *)malloc( njob * sizeof( Bchain ) );
+               nmemar = AllocateIntVec( njob );
+       }
+       
+    for( i=0; i<nseq; i++ ) sprintf( tree[i], "%d", i+1 );
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = ac+i+1;
+               ac[i].prev = ac+i-1;
+               ac[i].pos = i;
+       }
+       ac[nseq-1].next = NULL;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               hist[i] = -1;
+               nmemar[i] = 1;
+       }
+
+       fprintf( stderr, "\n" );
+       for( k=0; k<nseq-1; k++ )
+       {
+               if( k % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", k, nseq );
+
+#if 0
+               minscore = 99999.9;
+               for( acpti=ac; acpti->next!=NULL; acpti=acpti->next ) 
+               {
+                       effpt = eff[i=acpti->pos];
+//                     i = acpti->pos;
+                       for( acptj=acpti->next; acptj!=NULL; acptj=acptj->next )
+               {
+//                             j=acptj->pos;
+//                             tmpfloat = eff[i][j-i];
+//                             if( tmpfloat < minscore )
+                               if( (tmpfloat= effpt[(j=acptj->pos)-i]) < minscore )
+                               {
+                                       minscore = tmpfloat;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+
+//             fprintf( stderr, "im=%d, jm=%d, minscore = %f\n", im, jm, minscore );
+#else
+               dumfl[0] = dumfl[1] = -1.0;
+               loadtreeoneline( node, dumfl, fp );
+               im = node[0];
+               jm = node[1];
+               minscore = eff[im][jm-im];
+
+//             fprintf( stderr, "im=%d, jm=%d, minscore = %f\n", im, jm, minscore );
+
+
+               if( dumfl[0] != -1.0 || dumfl[1] != -1.0 )
+               {
+                       fprintf( stderr, "\n\nERROR: Branch length should not be given.\n" );
+                       exit( 1 );
+               }
+
+#endif
+
+
+               prevnode = hist[im];
+               nmemim = nmemar[im];
+               intpt = topol[k][0] = (int *)realloc( topol[k][0], ( nmemim + 1 ) * sizeof( int ) );
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               prevnode = hist[jm];
+               nmemjm = nmemar[jm];
+               intpt = topol[k][1] = (int *)realloc( topol[k][1], ( nmemjm + 1 ) * sizeof( int ) );
+               if( !intpt )
+               {
+                       fprintf( stderr, "Cannot reallocate topol\n" );
+                       exit( 1 );
+               }
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = ( minscore - tmptmplen[im] );
+               len[k][1] = ( minscore - tmptmplen[jm] );
+
+               if( len[k][0] < 0.0 ) len[k][0] = 0.0;
+               if( len[k][1] < 0.0 ) len[k][1] = 0.0;
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+               nmemar[im] = nmemim + nmemjm;
+
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+        {
+                       i = acpti->pos;
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim-miniim];
+                               eff1 = eff[minijm][maxijm-minijm];
+#if 0
+                eff[miniim][maxiim-miniim] =
+                               MIN( eff0, eff1 ) * sueff1 + ( eff0 + eff1 ) * sueff05; 
+#else
+                eff[miniim][maxiim-miniim] =
+                               (clusterfuncpt[0])( eff0, eff1 );
+#endif
+            }
+        }
+//             sprintf( treetmp, "(%s,%s)", tree[im], tree[jm] );
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               acjmprev->next = acjmnext;
+               if( acjmnext != NULL )
+                       acjmnext->prev = acjmprev;
+               free( (void *)eff[jm] ); eff[jm] = NULL;
+#if 0
+        fprintf( stdout, "vSTEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i]+1 );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i]+1 );
+        fprintf( stdout, "\n" );
+#endif
+    }
+#if 1
+       fclose( fp );
+       fp = fopen( "infile.tree", "w" );
+               fprintf( fp, "%s\n", treetmp );
+               fprintf( fp, "by loadtop\n" );
+       fclose( fp );
+#endif
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       free( (void *)nmemar ); nmemar = NULL;
+
+}
+
+
+void fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( int nseq, float **eff, int ***topol, float **len, char **name, int *nlen, Treedep *dep )
+{
+       int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       float tmpfloat;
+       float eff1, eff0;
+       static float *tmptmplen = NULL;
+       static int *hist = NULL;
+       static Bchain *ac = NULL;
+       int im = -1, jm = -1;
+       Bchain *acjmnext, *acjmprev;
+       int prevnode;
+       Bchain *acpti;
+       int *pt1, *pt2, *pt11, *pt22;
+       static int *nmemar;
+       int nmemim, nmemjm;
+       float minscore;
+       int *nearest = NULL; // by D.Mathog, a guess
+       float *mindisfrom = NULL; // by D.Mathog, a guess
+       static char **tree;
+       static char *treetmp;
+       static char *nametmp, *nameptr, *tmpptr;
+       FILE *fp;
+       float (*clusterfuncpt[1])(float,float);
+
+
+       sueff1 = 1 - SUEFF;
+       sueff05 = SUEFF * 0.5;
+       if ( treemethod == 'X' )
+               clusterfuncpt[0] = cluster_mix_float;
+       else if ( treemethod == 'E' )
+               clusterfuncpt[0] = cluster_average_float;
+       else if ( treemethod == 'q' )
+               clusterfuncpt[0] = cluster_minimum_float;
+       else
+       {
+               fprintf( stderr, "Unknown treemethod, %c\n", treemethod );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               hist = AllocateIntVec( njob );
+               tmptmplen = AllocateFloatVec( njob );
+               ac = (Bchain *)malloc( njob * sizeof( Bchain ) );
+               nmemar = AllocateIntVec( njob );
+               mindisfrom = AllocateFloatVec( njob );
+               nearest = AllocateIntVec( njob );
+               treetmp = AllocateCharVec( njob*150 );
+               nametmp = AllocateCharVec( 130 );
+               tree = AllocateCharMtx( njob, njob*150 );
+       }
+
+       
+    for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<130; j++ ) nametmp[j] = 0;
+               for( j=0; j<130; j++ ) 
+               {
+                       if( name[i][j] == 0 )
+                               break;
+                       else if( isalnum( name[i][j] ) )
+                               nametmp[j] = name[i][j];
+                       else
+                               nametmp[j] = '_';
+               }
+               nametmp[129] = 0;
+//             sprintf( tree[i], "%d_l=%d_%.20s", i+1, nlen[i], nametmp+1 );
+               if( outnumber )
+                       nameptr = strstr( nametmp, "_numo_e" ) + 8;
+               else
+                       nameptr = nametmp + 1;
+
+               if( (tmpptr=strstr( nameptr, "_oripos__" )) ) nameptr = tmpptr + 9; // = -> _ no tame
+
+               sprintf( tree[i], "%d_%.60s", i+1, nameptr );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = ac+i+1;
+               ac[i].prev = ac+i-1;
+               ac[i].pos = i;
+       }
+       ac[nseq-1].next = NULL;
+
+       for( i=0; i<nseq; i++ ) setnearest( nseq, ac, eff, mindisfrom+i, nearest+i, i ); // muscle
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               hist[i] = -1;
+               nmemar[i] = 1;
+       }
+
+       fprintf( stderr, "\n" );
+       for( k=0; k<nseq-1; k++ )
+       {
+               if( k % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", k, nseq );
+
+               minscore = 999.9;
+               for( acpti=ac; acpti->next!=NULL; acpti=acpti->next ) 
+               {
+                       i = acpti->pos;
+//                     fprintf( stderr, "k=%d i=%d\n", k, i );
+                       if( mindisfrom[i] < minscore ) // muscle
+                       {
+                               im = i;
+                               minscore = mindisfrom[i];
+                       }
+               }
+               jm = nearest[im];
+               if( jm < im ) 
+               {
+                       j=jm; jm=im; im=j;
+               }
+
+
+               prevnode = hist[im];
+               if( dep ) dep[k].child0 = prevnode;
+               nmemim = nmemar[im];
+               intpt = topol[k][0] = (int *)realloc( topol[k][0], ( nmemim + 1 ) * sizeof( int ) );
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               prevnode = hist[jm];
+               if( dep ) dep[k].child1 = prevnode;
+               nmemjm = nmemar[jm];
+               intpt = topol[k][1] = (int *)realloc( topol[k][1], ( nmemjm + 1 ) * sizeof( int ) );
+               if( !intpt )
+               {
+                       fprintf( stderr, "Cannot reallocate topol\n" );
+                       exit( 1 );
+               }
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = ( minscore - tmptmplen[im] );
+               len[k][1] = ( minscore - tmptmplen[jm] );
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+               nmemar[im] = nmemim + nmemjm;
+
+               mindisfrom[im] = 999.9;
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+        {
+                       i = acpti->pos;
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim-miniim];
+                               eff1 = eff[minijm][maxijm-minijm];
+#if 0
+                               tmpfloat = eff[miniim][maxiim-miniim] =
+                               MIN( eff0, eff1 ) * sueff1 + ( eff0 + eff1 ) * sueff05; 
+#else
+                tmpfloat = eff[miniim][maxiim-miniim] =
+                               (clusterfuncpt[0])( eff0, eff1 );
+#endif
+                               if( tmpfloat < mindisfrom[i]  )
+                               {
+                                       mindisfrom[i] = tmpfloat;
+                                       nearest[i] = im;
+                               }
+                               if( tmpfloat < mindisfrom[im]  )
+                               {
+                                       mindisfrom[im] = tmpfloat;
+                                       nearest[im] = i;
+                               }
+                               if( nearest[i] == jm )
+                               {
+                                       nearest[i] = im;
+                               }
+            }
+        }
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               acjmprev->next = acjmnext;
+               if( acjmnext != NULL )
+                       acjmnext->prev = acjmprev;
+               free( (void *)eff[jm] ); eff[jm] = NULL;
+
+#if 1 // muscle seems to miss this.
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+               {
+                       i = acpti->pos;
+                       if( nearest[i] == im ) 
+                       {
+//                             fprintf( stderr, "calling setnearest\n" );
+                               setnearest( nseq, ac, eff, mindisfrom+i, nearest+i, i );
+                       }
+               }
+#endif
+
+
+#if 0
+        fprintf( stdout, "vSTEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i]+1 );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i]+1 );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fp = fopen( "infile.tree", "w" );
+               fprintf( fp, "%s\n", treetmp );
+       fclose( fp );
+
+       FreeCharMtx( tree );
+       free( treetmp );
+       free( nametmp );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       free( (void *)nmemar ); nmemar = NULL;
+       free( mindisfrom );
+       free( nearest );
+
+}
+
+//void veryfastsupg_double_outtree( int nseq, double **eff, int ***topol, double **len, char **name )
+void fixed_musclesupg_double_treeout( int nseq, double **eff, int ***topol, double **len, char **name )
+{
+       int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       double tmpfloat;
+       double eff1, eff0;
+       static double *tmptmplen = NULL;
+       static int *hist = NULL;
+       static Bchain *ac = NULL;
+       int im = -1, jm = -1;
+       Bchain *acjmnext, *acjmprev;
+       int prevnode;
+       Bchain *acpti;
+       int *pt1, *pt2, *pt11, *pt22;
+       static int *nmemar;
+       int nmemim, nmemjm;
+       double minscore;
+       int *nearest = NULL; // by D.Mathog, a guess
+       double *mindisfrom = NULL; // by D.Mathog, a guess
+       static char **tree;
+       static char *treetmp;
+       static char *nametmp, *nameptr, *tmpptr;
+       FILE *fp;
+       double (*clusterfuncpt[1])(double,double);
+
+
+       sueff1_double = 1 - SUEFF;
+       sueff05_double = SUEFF * 0.5;
+       if ( treemethod == 'X' )
+               clusterfuncpt[0] = cluster_mix_double;
+       else if ( treemethod == 'E' )
+               clusterfuncpt[0] = cluster_average_double;
+       else if ( treemethod == 'q' )
+               clusterfuncpt[0] = cluster_minimum_double;
+       else
+       {
+               fprintf( stderr, "Unknown treemethod, %c\n", treemethod );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               hist = AllocateIntVec( njob );
+               tmptmplen = AllocateDoubleVec( njob );
+               ac = (Bchain *)malloc( njob * sizeof( Bchain ) );
+               nmemar = AllocateIntVec( njob );
+               mindisfrom = AllocateDoubleVec( njob );
+               nearest = AllocateIntVec( njob );
+               treetmp = AllocateCharVec( njob*150 );
+               nametmp = AllocateCharVec( 91 );
+               tree = AllocateCharMtx( njob, njob*150 );
+       }
+
+       
+    for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<90; j++ ) nametmp[j] = 0;
+               for( j=0; j<90; j++ ) 
+               {
+                       if( name[i][j] == 0 )
+                               break;
+                       else if( isalnum( name[i][j] ) )
+                               nametmp[j] = name[i][j];
+                       else
+                               nametmp[j] = '_';
+               }
+               nametmp[90] = 0;
+//             sprintf( tree[i], "%d_%.60s", i+1, nametmp+1 );
+               if( outnumber )
+                       nameptr = strstr( nametmp, "_numo_e" ) + 8;
+               else
+                       nameptr = nametmp + 1;
+
+               if( (tmpptr=strstr( nameptr, "_oripos__" )) ) nameptr = tmpptr + 9; // = -> _ no tame
+
+               sprintf( tree[i], "%d_%.60s", i+1, nameptr );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = ac+i+1;
+               ac[i].prev = ac+i-1;
+               ac[i].pos = i;
+       }
+       ac[nseq-1].next = NULL;
+
+       for( i=0; i<nseq; i++ ) setnearest_double_fullmtx( nseq, ac, eff, mindisfrom+i, nearest+i, i ); // muscle
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               hist[i] = -1;
+               nmemar[i] = 1;
+       }
+
+       fprintf( stderr, "\n" );
+       for( k=0; k<nseq-1; k++ )
+       {
+               if( k % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", k, nseq );
+
+               minscore = 999.9;
+               for( acpti=ac; acpti->next!=NULL; acpti=acpti->next ) 
+               {
+                       i = acpti->pos;
+//                     fprintf( stderr, "k=%d i=%d\n", k, i );
+                       if( mindisfrom[i] < minscore ) // muscle
+                       {
+                               im = i;
+                               minscore = mindisfrom[i];
+                       }
+               }
+               jm = nearest[im];
+               if( jm < im ) 
+               {
+                       j=jm; jm=im; im=j;
+               }
+
+
+               prevnode = hist[im];
+               nmemim = nmemar[im];
+//             intpt = topol[k][0] = (int *)realloc( topol[k][0], ( nmemim + 1 ) * sizeof( int ) );
+               intpt = topol[k][0];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               prevnode = hist[jm];
+               nmemjm = nmemar[jm];
+//             intpt = topol[k][1] = (int *)realloc( topol[k][1], ( nmemjm + 1 ) * sizeof( int ) );
+               intpt = topol[k][1];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = ( minscore - tmptmplen[im] );
+               len[k][1] = ( minscore - tmptmplen[jm] );
+
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+               nmemar[im] = nmemim + nmemjm;
+
+               mindisfrom[im] = 999.9;
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+        {
+                       i = acpti->pos;
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+#if 0
+                               tmpfloat = eff[miniim][maxiim] =
+                               MIN( eff0, eff1 ) * sueff1 + ( eff0 + eff1 ) * sueff05; 
+#else
+                tmpfloat = eff[miniim][maxiim] =
+                               (clusterfuncpt[0])( eff0, eff1 );
+#endif
+                               if( tmpfloat < mindisfrom[i]  )
+                               {
+                                       mindisfrom[i] = tmpfloat;
+                                       nearest[i] = im;
+                               }
+                               if( tmpfloat < mindisfrom[im]  )
+                               {
+                                       mindisfrom[im] = tmpfloat;
+                                       nearest[im] = i;
+                               }
+                               if( nearest[i] == jm )
+                               {
+                                       nearest[i] = im;
+                               }
+            }
+        }
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               acjmprev->next = acjmnext;
+               if( acjmnext != NULL )
+                       acjmnext->prev = acjmprev;
+//             free( (void *)eff[jm] ); eff[jm] = NULL;
+
+#if 1 // muscle seems to miss this.
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+               {
+                       i = acpti->pos;
+                       if( nearest[i] == im ) 
+                       {
+//                             fprintf( stderr, "calling setnearest\n" );
+                               setnearest_double_fullmtx( nseq, ac, eff, mindisfrom+i, nearest+i, i );
+                       }
+               }
+#endif
+
+
+#if 0
+        fprintf( stdout, "vSTEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i]+1 );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i]+1 );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fp = fopen( "infile.tree", "w" );
+               fprintf( fp, "%s\n", treetmp );
+       fclose( fp );
+
+       FreeCharMtx( tree );
+       free( treetmp );
+       free( nametmp );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       free( (void *)nmemar ); nmemar = NULL;
+       free( mindisfrom );
+       free( nearest );
+}
+
+
+void fixed_musclesupg_float_realloc_nobk_halfmtx( int nseq, float **eff, int ***topol, float **len, Treedep *dep )
+{
+       int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       float tmpfloat;
+       float eff1, eff0;
+       static float *tmptmplen = NULL;
+       static int *hist = NULL;
+       static Bchain *ac = NULL;
+       int im = -1, jm = -1;
+       Bchain *acjmnext, *acjmprev;
+       int prevnode;
+       Bchain *acpti;
+       int *pt1, *pt2, *pt11, *pt22;
+       static int *nmemar;
+       int nmemim, nmemjm;
+       float minscore;
+//     float sueff1 = 1 - SUEFF;
+//     float sueff05 = SUEFF * 0.5;
+       int *nearest = NULL; // by Mathog, a guess
+       float *mindisfrom = NULL; // by Mathog, a guess
+       float (*clusterfuncpt[1])(float,float);
+
+
+       sueff1 = 1 - SUEFF;
+       sueff05 = SUEFF * 0.5;
+       if ( treemethod == 'X' )
+               clusterfuncpt[0] = cluster_mix_float;
+       else if ( treemethod == 'E' )
+               clusterfuncpt[0] = cluster_average_float;
+       else if ( treemethod == 'q' )
+               clusterfuncpt[0] = cluster_minimum_float;
+       else
+       {
+               fprintf( stderr, "Unknown treemethod, %c\n", treemethod );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               hist = AllocateIntVec( njob );
+               tmptmplen = AllocateFloatVec( njob );
+               ac = (Bchain *)malloc( njob * sizeof( Bchain ) );
+               nmemar = AllocateIntVec( njob );
+               mindisfrom = AllocateFloatVec( njob );
+               nearest = AllocateIntVec( njob );
+       }
+
+       
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = ac+i+1;
+               ac[i].prev = ac+i-1;
+               ac[i].pos = i;
+       }
+       ac[nseq-1].next = NULL;
+
+       for( i=0; i<nseq; i++ ) setnearest( nseq, ac, eff, mindisfrom+i, nearest+i, i ); // muscle
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               hist[i] = -1;
+               nmemar[i] = 1;
+       }
+
+       fprintf( stderr, "\n" );
+       for( k=0; k<nseq-1; k++ )
+       {
+               if( k % 10 == 0 ) fprintf( stderr, "\r% 5d / %d", k, nseq );
+
+               minscore = 999.9;
+               for( acpti=ac; acpti->next!=NULL; acpti=acpti->next ) 
+               {
+                       i = acpti->pos;
+//                     fprintf( stderr, "k=%d i=%d\n", k, i );
+                       if( mindisfrom[i] < minscore ) // muscle
+                       {
+                               im = i;
+                               minscore = mindisfrom[i];
+                       }
+               }
+               jm = nearest[im];
+               if( jm < im ) 
+               {
+                       j=jm; jm=im; im=j;
+               }
+
+
+               prevnode = hist[im];
+               if( dep ) dep[k].child0 = prevnode;
+               nmemim = nmemar[im];
+               intpt = topol[k][0] = (int *)realloc( topol[k][0], ( nmemim + 1 ) * sizeof( int ) );
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               prevnode = hist[jm];
+               if( dep ) dep[k].child1 = prevnode;
+               nmemjm = nmemar[jm];
+               intpt = topol[k][1] = (int *)realloc( topol[k][1], ( nmemjm + 1 ) * sizeof( int ) );
+               if( !intpt )
+               {
+                       fprintf( stderr, "Cannot reallocate topol\n" );
+                       exit( 1 );
+               }
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = ( minscore - tmptmplen[im] );
+               len[k][1] = ( minscore - tmptmplen[jm] );
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+               nmemar[im] = nmemim + nmemjm;
+
+               mindisfrom[im] = 999.9;
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+        {
+                       i = acpti->pos;
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim-miniim];
+                               eff1 = eff[minijm][maxijm-minijm];
+                               tmpfloat = eff[miniim][maxiim-miniim] =
+#if 0
+                               MIN( eff0, eff1 ) * sueff1 + ( eff0 + eff1 ) * sueff05; 
+#else
+                               (clusterfuncpt[0])( eff0, eff1 );
+#endif
+                               if( tmpfloat < mindisfrom[i]  )
+                               {
+                                       mindisfrom[i] = tmpfloat;
+                                       nearest[i] = im;
+                               }
+                               if( tmpfloat < mindisfrom[im]  )
+                               {
+                                       mindisfrom[im] = tmpfloat;
+                                       nearest[im] = i;
+                               }
+                               if( nearest[i] == jm )
+                               {
+                                       nearest[i] = im;
+                               }
+            }
+        }
+
+//             fprintf( stderr, "im,jm=%d,%d\n", im, jm );
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               acjmprev->next = acjmnext;
+               if( acjmnext != NULL )
+                       acjmnext->prev = acjmprev;
+               free( (void *)eff[jm] ); eff[jm] = NULL;
+
+#if 1 // muscle seems to miss this.
+               for( acpti=ac; acpti!=NULL; acpti=acpti->next )
+               {
+                       i = acpti->pos;
+                       if( nearest[i] == im ) 
+                       {
+//                             fprintf( stderr, "calling setnearest\n" );
+                               setnearest( nseq, ac, eff, mindisfrom+i, nearest+i, i );
+                       }
+               }
+#endif
+
+
+#if 0
+        fprintf( stdout, "vSTEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i]+1 );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i]+1 );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       free( (void *)nmemar ); nmemar = NULL;
+       free( mindisfrom );
+       free( nearest );
+}
+
+
+
+
+
+
+
+
+void veryfastsupg_double_loadtop( int nseq, double **eff, int ***topol, double **len ) // BUG!!!
+{
+    int i, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       double eff1, eff0;
+       static double *tmptmplen = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       double minscore;
+       static char **tree;
+       static char *treetmp;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+       FILE *fp;
+       int node[2];
+       float dumfl[2];
+
+       fp = fopen( "_guidetree", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "cannot open _guidetree\n" );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               treetmp = AllocateCharVec( njob*50 );
+               tree = AllocateCharMtx( njob, njob*50 );
+               hist = AllocateIntVec( njob );
+               tmptmplen = (double *)malloc( njob * sizeof( double ) );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+       }
+       for( i=0; i<nseq; i++ ) sprintf( tree[i], "%d", i+1 );
+       
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+#if 0
+               minscore = 99999.9;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpdouble = eff[i][j];
+                               if( tmpdouble < minscore )
+                               {
+                                       minscore = tmpdouble;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+#else
+               dumfl[0] = dumfl[1] = -1.0;
+               loadtreeoneline( node, dumfl, fp );
+               im = node[0];
+               jm = node[1];
+               minscore = eff[im][jm];
+
+//             fprintf( stderr, "im=%d, jm=%d, minscore = %f\n", im, jm, minscore );
+
+
+               if( dumfl[0] != -1.0 || dumfl[1] != -1.0 )
+               {
+                       fprintf( stderr, "\n\nBranch length should not given.\n" );
+                       exit( 1 );
+               }
+#endif
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = minscore - tmptmplen[im];
+               len[k][1] = minscore - tmptmplen[jm];
+
+               if( len[k][0] < 0.0 ) len[k][0] = 0.0;
+               if( len[k][1] < 0.0 ) len[k][1] = 0.0;
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fclose( fp );
+
+       fp = fopen( "infile.tree", "w" );
+       fprintf( fp, "%s\n", treetmp );
+//     fprintf( fp, "by veryfastsupg_double_loadtop\n" );
+       fclose( fp );
+
+#if 1
+       fprintf( stderr, "\n" );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       FreeCharMtx( tree );
+       free( treetmp );
+#endif
+}
+
+void veryfastsupg_double_loadtree( int nseq, double **eff, int ***topol, double **len )
+{
+    int i, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       double eff1, eff0;
+       static double *tmptmplen = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       double minscore;
+       static char **tree;
+       static char *treetmp;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+       FILE *fp;
+       int node[2];
+       float lenfl[2];
+
+       fp = fopen( "_guidetree", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "cannot open _guidetree\n" );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               treetmp = AllocateCharVec( njob*50 );
+               tree = AllocateCharMtx( njob, njob*50 );
+               hist = AllocateIntVec( njob );
+               tmptmplen = (double *)malloc( njob * sizeof( double ) );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+       }
+
+       for( i=0; i<nseq; i++ ) sprintf( tree[i], "%d", i+1 );
+       
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+#if 0
+               minscore = 99999.9;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpdouble = eff[i][j];
+                               if( tmpdouble < minscore )
+                               {
+                                       minscore = tmpdouble;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+#else
+               lenfl[0] = lenfl[1] = -1.0;
+               loadtreeoneline( node, lenfl, fp );
+               im = node[0];
+               jm = node[1];
+               minscore = eff[im][jm];
+
+//             fprintf( stderr, "im=%d, jm=%d, minscore = %f\n", im, jm, minscore );
+
+
+               if( lenfl[0] == -1.0 || lenfl[1] == -1.0 )
+               {
+                       fprintf( stderr, "\n\nWARNING: Branch length is not given.\n" );
+                       exit( 1 );
+               }
+
+               if( lenfl[0] < 0.0 ) lenfl[0] = 0.0;
+               if( lenfl[1] < 0.0 ) lenfl[1] = 0.0;
+#endif
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+#if 0
+               len[k][0] = minscore - tmptmplen[im];
+               len[k][1] = minscore - tmptmplen[jm];
+#else
+               len[k][0] = lenfl[0];
+               len[k][1] = lenfl[1];
+#endif
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fclose( fp );
+
+
+       fp = fopen( "infile.tree", "w" );
+       fprintf( fp, "%s\n", treetmp );
+//     fprintf( fp, "by veryfastsupg_double_loadtree\n" );
+       fclose( fp );
+
+#if 1
+       fprintf( stderr, "\n" );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       FreeCharMtx( tree );
+       free( treetmp );
+#endif
+
+
+}
+
+#if 0
+void veryfastsupg_double( int nseq, double **eff, int ***topol, double **len )
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       double tmpdouble;
+       double eff1, eff0;
+       static double *tmptmplen = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       double minscore;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+       if( !hist )
+       {
+               hist = AllocateIntVec( njob );
+               tmptmplen = (double *)malloc( njob * sizeof( double ) );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+       }
+       
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+               minscore = 99999.9;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpdouble = eff[i][j];
+                               if( tmpdouble < minscore )
+                               {
+                                       minscore = tmpdouble;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = minscore - tmptmplen[im];
+               len[k][1] = minscore - tmptmplen[jm];
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+#if 1
+       fprintf( stderr, "\n" );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+#endif
+}
+#endif
+
+void veryfastsupg_double_outtree( int nseq, double **eff, int ***topol, double **len, char **name )
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       double tmpdouble;
+       double eff1, eff0;
+       static double *tmptmplen = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       double minscore;
+       static char **tree;
+       static char *treetmp;
+       static char *nametmp;
+       FILE *fpout;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+       double (*clusterfuncpt[1])(double,double);
+
+
+       sueff1_double = 1 - SUEFF;
+       sueff05_double = SUEFF * 0.5;
+       if ( treemethod == 'X' )
+               clusterfuncpt[0] = cluster_mix_double;
+       else if ( treemethod == 'E' )
+               clusterfuncpt[0] = cluster_average_double;
+       else if ( treemethod == 'q' )
+               clusterfuncpt[0] = cluster_minimum_double;
+       else
+       {
+               fprintf( stderr, "Unknown treemethod, %c\n", treemethod );
+               exit( 1 );
+       }
+
+       if( !hist )
+       {
+               treetmp = AllocateCharVec( njob*50 );
+               tree = AllocateCharMtx( njob, njob*50 );
+               hist = AllocateIntVec( njob );
+               tmptmplen = (double *)malloc( njob * sizeof( double ) );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+               nametmp = AllocateCharVec( 31 );
+       }
+
+//     for( i=0; i<nseq; i++ ) sprintf( tree[i], "%d", i+1 );
+    for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<30; j++ ) nametmp[j] = 0;
+               for( j=0; j<30; j++ ) 
+               {
+                       if( isalnum( name[i][j] ) )
+                               nametmp[j] = name[i][j];
+                       else
+                               nametmp[j] = '_';
+               }
+               nametmp[30] = 0;
+               sprintf( tree[i], "%d_%.20s", i+1, nametmp+1 );
+       }
+       
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+               minscore = 99999.9;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpdouble = eff[i][j];
+                               if( tmpdouble < minscore )
+                               {
+                                       minscore = tmpdouble;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = minscore - tmptmplen[im];
+               len[k][1] = minscore - tmptmplen[jm];
+
+               tmptmplen[im] = minscore;
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+#if 0
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+#else
+                eff[miniim][maxiim] =
+                               (clusterfuncpt[0])( eff0, eff1 );
+#endif
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+
+               sprintf( treetmp, "(%s:%7.5f,%s:%7.5f)", tree[im], len[k][0], tree[jm], len[k][1] );
+               strcpy( tree[im], treetmp );
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       fpout = fopen( "infile.tree", "w" );
+       fprintf( fpout, "%s\n", treetmp );
+//     fprintf( fpout, "by veryfastsupg_double_outtree\n" );
+       fclose( fpout );
+#if 1
+       fprintf( stderr, "\n" );
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+       FreeCharMtx( tree );
+       free( treetmp );
+       free( nametmp );
+#endif
+}
+
+void veryfastsupg( int nseq, double **oeff, int ***topol, double **len )
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       int tmpint;
+       int eff1, eff0;
+       static double *tmptmplen = NULL;
+       static int **eff = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       int minscore;
+       double minscoref;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+       if( !eff )
+       {
+               eff = AllocateIntMtx( njob, njob );
+               hist = AllocateIntVec( njob );
+               tmptmplen = (double *)malloc( njob * sizeof( double ) );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+       }
+       
+       for( i=0; i<nseq; i++ ) 
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       eff[i][j] = (int)( oeff[i][j] * INTMTXSCALE + 0.5 );
+               }
+       }
+
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+               minscore = INTMTXSCALE*4;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpint = eff[i][j];
+                               if( tmpint < minscore )
+                               {
+                                       minscore = tmpint;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+               minscoref = (double)minscore * 0.5 / ( INTMTXSCALE );
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+#if 1
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+#else
+               intpt = topol[k][0];
+        for( i=0; i<nseq; i++ )
+            if( pair[im][i] > -2 )
+                               *intpt++ = i;
+               *intpt = -1;
+
+               intpt = topol[k][1];
+        for( i=0; i<nseq; i++ )
+            if( pair[jm][i] > -2 )
+                               *intpt++ = i;
+               *intpt = -1;
+#endif
+
+               len[k][0] = minscoref - tmptmplen[im];
+               len[k][1] = minscoref - tmptmplen[jm];
+
+               tmptmplen[im] = minscoref;
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+#if 1
+       FreeIntMtx( eff ); eff = NULL;
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+#endif
+}
+void veryfastsupg_int( int nseq, int **oeff, int ***topol, double **len )
+/* len\e$B$O!"\e(B oeff\e$B$,@0?t!#\e(Blen\e$B$b<B$O@0?t!#\e(B
+   \e$BI,MW$K1~$8$F3d$C$F;H$&!#\e(B */
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+       int *intpt, *intpt2;
+       int tmpint;
+       int eff1, eff0;
+       static int *tmptmplen = NULL;
+       static int **eff = NULL;
+    static int *hist = NULL;
+       static Achain *ac = NULL;
+       int minscore;
+       int im = -1, jm = -1;
+       int prevnode, acjmnext, acjmprev;
+       int *pt1, *pt2, *pt11, *pt22;
+
+
+       if( !eff )
+       {
+               eff = AllocateIntMtx( njob, njob );
+               hist = AllocateIntVec( njob );
+               tmptmplen = AllocateIntVec( njob );
+               ac = (Achain *)malloc( njob * sizeof( Achain ) );
+       }
+       
+       for( i=0; i<nseq; i++ ) 
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       eff[i][j] = ( oeff[i][j] );
+               }
+       }
+
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmptmplen[i] = 0;
+    for( i=0; i<nseq; i++ ) hist[i] = -1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+               minscore = INTMTXSCALE*4;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+               {
+                               tmpint = eff[i][j];
+                               if( tmpint < minscore )
+                               {
+                                       minscore = tmpint;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+               prevnode = hist[im];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = im;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               intpt = topol[k][1];
+               prevnode = hist[jm];
+               if( prevnode == -1 )
+               {
+                       *intpt++ = jm;
+                       *intpt = -1;
+               }
+               else
+               {
+                       pt1 = topol[prevnode][0];
+                       pt2 = topol[prevnode][1];
+                       if( *pt1 > *pt2 )
+                       {
+                               pt11 = pt2;
+                               pt22 = pt1;
+                       }
+                       else
+                       {
+                               pt11 = pt1;
+                               pt22 = pt2;
+                       }
+                       for( intpt2=pt11; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       for( intpt2=pt22; *intpt2!=-1; )
+                               *intpt++ = *intpt2++;
+                       *intpt = -1;
+               }
+
+               minscore *= 0.5;
+
+               len[k][0] = (double)( minscore - tmptmplen[im] );
+               len[k][1] = (double)( minscore - tmptmplen[jm] );
+
+               tmptmplen[im] = minscore;
+
+#if 0
+               free( tmptmplen );
+               tmptmplen = AllocateIntVec( nseq );
+#endif
+
+
+               hist[im] = k;
+
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                               (int) ( (float)MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) + (float)( eff0 + eff1 ) * 0.5 * SUEFF );
+            }
+        }
+               acjmprev = ac[jm].prev; 
+               acjmnext = ac[jm].next; 
+               ac[acjmprev].next = acjmnext;
+               if( acjmnext != -1 )
+                       ac[acjmnext].prev = acjmprev;
+#if 0
+        fprintf( stdout, "STEP-%03d:\n", k+1 );
+               fprintf( stdout, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][0][i] );
+        fprintf( stdout, "\n" );
+               fprintf( stdout, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stdout, " %03d", topol[k][1][i] );
+        fprintf( stdout, "\n" );
+#endif
+    }
+       FreeIntMtx( eff ); eff = NULL;
+       free( (void *)tmptmplen ); tmptmplen = NULL;
+       free( hist ); hist = NULL;
+       free( (char *)ac ); ac = NULL;
+}
+void fastsupg( int nseq, double **oeff, int ***topol, double **len )
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+#if 0
+       double eff[nseq][nseq];
+    char pair[njob][njob];
+#else
+       static float *tmplen;
+       int *intpt;
+       float tmpfloat;
+       float eff1, eff0;
+       static float **eff = NULL;
+    static char **pair = NULL;
+       static Achain *ac;
+       float minscore;
+       int im = -1, jm = -1;
+       if( !eff )
+       {
+               eff = AllocateFloatMtx( njob, njob );
+               pair = AllocateCharMtx( njob, njob );
+               tmplen = AllocateFloatVec( njob );
+               ac = (Achain *)calloc( njob, sizeof( Achain ) );
+       }
+#endif
+       
+       for( i=0; i<nseq; i++ ) 
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       eff[i][j] = (float)oeff[i][j];
+               }
+       }
+
+       for( i=0; i<nseq; i++ )
+       {
+               ac[i].next = i+1;
+               ac[i].prev = i-1;
+//             ac[i].curr = i;
+       }
+       ac[nseq-1].next = -1;
+
+       for( i=0; i<nseq; i++ ) tmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) pair[i][j] = 0;
+    for( i=0; i<nseq; i++ ) pair[i][i] = 1;
+
+       fprintf( stderr, "\n" );
+    for( k=0; k<nseq-1; k++ )
+    {
+               if( k % 10 == 0 ) fprintf( stderr, "%d / %d\r", k, nseq );
+
+               minscore = 9999.0;
+               for( i=0; ac[i].next!=-1; i=ac[i].next ) 
+//             for( i=0; i<nseq-1; i++ ) 
+               {
+                       for( j=ac[i].next; j!=-1; j=ac[j].next )
+//                     for( j=i+1; j<nseq; j++ ) 
+               {
+                               tmpfloat = eff[i][j];
+                               if( tmpfloat < minscore )
+                               {
+                                       minscore = tmpfloat;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+
+//             fprintf( stderr, "im=%d, jm=%d\n", im, jm );
+
+               intpt = topol[k][0];
+        for( i=0; i<nseq; i++ )
+            if( pair[im][i] > 0 )
+                               *intpt++ = i;
+               *intpt = -1;
+
+               intpt = topol[k][1];
+        for( i=0; i<nseq; i++ )
+            if( pair[jm][i] > 0 )
+                               *intpt++ = i;
+               *intpt = -1;
+
+               minscore /= 2.0;
+
+               len[k][0] = (double)minscore - tmplen[im];
+               len[k][1] = (double)minscore - tmplen[jm];
+
+               tmplen[im] = (double)minscore;
+
+        for( i=0; i<nseq; i++ ) pair[im][i] += ( pair[jm][i] > 0 );
+        for( i=0; i<nseq; i++ ) pair[jm][i] = 0;
+
+//             for( i=0; i<nseq; i++ )
+               for( i=0; i!=-1; i=ac[i].next )
+        {
+            if( i != im && i != jm )
+            {
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+//                     eff[minijm][maxijm] = 9999.0;
+            }
+        }
+               ac[ac[jm].prev].next = ac[jm].next;
+               ac[ac[jm].next].prev = ac[jm].prev;
+//             eff[im][jm] = 9999.0;
+#if 0
+        fprintf( stderr, "STEP-%03d:\n", k+1 );
+               fprintf( stderr, "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) fprintf( stderr, " %03d", topol[k][0][i] );
+        fprintf( stderr, "\n" );
+               fprintf( stderr, "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) fprintf( stderr, " %03d", topol[k][1][i] );
+        fprintf( stderr, "\n" );
+#endif
+    }
+       fprintf( stderr, "\n" );
+
+//     FreeFloatMtx( eff );
+//     FreeCharMtx( pair );
+//     FreeFloatVec( tmplen );
+//     free( ac );
+}
+void supg( int nseq, double **oeff, int ***topol, double **len )
+{
+    int i, j, k, miniim, maxiim, minijm, maxijm;
+#if 0
+       double eff[nseq][nseq];
+    char pair[njob][njob];
+#else
+       static float *tmplen;
+       int *intpt;
+       float **floatptpt;
+       float *floatpt;
+       float tmpfloat;
+       float eff1, eff0;
+       static float **eff = NULL;
+    static char **pair = NULL;
+       if( !eff )
+       {
+               eff = AllocateFloatMtx( njob, njob );
+               pair = AllocateCharMtx( njob, njob );
+               tmplen = AllocateFloatVec( njob );
+       }
+#endif
+
+       
+       for( i=0; i<nseq; i++ ) 
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       eff[i][j] = (float)oeff[i][j];
+               }
+       }
+       for( i=0; i<nseq; i++ ) tmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) pair[i][j] = 0;
+    for( i=0; i<nseq; i++ ) pair[i][i] = 1;
+
+    for( k=0; k<nseq-1; k++ )
+    {
+        float minscore = 9999.0;
+        int im = -1, jm = -1;
+
+
+               floatptpt = eff;
+        for( i=0; i<nseq-1; i++ ) 
+               {
+                       floatpt = *floatptpt++ + i + 1;
+                       for( j=i+1; j<nseq; j++ )
+               {
+                               tmpfloat = *floatpt++;
+                               if( tmpfloat < minscore )
+                               {
+                                       minscore = tmpfloat;
+                                       im = i; jm = j;
+                               }
+                       }
+               }
+               intpt = topol[k][0];
+        for( i=0; i<nseq; i++ )
+            if( pair[im][i] > 0 )
+                               *intpt++ = i;
+               *intpt = -1;
+
+               intpt = topol[k][1];
+        for( i=0; i<nseq; i++ )
+            if( pair[jm][i] > 0 )
+                               *intpt++ = i;
+               *intpt = -1;
+
+               len[k][0] = (double)minscore / 2.0 - tmplen[im];
+               len[k][1] = (double)minscore / 2.0 - tmplen[jm];
+
+               tmplen[im] = (double)minscore / 2.0;
+
+        for( i=0; i<nseq; i++ ) pair[im][i] += ( pair[jm][i] > 0 );
+        for( i=0; i<nseq; i++ ) pair[jm][i] = 0;
+
+        for( i=0; i<nseq; i++ )
+        {
+            if( i != im && i != jm )
+            {
+#if 1
+                               if( i < im )
+                               {
+                                        miniim = i;
+                                        maxiim = im;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else if( i < jm )
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = i;
+                                        maxijm = jm;
+                               }
+                               else
+                               {
+                                        miniim = im;
+                                        maxiim = i;
+                                        minijm = jm;
+                                        maxijm = i;
+                               }
+#else
+                               miniim = MIN( i, im );
+                               maxiim = MAX( i, im );
+                               minijm = MIN( i, jm );
+                               maxijm = MAX( i, jm );
+#endif
+#if 1
+                               eff0 = eff[miniim][maxiim];
+                               eff1 = eff[minijm][maxijm];
+                eff[miniim][maxiim] =
+                MIN( eff0, eff1 ) * ( 1.0 - SUEFF ) +
+                               ( eff0 + eff1 ) * 0.5 * SUEFF;
+#else
+                MIN( eff[miniim][maxiim], eff[minijm][maxijm] ) * ( 1.0 - SUEFF ) +
+                               ( eff[miniim][maxiim] + eff[minijm][maxijm] ) * 0.5 * SUEFF;
+#endif
+                eff[minijm][maxijm] = 9999.0;
+               eff[im][jm] = 9999.0;
+            }
+        }
+#if DEBUG
+        printf( "STEP-%03d:\n", k+1 );
+               printf( "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) printf( " %03d", topol[k][0][i] );
+        printf( "\n" );
+               printf( "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) printf( " %03d", topol[k][1][i] );
+        printf( "\n" );
+#endif
+    }
+}
+
+void spg( int nseq, double **oeff, int ***topol, double **len )
+{
+    int i, j, k;
+       double tmplen[M];
+#if 0
+       double eff[nseq][nseq];
+    char pair[njob][njob];
+#else
+       double **eff = NULL;
+    char **pair = NULL;
+       if( !eff )
+       {
+               eff = AllocateDoubleMtx( njob, njob );
+               pair = AllocateCharMtx( njob, njob );
+       }
+#endif
+       
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) eff[i][j] = oeff[i][j];
+       for( i=0; i<nseq; i++ ) tmplen[i] = 0.0;
+    for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) pair[i][j] = 0;
+    for( i=0; i<nseq; i++ ) pair[i][i] = 1;
+
+    for( k=0; k<nseq-1; k++ )
+    {
+        float minscore = 9999.0;
+        int im = -1, jm = -1;
+        int count;
+
+        for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+        {
+            if( eff[i][j] < minscore )
+            {
+                minscore = eff[i][j];
+                im = i; jm = j;
+            }
+        }
+        for( i=0, count=0; i<nseq; i++ )
+            if( pair[im][i] > 0 )
+            {
+                topol[k][0][count] = i;
+                count++;
+            }
+        topol[k][0][count] = -1;
+        for( i=0, count=0; i<nseq; i++ )
+            if( pair[jm][i] > 0 )
+            {
+                topol[k][1][count] = i;
+                count++;
+            }
+        topol[k][1][count] = -1;
+
+               len[k][0] = minscore / 2.0 - tmplen[im];
+               len[k][1] = minscore / 2.0 - tmplen[jm];
+
+               tmplen[im] = minscore / 2.0;
+
+        for( i=0; i<nseq; i++ ) pair[im][i] += ( pair[jm][i] > 0 );
+        for( i=0; i<nseq; i++ ) pair[jm][i] = 0;
+
+        for( i=0; i<nseq; i++ )
+        {
+            if( i != im && i != jm )
+            {
+                eff[MIN(i,im)][MAX(i,im)] =
+                MIN( eff[MIN(i,im)][MAX(i,im)], eff[MIN(i,jm)][MAX(i,jm)] );
+                eff[MIN(i,jm)][MAX(i,jm)] = 9999.0;
+            }
+            eff[im][jm] = 9999.0;
+        }
+#if DEBUG
+        printf( "STEP-%03d:\n", k+1 );
+               printf( "len0 = %f\n", len[k][0] );
+        for( i=0; topol[k][0][i]>-1; i++ ) printf( " %03d", topol[k][0][i] );
+        printf( "\n" );
+               printf( "len1 = %f\n", len[k][1] );
+        for( i=0; topol[k][1][i]>-1; i++ ) printf( " %03d", topol[k][1][i] );
+        printf( "\n" );
+#endif
+    }
+}
+
+double ipower( double x, int n )    /* n > 0  */
+{
+    double r;
+
+    r = 1;
+    while( n != 0 )
+    {
+        if( n & 1 ) r *= x;
+        x *= x; n >>= 1;
+    }
+    return( r );
+}
+
+void countnode( int nseq, int ***topol, double **node ) /* node[j][i] != node[i][j] */
+{
+    int i, j, k, s1, s2;
+    static double rootnode[M];
+
+    if( nseq-2 < 0 )
+       {
+               fprintf( stderr, "Too few sequence for countnode: nseq = %d\n", nseq );
+               exit( 1 );
+    }
+
+    for( i=0; i<nseq; i++ ) rootnode[i] = 0;
+    for( i=0; i<nseq-2; i++ )
+    {
+        for( j=0; topol[i][0][j]>-1; j++ )
+            rootnode[topol[i][0][j]]++;
+        for( j=0; topol[i][1][j]>-1; j++ )
+            rootnode[topol[i][1][j]]++;
+        for( j=0; topol[i][0][j]>-1; j++ )
+        {
+            s1 = topol[i][0][j];
+            for( k=0; topol[i][1][k]>-1; k++ )
+            {
+                s2 = topol[i][1][k];
+                node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2] - 1;
+            }
+        }
+    }
+    for( j=0; topol[nseq-2][0][j]>-1; j++ )
+    {
+        s1 = topol[nseq-2][0][j];
+        for( k=0; topol[nseq-2][1][k]>-1; k++ )
+        {
+            s2 = topol[nseq-2][1][k];
+            node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2];
+        }
+    }
+}
+
+void countnode_int( int nseq, int ***topol, int **node )  /* node[i][j] == node[j][i] */
+{
+    int i, j, k, s1, s2;
+    int rootnode[M];
+
+    for( i=0; i<nseq; i++ ) rootnode[i] = 0;
+    for( i=0; i<nseq-2; i++ )
+    {
+        for( j=0; topol[i][0][j]>-1; j++ )
+            rootnode[topol[i][0][j]]++;
+        for( j=0; topol[i][1][j]>-1; j++ )
+            rootnode[topol[i][1][j]]++;
+        for( j=0; topol[i][0][j]>-1; j++ )
+        {
+            s1 = topol[i][0][j];
+            for( k=0; topol[i][1][k]>-1; k++ )
+            {
+                s2 = topol[i][1][k];
+                node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2] - 1;
+            }
+        }
+    }
+    for( j=0; topol[nseq-2][0][j]>-1; j++ )
+    {
+        s1 = topol[nseq-2][0][j];
+        for( k=0; topol[nseq-2][1][k]>-1; k++ )
+        {
+            s2 = topol[nseq-2][1][k];
+            node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2];
+        }
+    }
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ ) 
+               node[j][i] = node[i][j];
+#if DEBUG
+       fprintf( stderr, "node[][] in countnode_int" );
+       for( i=0; i<nseq; i++ ) 
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       fprintf( stderr, "%#3d", node[i][j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+#endif
+}
+
+void counteff_simple_float( int nseq, int ***topol, float **len, double *node )
+{
+    int i, j, s1, s2;
+       double total;
+       static double rootnode[M];
+       static double eff[M];
+
+#if DEBUG
+       for( i=0; i<nseq; i++ ){
+               fprintf( stderr, "len0 = %f\n", len[i][0] );
+               fprintf( stderr, "len1 = %f\n", len[i][1] );
+       }
+#endif
+    for( i=0; i<nseq; i++ )
+       {
+               rootnode[i] = 0.0;
+               eff[i] = 1.0;
+/*
+               rootnode[i] = 1.0;
+*/
+       }
+       for( i=0; i<nseq-1; i++ )
+       {
+               for( j=0; (s1=topol[i][0][j]) > -1; j++ )
+               {
+               rootnode[s1] += (double)len[i][0] * eff[s1];
+                       eff[s1] *= 0.5;
+/*
+               rootnode[s1] *= 0.5;
+*/
+                       
+               }
+               for( j=0; (s2=topol[i][1][j]) > -1; j++ )
+               {
+               rootnode[s2] +=  (double)len[i][1] * eff[s2];
+                       eff[s2] *= 0.5;
+/*
+               rootnode[s2] *= 0.5;
+*/
+                               
+               }
+       }
+       for( i=0; i<nseq; i++ ) 
+       {
+#if 1 /* 97.9.29 */
+               rootnode[i] += GETA3;
+#endif
+#if 0
+               fprintf( stderr, "### rootnode for %d = %f\n", i, rootnode[i] );
+#endif
+       }
+#if 1
+       total = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               total += rootnode[i];
+       }
+#else
+       total = 1.0;
+#endif
+               
+       for( i=0; i<nseq; i++ ) 
+       {
+               node[i] = rootnode[i] / total;
+       }
+
+#if 0
+       fprintf( stderr, "weight array in counteff_simple\n" );
+       for( i=0; i<nseq; i++ )
+               fprintf( stderr, "%f\n", node[i] );
+       printf( "\n" );
+       exit( 1 );
+#endif
+}
+
+void counteff_simple( int nseq, int ***topol, double **len, double *node )
+{
+    int i, j, s1, s2;
+       double total;
+       static double rootnode[M];
+       static double eff[M];
+
+#if DEBUG
+       for( i=0; i<nseq; i++ ){
+               fprintf( stderr, "len0 = %f\n", len[i][0] );
+               fprintf( stderr, "len1 = %f\n", len[i][1] );
+       }
+#endif
+    for( i=0; i<nseq; i++ )
+       {
+               rootnode[i] = 0.0;
+               eff[i] = 1.0;
+/*
+               rootnode[i] = 1.0;
+*/
+       }
+       for( i=0; i<nseq-1; i++ )
+       {
+               for( j=0; (s1=topol[i][0][j]) > -1; j++ )
+               {
+               rootnode[s1] += len[i][0] * eff[s1];
+                       eff[s1] *= 0.5;
+/*
+               rootnode[s1] *= 0.5;
+*/
+                       
+               }
+               for( j=0; (s2=topol[i][1][j]) > -1; j++ )
+               {
+               rootnode[s2] +=  len[i][1] * eff[s2];
+                       eff[s2] *= 0.5;
+/*
+               rootnode[s2] *= 0.5;
+*/
+                               
+               }
+       }
+       for( i=0; i<nseq; i++ ) 
+       {
+#if 1 /* 97.9.29 */
+               rootnode[i] += GETA3;
+#endif
+#if 0
+               fprintf( stderr, "### rootnode for %d = %f\n", i, rootnode[i] );
+#endif
+       }
+#if 1
+       total = 0.0;
+       for( i=0; i<nseq; i++ ) 
+       {
+               total += rootnode[i];
+       }
+#else
+       total = 1.0;
+#endif
+               
+       for( i=0; i<nseq; i++ ) 
+       {
+               node[i] = rootnode[i] / total;
+       }
+
+#if 0
+       fprintf( stderr, "weight array in counteff_simple\n" );
+       for( i=0; i<nseq; i++ )
+               fprintf( stderr, "%f\n", node[i] );
+       printf( "\n" );
+       exit( 1 );
+#endif
+}
+
+
+void counteff( int nseq, int ***topol, double **len, double **node )
+{
+    int i, j, k, s1, s2;
+       double rootnode[M];
+       double eff[M];
+
+       if( mix ) 
+       {
+               switch( weight )
+               {
+                       case( 2 ): 
+                               weight = 3;
+                               break;
+                       case( 3 ): 
+                               weight = 2;
+                               break;
+                       default: 
+                               ErrorExit( "mix error" );
+                               break;
+               }
+       }
+
+       if( weight == 2 )
+       {
+           for( i=0; i<nseq; i++ ) rootnode[i] = 0;
+       for( i=0; i<nseq-2; i++ )
+       {
+               for( j=0; topol[i][0][j]>-1; j++ )
+               rootnode[topol[i][0][j]]++;
+               for( j=0; topol[i][1][j]>-1; j++ )
+               rootnode[topol[i][1][j]]++;
+               for( j=0; topol[i][0][j]>-1; j++ )
+               {
+               s1 = topol[i][0][j];
+               for( k=0; topol[i][1][k]>-1; k++ )
+               {
+                       s2 = topol[i][1][k];
+                       node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2] - 1;
+               }
+               }
+       }
+       for( j=0; topol[nseq-2][0][j]>-1; j++ )
+       {
+               s1 = topol[nseq-2][0][j];
+               for( k=0; topol[nseq-2][1][k]>-1; k++ )
+               {
+               s2 = topol[nseq-2][1][k];
+               node[MIN(s1,s2)][MAX(s1,s2)] = rootnode[s1] + rootnode[s2];
+               }
+       }
+               for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+                       node[i][j] = ipower( 0.5, (int)node[i][j] ) + geta2;
+               for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ ) 
+                       node[j][i] = node[i][j];
+       }
+
+       if( weight == 3 )
+       {
+#if DEBUG
+               for( i=0; i<nseq; i++ ){
+                       fprintf( stderr, "len0 = %f\n", len[i][0] );
+                       fprintf( stderr, "len1 = %f\n", len[i][1] );
+               }
+#endif
+           for( i=0; i<nseq; i++ )
+               {
+                       rootnode[i] = 0.0;
+                       eff[i] = 1.0;
+/*
+                       rootnode[i] = 1.0;
+*/
+               }
+       for( i=0; i<nseq-1; i++ )
+       {
+               for( j=0; (s1=topol[i][0][j]) > -1; j++ )
+                       {
+                       rootnode[s1] += len[i][0] * eff[s1];
+                               eff[s1] *= 0.5;
+/*
+                       rootnode[s1] *= 0.5;
+*/
+                               
+                       }
+               for( j=0; (s2=topol[i][1][j]) > -1; j++ )
+                       {
+                       rootnode[s2] +=  len[i][1] * eff[s2];
+                               eff[s2] *= 0.5;
+/*
+                       rootnode[s2] *= 0.5;
+*/
+                               
+                       }
+               }
+               for( i=0; i<nseq; i++ ) 
+               {
+#if 1 /* 97.9.29 */
+                       rootnode[i] += GETA3;
+#endif
+#if DEBUG
+                       fprintf( stderr, "rootnode for %d = %f\n", i, rootnode[i] );
+#endif
+               }
+               for( i=0; i<nseq; i++ ) 
+               {
+                       for( j=0; j<nseq; j++ ) 
+                               if( j != i )
+                                       node[i][j] = (double)rootnode[i] * rootnode[j];
+                               else node[i][i] = rootnode[i];
+               }
+       }
+
+#if 0
+       printf( "weight matrix in counteff\n" );
+       for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<nseq; j++ ) 
+               {
+                       printf( "%f ", node[i][j] );
+               }
+               printf( "\n" );
+       }
+#endif
+}
+
+float score_calcp( char *seq1, char *seq2, int len )
+{
+       int k;
+       int ms1, ms2;
+       float tmpscore;
+       int len2 = len - 2;
+
+       tmpscore = 0.0;
+       for( k=0; k<len; k++ )
+       {
+               ms1 = (int)seq1[k];
+               ms2 = (int)seq2[k];
+               if( ms1 == (int)'-' && ms2 == (int)'-' ) continue;
+               tmpscore += (float)amino_dis[ms1][ms2];
+       
+               if( ms1 == (int)'-' ) 
+               {
+                       tmpscore += (float)penalty;
+                       tmpscore += (float)amino_dis[ms1][ms2];
+                       while( (ms1=(int)seq1[++k]) == (int)'-' )
+                               tmpscore += (float)amino_dis[ms1][ms2];
+                       k--;
+                       if( k >len2 ) break;
+                       continue;
+               }
+               if( ms2 == (int)'-' )
+               {
+                       tmpscore += (float)penalty;
+                       tmpscore += (float)amino_dis[ms1][ms2];
+                       while( (ms2=(int)seq2[++k]) == (int)'-' )
+                               tmpscore += (float)amino_dis[ms1][ms2];
+                       k--;
+                       if( k > len2 ) break;
+                       continue;
+               }
+       }
+       return( tmpscore );
+}
+
+float score_calc1( char *seq1, char *seq2 )   /* method 1 */
+{
+       int k;
+       float score = 0.0;
+       int count = 0;
+       int len = strlen( seq1 );
+
+       for( k=0; k<len; k++ )
+       {       
+               if( seq1[k] != '-' && seq2[k] != '-' )
+               {
+                       score += (float)amino_dis[(int)seq1[k]][(int)seq2[k]];
+                       count++;
+               }
+       }
+       if( count ) score /= (float)count;
+       else score = 1.0;
+       return( score );
+}
+
+float substitution_nid( char *seq1, char *seq2 )
+{
+       int k;
+       float s12;
+       int len = strlen( seq1 );
+       
+       s12 = 0.0;
+       for( k=0; k<len; k++ )
+               if( seq1[k] != '-' && seq2[k] != '-' )
+                       s12 += ( seq1[k] == seq2[k] );
+
+//     fprintf( stdout, "s12 = %f\n", s12 );
+       return( s12 );
+}
+
+float substitution_score( char *seq1, char *seq2 )
+{
+       int k;
+       float s12;
+       int len = strlen( seq1 );
+       
+       s12 = 0.0;
+       for( k=0; k<len; k++ )
+               if( seq1[k] != '-' && seq2[k] != '-' )
+                       s12 += amino_dis[(int)seq1[k]][(int)seq2[k]];
+
+//     fprintf( stdout, "s12 = %f\n", s12 );
+       return( s12 );
+}
+
+float substitution_hosei( char *seq1, char *seq2 )   /* method 1 */
+#if 0
+{
+       int k;
+       float score = 0.0;
+       int count = 0;
+       int len = strlen( seq1 );
+
+       for( k=0; k<len; k++ )
+       {       
+               if( seq1[k] != '-' && seq2[k] != '-' )
+               {
+                       score += (float)( seq1[k] != seq2[k] );
+                       count++;
+               }
+       }
+       if( count ) score /= (float)count;
+       else score = 1.0;
+       if( score < 0.95 ) score = - log( 1.0 - score );
+       else score = 3.0;
+       return( score );
+}
+#else
+{
+       int count = 0;
+       float score;
+       int iscore = 0;
+       char s1, s2;
+
+       while( (s1=*seq1++) )
+       {
+               s2 = *seq2++;
+               if( s1 == '-' ) continue;
+               if( s2 == '-' ) continue;
+               iscore += ( s1 != s2 );
+               count++;
+       }
+       if( count ) score = (float)iscore / count;
+       else score = 1.0;
+       if( score < 0.95 ) score = - log( 1.0 - score );
+       else score = 3.0;
+       return( score );
+}
+#endif
+
+float substitution( char *seq1, char *seq2 )   /* method 1 */
+{
+       int k;
+       float score = 0.0;
+       int count = 0;
+       int len = strlen( seq1 );
+
+       for( k=0; k<len; k++ )
+       {       
+               if( seq1[k] != '-' && seq2[k] != '-' )
+               {
+                       score += (float)( seq1[k] != seq2[k] );
+                       count++;
+               }
+       }
+       if( count ) score /= (float)count;
+       else score = 1.0;
+       return( score );
+}
+
+
+void treeconstruction( char **seq, int nseq, int ***topol, double **len, double **eff )
+{
+    int i, j;
+
+       if( weight > 1 )
+       {
+               if( utree == 0 )
+               {
+               for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+                       {
+/*
+                        eff[i][j] = (double)score_calc1( seq[i], seq[j] );
+*/
+                        eff[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+ /*
+                                fprintf( stderr, "%f\n", eff[i][j] );
+ */
+                       }
+/*
+                       fprintf( stderr, "distance matrix\n" );
+                       for( i=0; i<nseq; i++ )
+                       {
+                               for( j=0; j<nseq; j++ ) 
+                               {
+                                       fprintf( stderr, "%f ", eff[i][j] );
+                               }
+                               fprintf( stderr, "\n" );
+                       }
+*/
+/*
+                       upg( nseq, eff, topol, len );
+                       upg2( nseq, eff, topol, len );
+*/
+                       spg( nseq, eff, topol, len );
+                       counteff( nseq, topol, len, eff );
+               }
+       }
+       else
+       {
+               for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) 
+                       eff[i][j] = 1.0;
+       }
+/*
+fprintf( stderr, "weight matrix\n" );
+for( i=0; i<nseq; i++ )
+{
+       for( j=0; j<nseq; j++ ) 
+       {
+               fprintf( stderr, "%f ", eff[i][j] );
+       }
+       fprintf( stderr, "\n" );
+}
+*/
+}
+
+float bscore_calc( char **seq, int s, double **eff )  /* algorithm B */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    long score;
+
+       score = 0;
+       nglen = 0;
+       for( i=0; i<s-1; i++ ) for( j=i+1; j<s; j++ )
+       {
+               double efficient = eff[i][j];
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 + !gb1  * !gc1 
+                 * !gb2  *  gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+                                + gb1   * !gc1
+                                * gb2   *  gc2      *BEFF
+
+                                + gb1   *  gc1
+                                * gb2   * !gc2      *BEFF
+                 ;
+                       score += (long)cob * penalty * efficient;
+                       score += (long)amino_dis[(int)seq[i][k]][(int)seq[j][k]] * efficient;
+                       nglen += ( !gc1 * !gc2 );
+               }
+       }
+       return( (float)score / nglen + 400.0 * !scoremtx );
+}
+
+void AllocateTmpSeqs( char ***mseq2pt, char **mseq1pt, int locnlenmax )
+{
+       *mseq2pt = AllocateCharMtx( njob, locnlenmax+1 );
+       *mseq1pt = AllocateCharVec( locnlenmax+1 );
+}
+
+void FreeTmpSeqs( char **mseq2, char *mseq1 )
+{
+       FreeCharMtx( mseq2 );
+       free( (char *)mseq1 );
+}
+
+
+void gappick0( char *aseq, char *seq )
+{
+       for( ; *seq != 0; seq++ )
+       {
+               if( *seq != '-' )
+                       *aseq++ = *seq;
+       }
+       *aseq = 0;
+
+}
+
+void gappick( int nseq, int s, char **aseq, char **mseq2, 
+                         double **eff, double *effarr )
+{
+       int i, j, count, countjob, len, allgap;
+       len = strlen( aseq[0] );
+       for( i=0, count=0; i<len; i++ ) 
+       {
+               allgap = 1;
+               for( j=0; j<nseq; j++ ) if( j != s ) allgap *= ( aseq[j][i] == '-' );
+        if( allgap == 0 )
+               {
+                       for( j=0, countjob=0; j<nseq; j++ ) 
+                       {
+                               if( j != s )
+                               {
+                                       mseq2[countjob][count] = aseq[j][i];
+                                       countjob++;
+                               }
+                       }
+                       count++;
+               }
+       }
+       for( i=0; i<nseq-1; i++ ) mseq2[i][count] = 0;
+
+       for( i=0, countjob=0; i<nseq; i++ ) 
+       {
+               if( i != s )
+               {
+                       effarr[countjob] = eff[s][i];
+                       countjob++;
+               }
+       }
+/*
+fprintf( stdout, "effarr in gappick s = %d\n", s+1 );
+for( i=0; i<countjob; i++ ) 
+       fprintf( stdout, " %f", effarr[i] );
+printf( "\n" );
+*/
+}
+
+void commongappick_record( int nseq, char **seq, int *map )
+{
+       int i, j, count;
+       int len = strlen( seq[0] );
+
+
+       for( i=0, count=0; i<=len; i++ ) 
+       {
+       /*
+               allgap = 1;
+               for( j=0; j<nseq; j++ ) 
+                       allgap *= ( seq[j][i] == '-' );
+               if( !allgap )
+       */
+               for( j=0; j<nseq; j++ )
+                       if( seq[j][i] != '-' ) break;
+               if( j != nseq )
+               {
+                       for( j=0; j<nseq; j++ )
+                       {
+                               seq[j][count] = seq[j][i];
+                       }
+                       map[count] = i;
+                       count++;
+               }
+       }
+}
+
+void commongappick( int nseq, char **seq )
+{
+       int i, j, count;
+       int len = strlen( seq[0] );
+
+       for( i=0, count=0; i<=len; i++ ) 
+       {
+       /*
+               allgap = 1;
+               for( j=0; j<nseq; j++ ) 
+                       allgap *= ( seq[j][i] == '-' );
+               if( !allgap )
+       */
+               for( j=0; j<nseq; j++ )
+                       if( seq[j][i] != '-' ) break;
+               if( j != nseq )
+               {
+                       for( j=0; j<nseq; j++ )
+                       {
+                               seq[j][count] = seq[j][i];
+                       }
+                       count++;
+               }
+       }
+}
+               
+double score_calc0( char **seq, int s, double **eff, int ex )
+{
+       double tmp;
+
+       if( scmtd == 4 ) tmp = score_calc4( seq, s, eff, ex );
+       if( scmtd == 5 ) tmp = score_calc5( seq, s, eff, ex );
+       else             tmp = score_calc5( seq, s, eff, ex );
+
+       return( tmp );
+
+}
+
+/*
+float score_m_1( char **seq, int ex, double **eff )
+{
+       int i, j, k;
+       int len = strlen( seq[0] );
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+       double score;
+
+       score = 0.0;
+       nglen = 0;
+       for( i=0; i<njob; i++ ) 
+       {
+               double efficient = eff[MIN(i,ex)][MAX(i,ex)];
+               if( i == ex ) continue;
+
+               gc1 = 0; 
+               gc2 = 0;
+               for( k=0; k<len; k++ ) 
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[ex][k] == '-' );
+      
+            cob = 
+                   !gb1  *  gc1
+                 * !gb2  * !gc2
+
+                 + !gb1  * !gc1
+                 * !gb2  *  gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+                 +  gb1  * !gc1
+                 *  gb2  *  gc2      *BEFF
+
+                 +  gb1  *  gc1
+                 *  gb2  * !gc2      *BEFF
+                 ;
+                       score += (double)cob * penalty * efficient;
+                       score += (double)amino_dis[seq[i][k]][seq[ex][k]] * efficient;
+                       *
+                       nglen += ( !gc1 * !gc2 );
+                       *
+                       if( !gc1 && !gc2 ) fprintf( stdout, "%f\n", score );
+               }
+       }
+       return( (float)score / nglen + 400.0 * !scoremtx );
+}
+*/
+
+#if 0
+void sitescore( char **seq, double **eff, char sco1[], char sco2[], char sco3[] )
+{
+       int i, j, k;
+       int len = strlen( seq[0] );
+       double tmp;
+       double count;
+       int ch;
+       double sco[N];
+
+       for( i=0; i<len; i++ ) 
+       {
+               tmp = 0.0; count = 0;
+               for( j=0; j<njob-1; j++ ) for( k=j+1; k<njob; k++ ) 
+               {
+               /*
+                       if( seq[j][i] != '-' && seq[k][i] != '-' )
+               */
+                       {
+                               tmp += amino_dis[seq[j][i]][seq[k][i]] + 400 * !scoremtx;
+                               count++; 
+                       }
+               }
+               if( count > 0.0 ) tmp /= count;
+               else( tmp = 0.0 );
+               ch = (int)( tmp/100.0 - 0.000001 );
+               sprintf( sco1+i, "%c", ch+0x61 );
+       }
+       sco1[len] = 0;
+
+    for( i=0; i<len; i++ ) 
+    {
+        tmp = 0.0; count = 0;
+        for( j=0; j<njob-1; j++ ) for( k=j+1; k<njob; k++ ) 
+        {
+               /*
+            if( seq[j][i] != '-' && seq[k][i] != '-' )
+               */
+            {
+                tmp += eff[j][k] * ( amino_dis[seq[j][i]][seq[k][i]] + 400 * !scoremtx );
+                count += eff[j][k]; 
+            }
+        }
+               if( count > 0.0 ) tmp /= count;
+               else( tmp = 0.0 );
+               tmp = ( tmp - 400 * !scoremtx ) * 2;
+               if( tmp < 0 ) tmp = 0;
+        ch = (int)( tmp/100.0 - 0.000001 );
+        sprintf( sco2+i, "%c", ch+0x61 );
+               sco[i] = tmp;
+    }
+    sco2[len] = 0;
+
+       for( i=WIN; i<len-WIN; i++ )
+       {
+               tmp = 0.0;
+               for( j=i-WIN; j<=i+WIN; j++ )
+               {
+                       tmp += sco[j];
+               }
+               for( j=0; j<njob; j++ ) 
+               {
+                       if( seq[j][i] == '-' )
+                       {
+                               tmp = 0.0;
+                               break;
+                       }
+               }
+               tmp /= WIN * 2 + 1;
+               ch = (int)( tmp/100.0 - 0.0000001 );
+               sprintf( sco3+i, "%c", ch+0x61 );
+       }
+       for( i=0; i<WIN; i++ ) sco3[i] = '-';
+       for( i=len-WIN; i<len; i++ ) sco3[i] = '-';
+       sco3[len] = 0;
+}
+#endif
+
+void strins( char *str1, char *str2 )
+{
+       char *bk;
+       int len1 = strlen( str1 );
+       int len2 = strlen( str2 );
+
+       bk = str2;
+       str2 += len1+len2;
+       str1 += len1-1;
+
+       while( str2 >= bk+len1 ) { *str2 = *(str2-len1); str2--;} // by D.Mathog
+       while( str2 >= bk ) { *str2-- = *str1--; }
+}
+
+int isaligned( int nseq, char **seq )
+{
+       int i;
+       int len = strlen( seq[0] );
+       for( i=1; i<nseq; i++ ) 
+       {
+               if( strlen( seq[i] ) != len ) return( 0 );
+       }
+       return( 1 );
+}
+
+double score_calc_for_score( int nseq, char **seq )
+{
+    int i, j, k, c;
+    int len = strlen( seq[0] );
+    double score;
+    double tmpscore;
+    char *mseq1, *mseq2;
+
+    score = 0.0;
+    for( i=0; i<nseq-1; i++ )
+    {
+        for( j=i+1; j<nseq; j++ )
+        {
+            mseq1 = seq[i];
+            mseq2 = seq[j];
+            tmpscore = 0.0;
+            c = 0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                c++;
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty - n_dis[0][24];
+                    while( mseq1[++k] == '-' )
+                        ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty - n_dis[0][24];
+                    while( mseq2[++k] == '-' )
+                        ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+            score += (double)tmpscore / (double)c;
+#if DEBUG
+                       printf( "tmpscore in mltaln9.c = %f\n", tmpscore );
+                       printf( "tmpscore / c          = %f\n", tmpscore/(double)c );
+#endif
+        }
+    }
+       fprintf( stderr, "raw score = %f\n", score );
+       score /= (double)nseq * ( nseq-1.0 ) / 2.0;
+       score += 400.0;
+#if DEBUG
+       printf( "score in mltaln9.c = %f\n", score );
+#endif
+    return( (double)score );
+}
+
+void floatncpy( float *vec1, float *vec2, int len )
+{
+       while( len-- )
+               *vec1++ = *vec2++;
+}
+
+float score_calc_a( char **seq, int s, double **eff )  /* algorithm A+ */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    float score;
+
+       score = 0;
+       nglen = 0;
+       for( i=0; i<s-1; i++ ) for( j=i+1; j<s; j++ )
+       {
+               double efficient = eff[i][j];
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 +  gb1  * !gc1 
+                 * !gb2  * !gc2
+
+                    + !gb1  * !gc1
+                        * !gb2  *  gc2
+
+                 + !gb1  * !gc1 
+                 *  gb2  * !gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+                                +  gb1  * !gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                *  gb2  * !gc2
+      
+                                + !gb1  *  gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                * !gb2  *  gc2
+                 ;
+                       score += 0.5 * (float)cob * penalty * efficient;
+                       score += (float)amino_dis[(int)seq[i][k]][(int)seq[j][k]] * (float)efficient;
+                       nglen += ( !gc1 * !gc2 );
+               }
+       }
+       return( (float)score / nglen + 400.0 * !scoremtx );
+}
+
+
+float score_calc_s( char **seq, int s, double **eff )  /* algorithm S, not used */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    float score;
+
+       score = 0;
+       nglen = 0;
+       for( i=0; i<s-1; i++ ) for( j=i+1; j<s; j++ )
+       {
+               double efficient = eff[i][j];
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 +  gb1  * !gc1 
+                 * !gb2  * !gc2
+
+                    + !gb1  * !gc1
+                        * !gb2  *  gc2
+
+                 + !gb1  * !gc1 
+                 *  gb2  * !gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+#if 0
+                                +  gb1  * !gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                *  gb2  * !gc2
+      
+                                + !gb1  *  gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                * !gb2  *  gc2
+#endif
+                 ;
+                       score += 0.5 * (float)cob * penalty * efficient;
+                       score += (float)amino_dis[(int)seq[i][k]][(int)seq[j][k]] * (float)efficient;
+                       nglen += ( !gc1 * !gc2 );
+               }
+       }
+       return( (float)score / nglen + 400.0 );
+}
+
+double score_calc_for_score_s( int s, char **seq )  /* algorithm S */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    float score;
+
+       score = 0;
+       nglen = 0;
+       for( i=0; i<s-1; i++ ) for( j=i+1; j<s; j++ )
+       {
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 +  gb1  * !gc1 
+                 * !gb2  * !gc2
+
+                    + !gb1  * !gc1
+                        * !gb2  *  gc2
+
+                 + !gb1  * !gc1 
+                 *  gb2  * !gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+#if 0
+                                +  gb1  * !gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                *  gb2  * !gc2
+      
+                                + !gb1  *  gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                * !gb2  *  gc2
+#endif
+                 ;
+                       score += 0.5 * (float)cob * penalty;
+                       score += (float)amino_dis[(int)seq[i][k]][(int)seq[j][k]];
+                       nglen += ( !gc1 * !gc2 );
+               }
+#if 0
+               fprintf( stderr, "i = %d, j=%d\n", i+1, j+1 );
+               fprintf( stderr, "score = %f\n", score );
+#endif
+       }
+       return( (double)score / nglen + 400.0 );
+}
+
+double SSPscore___( int s, char **seq, int ex )  /* algorithm S */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    float score;
+
+       score = 0;
+       nglen = 0;
+       i=ex; for( j=0; j<s; j++ )
+       {
+
+               if( j == ex ) continue;
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 +  gb1  * !gc1 
+                 * !gb2  * !gc2
+
+                    + !gb1  * !gc1
+                        * !gb2  *  gc2
+
+                 + !gb1  * !gc1 
+                 *  gb2  * !gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2 * 2.0 
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2 * 2.0 
+      
+#if 0
+                                +  gb1  * !gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                *  gb2  * !gc2
+      
+                                + !gb1  *  gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                * !gb2  *  gc2
+#endif
+                 ;
+                       score += 0.5 * (float)cob * penalty;
+                       score += (float)amino_dis[(int)seq[i][k]][(int)seq[j][k]];
+                       nglen += ( !gc1 * !gc2 ); /* tsukawanai */
+               }
+#if 0
+               fprintf( stderr, "i = %d, j=%d\n", i+1, j+1 );
+               fprintf( stderr, "score = %f\n", score );
+#endif
+       }
+       return( (double)score );
+}
+
+double SSPscore( int s, char **seq )  /* algorithm S */
+{
+       int i, j, k;
+       int gb1, gb2, gc1, gc2;
+       int cob;
+       int nglen;
+    int len = strlen( seq[0] );
+    float score;
+
+       score = 0;
+       nglen = 0;
+       for( i=0; i<s-1; i++ ) for( j=i+1; j<s; j++ )
+       {
+
+               gc1 = 0;
+               gc2 = 0;
+               for( k=0; k<len; k++ )
+               {
+                       gb1 = gc1;
+                       gb2 = gc2;
+
+                       gc1 = ( seq[i][k] == '-' );
+                       gc2 = ( seq[j][k] == '-' );
+                       
+            cob = 
+                      !gb1  *  gc1
+                        * !gb2  * !gc2
+
+                 +  gb1  * !gc1 
+                 * !gb2  * !gc2
+
+                    + !gb1  * !gc1
+                        * !gb2  *  gc2
+
+                 + !gb1  * !gc1 
+                 *  gb2  * !gc2
+
+                 + !gb1  *  gc1
+                 *  gb2  * !gc2
+
+                 +  gb1  * !gc1
+                 * !gb2  *  gc2
+      
+#if 0
+                                +  gb1  * !gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                *  gb2  * !gc2
+      
+                                + !gb1  *  gc1
+                                *  gb2  *  gc2
+
+                                +  gb1  *  gc1
+                                * !gb2  *  gc2
+#endif
+                 ;
+                       score += 0.5 * (float)cob * penalty;
+                       score += (float)amino_dis[(int)seq[i][k]][(int)seq[j][k]];
+                       nglen += ( !gc1 * !gc2 ); /* tsukawanai */
+               }
+#if 0
+               fprintf( stderr, "i = %d, j=%d\n", i+1, j+1 );
+               fprintf( stderr, "score = %f\n", score );
+#endif
+       }
+       return( (double)score );
+}
+
+
+
+double DSPscore( int s, char **seq )  /* method 3 deha nai */
+{
+    int i, j, k;
+    double c;
+    int len = strlen( seq[0] );
+    double score;
+    double tmpscore;
+    char *mseq1, *mseq2;
+#if DEBUG
+       FILE *fp;
+#endif
+
+    score = 0.0;
+    c = 0.0;
+
+    for( i=0; i<s-1; i++ )
+    {
+        for( j=i+1; j<s; j++ )
+        {
+            mseq1 = seq[i];
+            mseq2 = seq[j];
+            tmpscore = 0.0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq1[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq2[++k] == '-' )
+                        tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+            score += (double)tmpscore;
+        }
+    }
+
+       return( score );
+}
+
+
+#define SEGMENTSIZE 150
+
+int searchAnchors( int nseq, char **seq, Segment *seg )
+{
+       int i, j, k, kcyc;
+       int status;
+       double score;
+       int value = 0;
+       int len;
+       int length;
+       static double *stra = NULL;
+       static int alloclen = 0;
+       double cumscore;
+       static double threshold;
+
+       len = strlen( seq[0] );
+       if( alloclen < len )
+       {
+               if( alloclen )
+               {
+                       FreeDoubleVec( stra );
+               }
+               else
+               {
+                       threshold = (int)divThreshold / 100.0 * 600.0 * divWinSize;
+               }
+               stra = AllocateDoubleVec( len );
+               alloclen = len;
+       }
+
+       for( i=0; i<len; i++ )
+       {
+#if 0
+               /* make prf */
+               for( j=0; j<26; j++ )
+               {
+                       prf[j] = 0.0;
+               }
+               for( j=0; j<nseq; j++ ) prf[amino_n[seq[j][i]]] += 1.0;
+
+               /* make hat */
+               pre = 26;
+               for( j=25; j>=0; j-- )
+               {
+                       if( prf[j] )
+                       {
+                               hat[pre] = j;
+                               pre = j;
+                       }
+               }
+               hat[pre] = -1;
+
+               /* make site score */
+               stra[i] = 0.0;
+               for( k=hat[26]; k!=-1; k=hat[k] ) 
+                       for( j=hat[26]; j!=-1; j=hat[j] ) 
+                               stra[i] += n_dis[k][j] * prf[k] * prf[j];
+#else
+               stra[i] = 0.0;
+               kcyc = nseq-1;
+               for( k=0; k<kcyc; k++ ) for( j=k+1; j<nseq; j++ )
+                       stra[i] += n_dis[(int)amino_n[(int)seq[k][i]]][(int)amino_n[(int)seq[j][i]]];
+               stra[i] /= (double)nseq * ( nseq-1 ) / 2;
+#endif
+       }
+
+       (seg+0)->skipForeward = 0;
+       (seg+1)->skipBackward = 0;
+       status = 0;
+       cumscore = 0.0;
+       score = 0.0;
+       length = 0; /* modified at 01/09/11 */
+       for( j=0; j<divWinSize; j++ ) score += stra[j];
+       for( i=1; i<len-divWinSize; i++ )
+       {
+               score = score - stra[i-1] + stra[i+divWinSize-1];
+#if DEBUG
+               fprintf( stderr, "%d %f   ? %f", i, score, threshold );
+               if( score > threshold ) fprintf( stderr, "YES\n" );
+               else                    fprintf( stderr, "NO\n" );
+#endif
+
+               if( score > threshold )
+               {
+                       if( !status )
+                       {
+                               status = 1;
+                               seg->start = i;
+                               length = 0;
+                               cumscore = 0.0;
+                       }
+                       length++;
+                       cumscore += score;
+               }
+               if( score <= threshold || length > SEGMENTSIZE )
+               {
+                       if( status )
+                       {
+                               seg->end = i;
+                               seg->center = ( seg->start + seg->end + divWinSize ) / 2 ;
+                               seg->score = cumscore;
+#if DEBUG
+                               fprintf( stderr, "%d-%d length = %d\n", seg->start, seg->end, length );
+#endif
+                               if( length > SEGMENTSIZE )
+                               {
+                                       (seg+0)->skipForeward = 1;
+                                       (seg+1)->skipBackward = 1;
+                               }
+                               else
+                               {
+                                       (seg+0)->skipForeward = 0;
+                                       (seg+1)->skipBackward = 0;
+                               }
+                               length = 0;
+                               cumscore = 0.0;
+                               status = 0;
+                               value++;
+                               seg++;
+                               if( value > MAXSEG - 3 ) ErrorExit( "TOO MANY SEGMENTS!");
+                       }
+               }
+       }
+       if( status )
+       {
+               seg->end = i;
+               seg->center = ( seg->start + seg->end + divWinSize ) / 2 ;
+               seg->score = cumscore;
+#if DEBUG
+fprintf( stderr, "%d-%d length = %d\n", seg->start, seg->end, length );
+#endif
+               value++;
+       }
+       return( value );
+}
+
+void dontcalcimportance( int nseq, double *eff, char **seq, LocalHom **localhom )
+{
+       int i, j;
+       LocalHom *ptr;
+       static int *nogaplen = NULL;
+
+       if( nogaplen == NULL )
+       {
+               nogaplen = AllocateIntVec( nseq );
+       }
+
+       for( i=0; i<nseq; i++ )
+       {
+               nogaplen[i] = seqlen( seq[i] );
+//             fprintf( stderr, "nogaplen[%d] = %d\n", i, nogaplen[i] );
+       }
+
+       for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<nseq; j++ )
+               {
+                       for( ptr=localhom[i]+j; ptr; ptr=ptr->next )
+                       {
+//                             fprintf( stderr, "i,j=%d,%d,ptr=%p\n", i, j, ptr );
+#if 1
+                               ptr->importance = ptr->opt / ptr->overlapaa;
+                               ptr->fimportance = (float)ptr->importance;
+#else
+                               ptr->importance = ptr->opt / MIN( nogaplen[i], nogaplen[j] );
+#endif
+                       }
+               }
+       }
+}
+
+void calcimportance( int nseq, double *eff, char **seq, LocalHom **localhom )
+{
+       int i, j, pos, len;
+       static double *importance;
+       double tmpdouble;
+       static int *nogaplen = NULL;
+       LocalHom *tmpptr;
+
+       if( importance == NULL )
+       {
+               importance = AllocateDoubleVec( nlenmax );
+               nogaplen = AllocateIntVec( nseq );
+       }
+
+
+       for( i=0; i<nseq; i++ )
+       {
+               nogaplen[i] = seqlen( seq[i] );
+//             fprintf( stderr, "nogaplen[] = %d\n", nogaplen[i] );
+       }
+
+#if 0
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ )
+       {
+               tmpptr = localhom[i]+j;
+               fprintf( stderr, "%d-%d\n", i, j );
+               do
+               {
+                       fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, opt=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->opt );
+               } while( tmpptr=tmpptr->next );
+       }
+#endif
+
+
+       for( i=0; i<nseq; i++ )
+       {
+//             fprintf( stderr, "i = %d\n", i );
+               for( pos=0; pos<nlenmax; pos++ )
+                       importance[pos] = 0.0;
+               for( j=0; j<nseq; j++ )
+               {
+                       if( i == j ) continue;
+                       tmpptr = localhom[i]+j;
+                       for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1 ) continue;
+                               for( pos=tmpptr->start1; pos<=tmpptr->end1; pos++ )
+#if 1
+                                       importance[pos] += eff[j];
+#else
+                                       importance[pos] += eff[j] * tmpptr->opt / MIN( nogaplen[i], nogaplen[j] );
+                                       importance[pos] += eff[j] * tmpptr->opt / tmpptr->overlapaa;
+#endif
+                       }
+               }
+#if 0
+               fprintf( stderr, "position specific importance of seq %d:\n", i );
+               for( pos=0; pos<nlenmax; pos++ )
+                       fprintf( stderr, "%d: %f\n", pos, importance[pos] );
+               fprintf( stderr, "\n" );
+#endif
+               for( j=0; j<nseq; j++ )
+               {
+//                     fprintf( stderr, "i=%d, j=%d\n", i, j );
+                       if( i == j ) continue;
+                       if( localhom[i][j].opt == -1.0 ) continue;
+#if 1
+                       for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               tmpdouble = 0.0;
+                               len = 0;
+                               for( pos=tmpptr->start1; pos<=tmpptr->end1; pos++ )
+                               {
+                                       tmpdouble += importance[pos];
+                                       len++;
+                               }
+                               tmpdouble /= (double)len;
+
+                               tmpptr->importance = tmpdouble * tmpptr->opt;
+                               tmpptr->fimportance = (float)tmpptr->importance;
+                       }
+#else
+                       tmpdouble = 0.0;
+                       len = 0;
+                       for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               for( pos=tmpptr->start1; pos<=tmpptr->end1; pos++ )
+                               {
+                                       tmpdouble += importance[pos];
+                                       len++;
+                               }
+                       }
+
+                       tmpdouble /= (double)len;
+
+                       for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               tmpptr->importance = tmpdouble * tmpptr->opt;
+//                             tmpptr->importance = tmpptr->opt / tmpptr->overlapaa; //\e$B$J$+$C$?$3$H$K$9$k\e(B
+                       }
+#endif
+
+//                     fprintf( stderr, "importance of match between %d - %d = %f\n", i, j, tmpdouble );
+               }
+       }
+
+#if 0
+       fprintf( stderr, "before averaging:\n" );
+
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ )
+       {
+               fprintf( stderr, "%d-%d\n", i, j );
+               for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+               {
+                       fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f -> %f opt=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->opt / tmpptr->overlapaa, eff[i] * tmpptr->importance, tmpptr->opt );
+               }
+       }
+#endif
+
+#if 1
+//     fprintf( stderr, "average?\n" );
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               double imp;
+               LocalHom *tmpptr1, *tmpptr2;
+
+//             fprintf( stderr, "i=%d, j=%d\n", i, j );
+
+               tmpptr1 = localhom[i]+j; tmpptr2 = localhom[j]+i;
+               for( ; tmpptr1 && tmpptr2; tmpptr1 = tmpptr1->next, tmpptr2 = tmpptr2->next)
+               {
+                       if( tmpptr1->opt == -1.0 || tmpptr2->opt == -1.0 ) 
+                       {
+//                             fprintf( stderr, "WARNING: i=%d, j=%d, tmpptr1->opt=%f, tmpptr2->opt=%f\n", i, j, tmpptr1->opt, tmpptr2->opt );
+                               continue;
+                       }
+//                     fprintf( stderr, "## importances = %f, %f\n", tmpptr1->importance, tmpptr2->importance );
+                       imp = 0.5 * ( tmpptr1->importance + tmpptr2->importance );
+                       tmpptr1->importance = tmpptr2->importance = imp;
+                       tmpptr1->fimportance = tmpptr2->fimportance = (float)imp;
+
+//                     fprintf( stderr, "## importance = %f\n", tmpptr1->importance );
+
+               }
+
+#if 1
+               if( ( tmpptr1 && !tmpptr2 ) || ( !tmpptr1 && tmpptr2 ) )
+               {
+                       fprintf( stderr, "ERROR: i=%d, j=%d\n", i, j );
+                       exit( 1 );
+               }
+#endif
+       }
+#endif
+#if 0
+       fprintf( stderr, "after averaging:\n" );
+
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ )
+       {
+               fprintf( stderr, "%d-%d\n", i, j );
+               for( tmpptr = localhom[i]+j; tmpptr; tmpptr=tmpptr->next )
+               {
+                       fprintf( stderr, "reg1=%d-%d, reg2=%d-%d, imp=%f -> %f opt=%f\n", tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->opt / tmpptr->overlapaa, tmpptr->importance, tmpptr->opt );
+               }
+       }
+#endif
+}
+
+
+#if 0
+void weightimportance( int nseq, double **eff, LocalHom **localhom )
+{
+       int i, j, pos, len;
+       static double *importance;
+       double tmpdouble;
+       LocalHom *tmpptr, *tmpptr1, *tmpptr2;
+       if( importance == NULL )
+               importance = AllocateDoubleVec( nlenmax );
+
+
+       fprintf( stderr, "effmtx = :\n" );
+       for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<nseq; j++ )
+               {
+                       fprintf( stderr, "%6.3f ", eff[i][j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               for( pos=0; pos<nlenmax; pos++ )
+                       importance[pos] = 0.0;
+               for( j=0; j<nseq; j++ )
+               {
+
+                       if( i == j ) continue;
+                       tmpptr = localhom[i]+j;
+                       while( 1 )
+                       {
+                               fprintf( stderr, "i=%d, j=%d\n", i, j );
+                               for( pos=tmpptr->start1; pos<=tmpptr->end1; pos++ )
+//                                     importance[pos] += eff[i][j] * tmpptr->importance;
+                                       importance[pos] += eff[i][j] / (double)nseq * tmpptr->importance / 1.0;
+                               fprintf( stderr, "eff[][] = %f, localhom[i][j].importance = %f \n", eff[i][j], tmpptr->importance );
+                               tmpptr = tmpptr->next;
+                               if( tmpptr == NULL ) break;
+                       } 
+
+               }
+#if 0
+               fprintf( stderr, "position specific importance of seq %d:\n", i );
+               for( pos=0; pos<nlenmax; pos++ )
+                       fprintf( stderr, "%d: %f\n", pos, importance[pos] );
+               fprintf( stderr, "\n" );
+#endif
+               for( j=0; j<nseq; j++ )
+               {
+                       fprintf( stderr, "i=%d, j=%d\n", i, j );
+                       if( i == j ) continue;
+                       tmpptr = localhom[i]+j;
+                       do
+                       {
+                               tmpdouble = 0.0;
+                               len = 0;
+                               for( pos=tmpptr->start1; pos<=tmpptr->end1; pos++ )
+                               {
+                                       tmpdouble += importance[pos];
+                                       len++;
+                               }
+                               tmpdouble /= (double)len;
+                               tmpptr->importance = tmpdouble;
+                               fprintf( stderr, "importance of match between %d - %d = %f\n", i, j, tmpdouble );
+                               tmpptr = tmpptr->next;
+                       } while( tmpptr );
+               }
+       }
+#if 1
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               fprintf( stderr, "i = %d, j=%d\n", i, j );
+               tmpptr1 = localhom[i]+j;
+               tmpptr2 = localhom[j]+i;
+               while( tmpptr1 && tmpptr2 )
+               {
+                       tmpptr1->importance += tmpptr2->importance;
+                       tmpptr1->importance *= 0.5;
+                       tmpptr2->importance *= tmpptr1->importance;
+                       fprintf( stderr, "%d-%d: s1=%d, e1=%d, s2=%d, e2=%d, importance=%f\n", i, j, tmpptr1->start1, tmpptr1->end1, tmpptr1->start2, tmpptr1->end2, tmpptr1->importance );
+                       tmpptr1 = tmpptr1->next;
+                       tmpptr2 = tmpptr2->next;
+                       fprintf( stderr, "tmpptr1 = %p, tmpptr2 = %p\n", tmpptr1, tmpptr2 );
+               }
+       }
+#endif
+}
+
+void weightimportance2( int nseq, double *eff, LocalHom **localhom )
+{
+       int i, j, pos, len;
+       static double *wimportance;
+       double tmpdouble;
+       if( wimportance == NULL )
+               wimportance = AllocateDoubleVec( nlenmax );
+
+
+       fprintf( stderr, "effmtx = :\n" );
+       for( i=0; i<nseq; i++ )
+       {
+               for( j=0; j<nseq; j++ )
+               {
+                       fprintf( stderr, "%6.3f ", eff[i] * eff[j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               fprintf( stderr, "i = %d\n", i );
+               for( pos=0; pos<nlenmax; pos++ )
+                       wimportance[pos] = 0.0;
+               for( j=0; j<nseq; j++ )
+               {
+                       if( i == j ) continue;
+                       for( pos=localhom[i][j].start1; pos<=localhom[i][j].end1; pos++ )
+//                             wimportance[pos] += eff[i][j];
+                               wimportance[pos] += eff[i] * eff[j] / (double)nseq * localhom[i][j].importance / 1.0;
+               }
+#if 0
+               fprintf( stderr, "position specific wimportance of seq %d:\n", i );
+               for( pos=0; pos<nlenmax; pos++ )
+                       fprintf( stderr, "%d: %f\n", pos, wimportance[pos] );
+               fprintf( stderr, "\n" );
+#endif
+               for( j=0; j<nseq; j++ )
+               {
+                       if( i == j ) continue;
+                       tmpdouble = 0.0;
+                       len = 0;
+                       for( pos=localhom[i][j].start1; pos<=localhom[i][j].end1; pos++ )
+                       {
+                               tmpdouble += wimportance[pos];
+                               len++;
+                       }
+                       tmpdouble /= (double)len;
+                       localhom[i][j].wimportance = tmpdouble;
+                       fprintf( stderr, "wimportance of match between %d - %d = %f\n", i, j, tmpdouble );
+               }
+       }
+#if 1
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               localhom[i][j].wimportance += localhom[j][i].wimportance;
+               localhom[i][j].wimportance = 0.5 * ( localhom[i][j].wimportance );
+       }
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               localhom[j][i].wimportance = localhom[i][j].wimportance;
+       }
+#endif
+}
+
+void weightimportance4( int clus1, int clus2, double *eff1, double *eff2, LocalHom ***localhom )
+{
+       int i, j, pos, len;
+       static double *wimportance;
+       LocalHom *tmpptr, *tmpptr1, *tmpptr2;
+       if( wimportance == NULL )
+               wimportance = AllocateDoubleVec( nlenmax );
+
+
+#if 0
+       fprintf( stderr, "effarr1 = :\n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "%6.3f\n", eff1[i] );
+       fprintf( stderr, "effarr2 = :\n" );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "%6.3f\n", eff2[i] );
+#endif
+
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+//                     fprintf( stderr, "i=%d, j=%d\n", i, j );
+                       tmpptr = localhom[i][j];
+                       do
+                       {
+                               tmpptr->wimportance = tmpptr->importance * eff1[i] * eff2[j];
+                               tmpptr = tmpptr->next;
+                       } while( tmpptr );
+               }
+       }
+}
+
+static void    addlocalhom_e( LocalHom *localhom, int start1, int start2, int end1, int end2, double opt )
+{
+       LocalHom *tmpptr;
+       tmpptr = localhom;
+
+       fprintf( stderr, "adding localhom\n" );
+       while( tmpptr->next )
+               tmpptr = tmpptr->next;
+       fprintf( stderr, "allocating localhom\n" );
+       tmpptr->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+       fprintf( stderr, "done\n" );
+       tmpptr = tmpptr->next;
+
+       tmpptr->start1 = start1;
+       tmpptr->start2 = start2;
+       tmpptr->end1 = end1;
+       tmpptr->end2 = end2;
+       tmpptr->opt = opt;
+
+       fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+}
+
+#if 0
+#endif
+
+
+
+void extendlocalhom( int nseq, LocalHom **localhom )
+{
+       int i, j, k, pos0, pos1, pos2, st;
+       int start1, start2, end1, end2;
+       static int *tmpint1 = NULL;
+       static int *tmpint2 = NULL;
+       static int *tmpdouble1 = NULL;
+       static int *tmpdouble2 = NULL;
+       double opt;
+       LocalHom *tmpptr;
+       if( tmpint1 == NULL )
+       {
+               tmpint1 = AllocateIntVec( nlenmax );
+               tmpint2 = AllocateIntVec( nlenmax );
+               tmpdouble1 = AllocateIntVec( nlenmax );
+               tmpdouble2 = AllocateIntVec( nlenmax );
+       }
+
+
+       for( k=0; k<nseq; k++ )
+       {
+               for( i=0; i<nseq-1; i++ ) 
+               {
+                       if( i == k ) continue;
+                       for( pos0=0; pos0<nlenmax; pos0++ ) 
+                               tmpint1[pos0] = -1;
+
+                       tmpptr=localhom[k]+i;
+                       do
+                       {
+                               pos0 = tmpptr->start1;
+                               pos1 = tmpptr->start2;
+                               while( pos0<=tmpptr->end1 )
+                               {
+                                       tmpint1[pos0] = pos1++;
+                                       tmpdouble1[pos0] = tmpptr->opt;
+                                       pos0++;
+                               }
+                       } while( tmpptr = tmpptr->next );
+
+
+                       for( j=i+1; j<nseq; j++ )
+                       {
+                               if( j == k ) continue;
+                               for( pos1=0; pos1<nlenmax; pos1++ ) tmpint2[pos1] = -1;
+                               tmpptr=localhom[k]+j;
+                               do
+                               {
+                                       pos0 = tmpptr->start1;
+                                       pos2 = tmpptr->start2;
+                                       while( pos0<=tmpptr->end1 )
+                                       {
+                                               tmpint2[pos0] = pos2++;
+                                               tmpdouble2[pos0++] = tmpptr->opt;
+                                       }
+                               } while( tmpptr = tmpptr->next );
+
+#if 0
+
+                               fprintf( stderr, "i,j=%d,%d\n", i, j );
+
+                               for( pos0=0; pos0<nlenmax; pos0++ )
+                                       fprintf( stderr, "%d ", tmpint1[pos0] );
+                               fprintf( stderr, "\n" );
+
+                               for( pos0=0; pos0<nlenmax; pos0++ )
+                                       fprintf( stderr, "%d ", tmpint2[pos0] );
+                               fprintf( stderr, "\n" );
+#endif
+
+
+                               st = 0;
+                               for( pos0=0; pos0<nlenmax; pos0++ )
+                               {
+//                                     fprintf( stderr, "pos0 = %d/%d, st = %d, tmpint1[pos0] = %d, tmpint2[pos0] = %d\n", pos0, nlenmax, st, tmpint1[pos0], tmpint2[pos0] );
+                                       if( tmpint1[pos0] >= 0 && tmpint2[pos0] >= 0 )
+                                       {
+                                               if( st == 0 )
+                                               {
+                                                       st = 1;
+                                                       start1 = tmpint1[pos0];
+                                                       start2 = tmpint2[pos0];
+                                                       opt = MIN( tmpdouble1[pos0], tmpdouble2[pos0] );
+                                               }
+                                               else if( tmpint1[pos0-1] != tmpint1[pos0]-1 || tmpint2[pos0-1] != tmpint2[pos0]-1 )
+                                               {
+                                                       addlocalhom_e( localhom[i]+j, start1, start2, tmpint1[pos0-1], tmpint2[pos0-1], opt );
+                                                       addlocalhom_e( localhom[j]+i, start2, start1, tmpint2[pos0-1], tmpint1[pos0-1], opt );
+                                                       start1 = tmpint1[pos0];
+                                                       start2 = tmpint2[pos0];
+                                                       opt = MIN( tmpdouble1[pos0], tmpdouble2[pos0] );
+                                               }
+                                       }
+                                       if( tmpint1[pos0] == -1 || tmpint2[pos0] == -1 )
+                                       {
+                                               if( st == 1 )
+                                               {
+                                                       st = 0;
+                                                       addlocalhom_e( localhom[i]+j, start1, start2, tmpint1[pos0-1], tmpint2[pos0-1], opt );
+                                                       addlocalhom_e( localhom[j]+i, start2, start1, tmpint2[pos0-1], tmpint1[pos0-1], opt );
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+}
+#endif
+
+static void addlocalhom2_e( LocalHom *pt, LocalHom *lh, int sti, int stj, int eni, int enj, double opt, int overlp, int interm )
+{
+// dokka machigatteru
+       if( pt != lh ) // susumeru
+       {
+               pt->next = (LocalHom *)calloc( 1, sizeof( LocalHom ) );
+               pt = pt->next;
+               pt->next = NULL;
+               lh->last = pt;
+       }
+       else // sonomamatsukau
+       {
+               lh->last = pt;
+       }
+       lh->nokori++;
+//     fprintf( stderr, "in addlocalhom2_e, pt = %p, pt->next = %p, interm=%d, sti-eni-stj-enj=%d %d %d %d\n", pt, pt->next, interm, sti, eni, stj, enj );
+
+       pt->start1 = sti;
+       pt->start2 = stj;
+       pt->end1 = eni;
+       pt->end2 = enj;
+       pt->opt = opt;
+       pt->extended = interm;
+       pt->overlapaa = overlp;
+#if 0
+       fprintf( stderr, "i: %d-%d\n", sti, eni );
+       fprintf( stderr, "j: %d-%d\n", stj, enj );
+       fprintf( stderr, "opt=%f\n", opt );
+       fprintf( stderr, "overlp=%d\n", overlp );
+#endif
+}
+
+void extendlocalhom2( int nseq, LocalHom **localhom, double **dist )
+{
+       int overlp, plim;
+       int i, j, k;
+       int pi, pj, pk, len;
+       int status, sti, stj;
+       int *ipt;
+       int co;
+       static int *ini = NULL;
+       static int *inj = NULL;
+       LocalHom *pt;
+
+       sti = 0; // by D.Mathog, a guess
+       stj = 0; // by D.Mathog, a guess
+
+       if( ini == NULL )
+       {
+               ini = AllocateIntVec( nlenmax+1 );
+               inj = AllocateIntVec( nlenmax+1 );
+       }
+
+
+       for( i=0; i<nseq-1; i++ )
+       {
+               for( j=i+1; j<nseq; j++ )
+               {
+#if 0
+                       for( k=0; k<nseq; k++ ) sai[k] = 0;
+                       numint = ncons;
+                       while( 1 )
+                       {
+                               k = (int)( rnd() * nseq );
+                               if( k == i || k == j ) continue; // mou yatta nomo habuita hoga ii 
+                               if( numint-- == 0 ) break;
+                               if( sai[k] ) continue;
+                               sai[k] = 1;
+#else
+                       for( k=0; k<nseq; k++ )
+                       {
+#endif
+//                             fprintf( stderr, "i=%d, j=%d, k=%d, dists = %f,%f,%f thrinter=%f\n", i, j, k, dist[i][j], dist[MIN(i,k)][MAX(i,k)], dist[MIN(j,k)][MAX(j,k)], thrinter );
+                               if( k == i || k == j ) continue; // mou yatta nomo habuita hoga ii 
+                               if( dist[MIN(i,k)][MAX(i,k)] > dist[i][j] * thrinter || dist[MIN(j,k)][MAX(j,k)] > dist[i][j] * thrinter ) continue;
+                               ipt = ini; co = nlenmax+1;
+                               while( co-- ) *ipt++ = -1;
+                               ipt = inj; co = nlenmax+1;
+                               while( co-- ) *ipt++ = -1;
+                               overlp = 0;
+
+                               {
+                                       for( pt=localhom[i]+k; pt; pt=pt->next )
+                               {
+//                                             fprintf( stderr, "i=%d,k=%d,st1:st2=%d:%d,pt=%p,extended=%p\n", i, k, pt->start1, pt->start2, pt, pt->extended );
+                                               if( pt->opt == -1 )
+                                               {
+                                                       fprintf( stderr, "opt kainaide tbfast.c = %f\n", pt->opt );
+                                               }
+                                               if( pt->extended > -1 ) break;
+                                               pi = pt->start1;
+                                               pk = pt->start2;
+                                               len = pt->end1 - pt->start1 + 1;
+                                               ipt = ini + pk;
+                                               while( len-- ) *ipt++ = pi++;
+                                       }
+                               }
+
+                               {
+                                       for( pt=localhom[j]+k; pt; pt=pt->next )
+                               {
+                                               if( pt->opt == -1 )
+                                               {
+                                                       fprintf( stderr, "opt kainaide tbfast.c = %f\n", pt->opt );
+                                               }
+                                               if( pt->extended > -1 ) break;
+                                               pj = pt->start1;
+                                               pk = pt->start2;
+                                               len = pt->end1 - pt->start1 + 1;
+                                               ipt = inj + pk;
+                                               while( len-- ) *ipt++ = pj++;
+                                       }
+                               }
+#if 0
+                               fprintf( stderr, "i=%d,j=%d,k=%d\n", i, j, k );
+                               overlp = 0;
+                               for( pk = 0; pk < nlenmax; pk++ )
+                               {
+                                       if( ini[pk] != -1 && inj[pk] != -1 ) overlp++;
+                                       fprintf( stderr, " %d", inj[pk] );
+                               }
+                               fprintf( stderr, "\n" );
+
+                               fprintf( stderr, "i=%d,j=%d,k=%d\n", i, j, k );
+                               overlp = 0;
+                               for( pk = 0; pk < nlenmax; pk++ )
+                               {
+                                       if( ini[pk] != -1 && inj[pk] != -1 ) overlp++;
+                                       fprintf( stderr, " %d", ini[pk] );
+                               }
+                               fprintf( stderr, "\n" );
+#endif
+                               overlp = 0;
+                               plim = nlenmax+1;
+                               for( pk = 0; pk < plim; pk++ )
+                                       if( ini[pk] != -1 && inj[pk] != -1 ) overlp++;
+
+
+                               status = 0;
+                               plim = nlenmax+1;
+                               for( pk=0; pk<plim; pk++ )
+                               {
+//                                     fprintf( stderr, "%d %d: %d-%d\n", i, j, ini[pk], inj[pk] );
+                                       if( status )
+                                       {
+                                               if( ini[pk] == -1 || inj[pk] == -1 || ini[pk-1] != ini[pk] - 1 || inj[pk-1] != inj[pk] - 1 ) // saigonoshori
+                                               {
+                                                       status = 0;
+//                                                     fprintf( stderr, "end here!\n" );
+
+                                                       pt = localhom[i][j].last;
+//                                                     fprintf( stderr, "in ex (ba), pt = %p, nokori=%d, i,j,k=%d,%d,%d\n", pt, localhom[i][j].nokori, i, j, k );
+                                                       addlocalhom2_e( pt, localhom[i]+j, sti, stj, ini[pk-1], inj[pk-1], MIN( localhom[i][k].opt, localhom[j][k].opt ) * 1.0, overlp, k );
+//                                                     fprintf( stderr, "in ex, pt = %p, pt->next = %p, pt->next->next = %p\n", pt, pt->next, pt->next->next );
+
+                                                       pt = localhom[j][i].last;
+//                                                     fprintf( stderr, "in ex (ba), pt = %p, pt->next = %p\n", pt, pt->next );
+//                                                     fprintf( stderr, "in ex (ba), pt = %p, pt->next = %p, k=%d\n", pt, pt->next, k );
+                                                       addlocalhom2_e( pt, localhom[j]+i, stj, sti, inj[pk-1], ini[pk-1], MIN( localhom[i][k].opt, localhom[j][k].opt ) * 1.0, overlp, k );
+//                                                     fprintf( stderr, "in ex, pt = %p, pt->next = %p, pt->next->next = %p\n", pt, pt->next, pt->next->next );
+                                               }
+                                       }
+                                       if( !status ) // else deha arimasenn.
+                                       {
+                                               if( ini[pk] == -1 || inj[pk] == -1 ) continue;
+                                               sti = ini[pk];
+                                               stj = inj[pk];
+//                                             fprintf( stderr, "start here!\n" );
+                                               status = 1;
+                                       }
+                               }
+//                             if( status ) fprintf( stderr, "end here\n" );
+
+//                             exit( 1 );
+//                                     fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next ); 
+                       }
+#if 0
+                       for( pt=localhomtable[i]+j; pt; pt=pt->next )
+               {
+                   if( tmpptr->opt == -1.0 ) continue;
+                               fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next ); 
+               }
+#endif
+               }
+       }
+}
+
+int makelocal( char *s1, char *s2, int thr )
+{
+       int start, maxstart, maxend;
+       char *pt1, *pt2;
+       double score;
+       double maxscore;
+
+       pt1 = s1;
+       pt2 = s2;
+
+       maxend = 0; // by D.Mathog, a guess
+
+//     fprintf( stderr, "thr = %d, \ns1 = %s\ns2 = %s\n", thr, s1, s2 );
+       maxscore = 0.0;
+       score = 0.0;
+       start = 0;
+       maxstart = 0;
+       while( *pt1 )
+       {
+//             fprintf( stderr, "*pt1 = %c*pt2 = %c\n", *pt1, *pt2 );
+               if( *pt1 == '-' || *pt2 == '-' )
+               {
+//                     fprintf( stderr, "penalty = %d\n", penalty );
+                       score += penalty;
+                       while( *pt1 == '-' || *pt2 == '-' )
+                       {
+                               pt1++; pt2++;
+                       }
+                       continue;
+               }
+
+               score += ( amino_dis[(int)*pt1++][(int)*pt2++] - thr );
+//             score += ( amino_dis[(int)*pt1++][(int)*pt2++] );
+               if( score > maxscore ) 
+               {
+//                     fprintf( stderr, "score = %f\n", score );
+                       maxscore = score;
+                       maxstart = start;
+//                     fprintf( stderr, "## max! maxstart = %d, start = %d\n", maxstart, start );
+               }
+               if( score < 0.0 )
+               {
+//                     fprintf( stderr, "## resetting, start = %d, maxstart = %d\n", start, maxstart );
+                       if( start == maxstart )
+                       {
+                               maxend = pt1 - s1;
+//                             fprintf( stderr, "maxend = %d\n", maxend );
+                       }
+                       score = 0.0;
+                       start = pt1 - s1;
+               }
+       }
+       if( start == maxstart )
+               maxend = pt1 - s1 - 1;
+
+//     fprintf( stderr, "maxstart = %d, maxend = %d, maxscore = %f\n", maxstart, maxend, maxscore );
+       s1[maxend+1] = 0;
+       s2[maxend+1] = 0;
+       return( maxstart );
+}
+
+void resetlocalhom( int nseq, LocalHom **lh )
+{
+       int i, j;
+       LocalHom *pt;
+
+       for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               for( pt=lh[i]+j; pt; pt=pt->next )
+                       pt->opt = 1.0;
+       }
+
+}
+
+void gapireru( char *res, char *ori, char *gt )
+{
+       char g;
+       while( (g = *gt++) )
+       {
+               if( g == '-' )
+               {
+                       *res++ = *newgapstr;
+               }
+               else
+               {
+                       *res++ = *ori++;
+               }
+       }
+       *res = 0;
+}
+
+void getkyokaigap( char *g, char **s, int pos, int n )
+{
+//     char *bk = g;
+//     while( n-- ) *g++ = '-';
+       while( n-- ) *g++ = (*s++)[pos];
+
+//     fprintf( stderr, "bk = %s\n", bk );
+}
+
+void new_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len, char *sgappat )
+#if 0
+{
+       int i, j, gc, gb; 
+       float feff;
+
+       
+       for( i=0; i<len+1; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( sgappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       if( !gb *  gc ) ogcp[i] += feff;
+               }
+       }
+}
+#else
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = ogcp;
+       i = len;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               spt = seq[j];
+               fpt = ogcp;
+               gc = ( sgappat[j] == '-' );
+               i = len;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *spt++ == '-' );
+                       {
+                               if( !gb *  gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+       }
+}
+#endif
+void new_OpeningGapCount_zure( float *ogcp, int clus, char **seq, double *eff, int len, char *sgappat, char *egappat )
+#if 0
+{
+       int i, j, gc, gb; 
+       float feff;
+
+       
+       for( i=0; i<len+1; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( sgappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       if( !gb *  gc ) ogcp[i] += feff;
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       if( !gb *  gc ) ogcp[i] += feff;
+               }
+       }
+}
+#else
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = ogcp;
+       i = len+2;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               spt = seq[j];
+               fpt = ogcp;
+               gc = ( sgappat[j] == '-' );
+               i = len;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *spt++ == '-' );
+                       {
+                               if( !gb *  gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       if( !gb *  gc ) *fpt += feff;
+               }
+       }
+}
+#endif
+
+void new_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len, char *sgappat, char *egappat )
+#if 0
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len+1; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( sgappat[j] == '-' );
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i] += feff;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[len] += feff;
+                       }
+               }
+       }
+}
+#else
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = fgcp;
+       i = len+2;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               fpt = fgcp;
+               spt = seq[j];
+               gc = ( sgappat[j] == '-' );
+               i = len;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *spt++ == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                       }
+               }
+       }
+}
+#endif
+void new_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len, char *egappat )
+#if 0
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[len-1] += feff;
+                       }
+               }
+       }
+}
+#else
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = fgcp;
+       i = len;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               fpt = fgcp;
+               spt = seq[j];
+               gc = ( *spt == '-' );
+               i = len;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *++spt == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                       }
+               }
+       }
+}
+#endif
+
+void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = ogcp;
+       i = len;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               spt = seq[j];
+               fpt = ogcp;
+               gc = 0;
+//             gc = 1;
+               i = len;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *spt++ == '-' );
+                       {
+                               if( !gb *  gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+       }
+       ogcp[len] = 0.0;
+}
+
+void st_FinalGapCount_zure( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = fgcp;
+       i = len+1;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               fpt = fgcp+1;
+               spt = seq[j];
+               gc = ( *spt == '-' );
+               i = len;
+//             for( i=1; i<len; i++ ) 
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *++spt == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+//                     gc = 1;
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                       }
+               }
+       }
+}
+
+void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = fgcp;
+       i = len;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               fpt = fgcp;
+               spt = seq[j];
+               gc = ( *spt == '-' );
+               i = len;
+//             for( i=1; i<len; i++ ) 
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *++spt == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+               {
+                       gb = gc;
+                       gc = 0;
+//                     gc = 1;
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                       }
+               }
+       }
+}
+
+void getGapPattern( float *fgcp, int clus, char **seq, double *eff, int len, char *xxx )
+{
+       int i, j, gc, gb; 
+       float feff;
+       float *fpt;
+       char *spt;
+       
+       fpt = fgcp;
+       i = len+1;
+       while( i-- ) *fpt++ = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               fpt = fgcp;
+               spt = seq[j];
+               gc = ( *spt == '-' );
+               i = len+1;
+               while( i-- )
+               {
+                       gb = gc;
+                       gc = ( *++spt == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                               fpt++;
+                       }
+               }
+#if 0
+               {
+                       gb = gc;
+                       gc = ( egappat[j] == '-' );
+                       {
+                               if( gb * !gc ) *fpt += feff;
+                       }
+               }
+#endif
+       }
+       for( j=0; j<len; j++ )
+       {
+               fprintf( stderr, "%d, %f\n", j, fgcp[j] );
+       }
+}
+
+void getdigapfreq_st( float *freq, int clus, char **seq, double *eff, int len )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+1; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               if( 0 && seq[i][0] == '-' ) // machigai kamo
+                       freq[0] += feff;
+               for( j=1; j<len; j++ ) 
+               {
+                       if( seq[i][j] == '-' && seq[i][j-1] == '-' )
+                               freq[j] += feff;
+               }
+               if( 0 && seq[i][len-1] == '-' )
+                       freq[len] += feff;
+       }
+//     fprintf( stderr, "\ndigapf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getdiaminofreq_x( float *freq, int clus, char **seq, double *eff, int len )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+2; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               if( seq[i][0] != '-' ) // tadashii
+                       freq[0] += feff;
+               for( j=1; j<len; j++ ) 
+               {
+                       if( seq[i][j] != '-' && seq[i][j-1] != '-' )
+                               freq[j] += feff;
+               }
+               if( 1 && seq[i][len-1] != '-' ) // xxx wo tsukawanaitoki [len-1] nomi
+                       freq[len] += feff;
+       }
+//     fprintf( stderr, "\ndiaaf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getdiaminofreq_st( float *freq, int clus, char **seq, double *eff, int len )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+1; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               if( seq[i][0] != '-' )
+                       freq[0] += feff;
+               for( j=1; j<len; j++ ) 
+               {
+                       if( seq[i][j] != '-' && seq[i][j-1] != '-' )
+                               freq[j] += feff;
+               }
+//             if( 1 && seq[i][len-1] != '-' ) // xxx wo tsukawanaitoki [len-1] nomi
+                       freq[len] += feff;
+       }
+//     fprintf( stderr, "\ndiaaf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getdigapfreq_part( float *freq, int clus, char **seq, double *eff, int len, char *sgappat, char *egappat )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+2; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+//             if( seq[i][0] == '-' )
+               if( seq[i][0] == '-' && sgappat[i] == '-' )
+                       freq[0] += feff;
+               for( j=1; j<len; j++ ) 
+               {
+                       if( seq[i][j] == '-' && seq[i][j-1] == '-' )
+                               freq[j] += feff;
+               }
+//             if( seq[i][len] == '-' && seq[i][len-1] == '-' ) // xxx wo tsukawanaitoki arienai
+               if( egappat[i] == '-' && seq[i][len-1] == '-' )
+                       freq[len] += feff;
+       }
+//     fprintf( stderr, "\ndigapf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getdiaminofreq_part( float *freq, int clus, char **seq, double *eff, int len, char *sgappat, char *egappat )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+2; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               if( seq[i][0] != '-' && sgappat[i] != '-' )
+                       freq[0] += feff;
+               for( j=1; j<len; j++ ) 
+               {
+                       if( seq[i][j] != '-' && seq[i][j-1] != '-' )
+                               freq[j] += feff;
+               }
+//             if( 1 && seq[i][len-1] != '-' ) // xxx wo tsukawanaitoki [len-1] nomi
+               if( egappat[i] != '-'  && seq[i][len-1] != '-' ) // xxx wo tsukawanaitoki [len-1] nomi
+                       freq[len] += feff;
+       }
+//     fprintf( stderr, "\ndiaaf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getgapfreq_zure_part( float *freq, int clus, char **seq, double *eff, int len, char *sgap )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+2; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               if( sgap[i] == '-' )
+                       freq[0] += feff;
+               for( j=0; j<len; j++ ) 
+               {
+                       if( seq[i][j] == '-' )
+                               freq[j+1] += feff;
+               }
+//             if( egap[i] == '-' )
+//                     freq[len+1] += feff;
+       }
+//     fprintf( stderr, "\ngapf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getgapfreq_zure( float *freq, int clus, char **seq, double *eff, int len )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+1; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               for( j=0; j<len; j++ ) 
+               {
+                       if( seq[i][j] == '-' )
+                               freq[j+1] += feff;
+               }
+       }
+       freq[len+1] = 0.0;
+//     fprintf( stderr, "\ngapf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void getgapfreq( float *freq, int clus, char **seq, double *eff, int len )
+{
+       int i, j;
+       float feff;
+       for( i=0; i<len+1; i++ ) freq[i] = 0.0;
+       for( i=0; i<clus; i++ )
+       {
+               feff = eff[i];
+               for( j=0; j<len; j++ ) 
+               {
+                       if( seq[i][j] == '-' )
+                               freq[j] += feff;
+               }
+       }
+       freq[len] = 0.0;
+//     fprintf( stderr, "\ngapf = \n" );
+//     for( i=0; i<len+1; i++ ) fprintf( stderr, "%5.3f ", freq[i] );
+}
+
+void st_getGapPattern( Gappat **pat, int clus, char **seq, double *eff, int len )
+{
+       int i, j, k, gb, gc; 
+       int known;
+       float feff;
+       Gappat **fpt;
+       char *spt;
+       int gaplen;
+
+       fpt = pat;
+       i = len+1;
+       while( i-- ) 
+       {
+               if( *fpt ) free( *fpt );
+               *fpt++ = NULL;
+       }
+
+       for( j=0; j<clus; j++ ) 
+       {
+//             fprintf( stderr, "seq[%d] = %s\n", j, seq[j] );
+               feff = (float)eff[j];
+
+               fpt = pat;
+               *fpt = NULL; // Falign.c kara yobareru tokiha chigau.
+               spt = seq[j];
+               gc = 0;
+               gaplen = 0;
+
+               for( i=0; i<len+1; i++ ) 
+//             while( i-- )
+               {
+//                     fprintf( stderr, "i=%d, gaplen = %d\n", i, gaplen );
+                       gb = gc;
+                       gc = ( i != len && *spt++ == '-' );
+                       if( gc ) 
+                               gaplen++;
+                       else
+                       {
+                               if( gb && gaplen )
+                               {
+                                       k = 1;
+                                       known = 0;
+                                       if( *fpt ) for( ; (*fpt)[k].len != -1; k++ )
+                                       {
+                                               if( (*fpt)[k].len == gaplen ) 
+                                               {
+//                                                     fprintf( stderr, "known\n" );
+                                                       known = 1;
+                                                       break;
+                                               }
+                                       }
+
+                                       if( known == 0 )
+                                       {
+                                               *fpt = (Gappat *)realloc( *fpt, (k+3) *  sizeof( Gappat ) );  // mae1 (total), ato2 (len0), term
+                                               if( !*fpt )
+                                               {
+                                                       fprintf( stderr, "Cannot allocate gappattern!'n" );
+                                                       fprintf( stderr, "Use an approximate method, with the --mafft5 option.\n" );
+                                                       exit( 1 );
+                                               }
+                                               (*fpt)[k].freq = 0.0;
+                                               (*fpt)[k].len = gaplen;
+                                               (*fpt)[k+1].len = -1;
+                                               (*fpt)[k+1].freq = 0.0; // iranai
+//                                             fprintf( stderr, "gaplen=%d, Unknown, %f\n", gaplen, (*fpt)[k].freq );
+                                       }
+
+//                                     fprintf( stderr, "adding pos %d, len=%d, k=%d, freq=%f->", i, gaplen, k, (*fpt)[k].freq );
+                                       (*fpt)[k].freq += feff;
+//                                     fprintf( stderr, "%f\n", (*fpt)[k].freq );
+                                       gaplen = 0;
+                               }
+                       }
+                       fpt++;
+               }
+       }
+#if 1
+       for( j=0; j<len+1; j++ )
+       {
+               if( pat[j] )
+               {
+//                     fprintf( stderr, "j=%d\n", j );
+//                     for( i=1; pat[j][i].len!=-1; i++ )
+//                             fprintf( stderr, "pos=%d, i=%d, len=%d, freq=%f\n", j, i, pat[j][i].len, pat[j][i].freq );
+
+                       pat[j][0].len = 0; // iminashi
+                       pat[j][0].freq = 0.0;
+                       for( i=1; pat[j][i].len!=-1;i++ )
+                       {
+                               pat[j][0].freq += pat[j][i].freq;
+//                             fprintf( stderr, "totaling, i=%d, result = %f\n", i, pat[j][0].freq );
+                       }
+//                     fprintf( stderr, "totaled, result = %f\n", pat[j][0].freq );
+
+                       pat[j][i].freq = 1.0 - pat[j][0].freq;
+                       pat[j][i].len = 0; // imiari
+                       pat[j][i+1].len = -1; 
+               }
+               else
+               {
+                       pat[j] = (Gappat *)calloc( 3, sizeof( Gappat ) );
+                       pat[j][0].freq = 0.0;
+                       pat[j][0].len = 0; // iminashi
+
+                       pat[j][1].freq = 1.0 - pat[j][0].freq;
+                       pat[j][1].len = 0; // imiari
+                       pat[j][2].len = -1; 
+               }
+       }
+#endif
+}
+
+static void commongappickpair( char *r1, char *r2, char *i1, char *i2 )
+{
+//     strcpy( r1, i1 );
+//     strcpy( r2, i2 );
+//     return; // not SP
+       while( *i1 )
+       {
+               if( *i1 == '-' && *i2 == '-' ) 
+               {
+                       i1++;
+                       i2++;
+               }
+               else
+               {
+                       *r1++ = *i1++;
+                       *r2++ = *i2++;
+               }
+       }
+       *r1 = 0;
+       *r2 = 0;
+}
+
+float naiveRpairscore( int n1, int n2, char **seq1, char **seq2, double *eff1, double *eff2, int penal )
+{
+//     return( 0 );
+       int i, j;
+       float val;
+       float  valf;
+       int  pv;
+       double deff;
+       char *p1, *p2, *p1p, *p2p;
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               deff = eff1[i] * eff2[j];
+//             fprintf( stderr, "feff %d-%d = %f\n", i, j, feff );
+//             fprintf( stderr, "i1 = %s\n", seq1[i] );
+//             fprintf( stderr, "i2 = %s\n", seq2[j] );
+//             fprintf( stderr, "s1 = %s\n", s1 );
+//             fprintf( stderr, "s2 = %s\n", s2 );
+//             fprintf( stderr, "penal = %d\n", penal );
+
+               valf = 0;
+               p1 = seq1[i]; p2 = seq2[j];
+               pv = 0;
+               if( *p1 == '-' && *p2 != '-' )
+                       pv = penal;
+               if( *p1 != '-' && *p2 == '-' )
+                       pv = penal;
+//             if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, p1-seq1[i], p2-seq2[j] );
+               p1p = p1; p2p = p2;
+               valf += (float)amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+               while( *p1p )
+               {
+                       pv = 0;
+                       if( *p1p != '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p == '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p != '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal * 2; // ??
+//                                     ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       pv = penal;
+//                                     ;
+                       }
+                       if( *p1p == '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal * 2; // ??
+//                                     ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       pv = penal;
+//                                     ;
+                       }
+//                     fprintf( stderr, "adding %c-%c, %d\n", *p1, *p2, amino_dis[*p1][*p2] );
+//                     if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, p1-seq1[i], p2-seq2[j] );
+                       valf += amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+                       p1p++; p2p++;
+               }
+//             fprintf( stderr, "valf = %d\n", valf );
+               val += deff * ( valf );
+       }
+       fprintf( stderr, "val = %f\n", val );
+       return( val );
+//     exit( 1 );
+}
+float naiveQpairscore( int n1, int n2, char **seq1, char **seq2, double *eff1, double *eff2, int penal )
+{
+       int i, j;
+       float val;
+       float  valf;
+       int  pv;
+       double deff;
+       char *p1, *p2, *p1p, *p2p;
+       return( 0 );
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               deff = eff1[i] * eff2[j];
+//             fprintf( stderr, "feff %d-%d = %f\n", i, j, feff );
+//             fprintf( stderr, "i1 = %s\n", seq1[i] );
+//             fprintf( stderr, "i2 = %s\n", seq2[j] );
+//             fprintf( stderr, "s1 = %s\n", s1 );
+//             fprintf( stderr, "s2 = %s\n", s2 );
+//             fprintf( stderr, "penal = %d\n", penal );
+
+               valf = 0;
+               p1 = seq1[i]; p2 = seq2[j];
+               pv = 0;
+               if( *p1 == '-' && *p2 != '-' )
+                       pv = penal;
+               if( *p1 != '-' && *p2 == '-' )
+                       pv = penal;
+//             if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, p1-seq1[i], p2-seq2[j] );
+               p1p = p1; p2p = p2;
+               valf += (float)amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+               while( *p1p )
+               {
+                       pv = 0;
+                       if( *p1p != '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p == '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p != '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal * 2; // ??
+//                                     ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 == '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                       }
+                       if( *p1p == '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal * 2; // ??
+//                                     ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+//                                     ;
+                               if( *p1 == '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                       }
+//                     fprintf( stderr, "adding %c-%c, %d\n", *p1, *p2, amino_dis[*p1][*p2] );
+//                     if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, p1-seq1[i], p2-seq2[j] );
+                       valf += amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+                       p1p++; p2p++;
+               }
+//             fprintf( stderr, "valf = %d\n", valf );
+               val += deff * ( valf );
+       }
+       fprintf( stderr, "val = %f\n", val );
+       return( val );
+//     exit( 1 );
+}
+float naiveHpairscore( int n1, int n2, char **seq1, char **seq2, double *eff1, double *eff2, int penal )
+{
+       int i, j;
+       float val;
+       float  valf;
+       int  pv;
+//     float feff = 0.0; // by D.Mathog, a guess
+       double deff;
+       char *p1, *p2, *p1p, *p2p;
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               deff = eff1[i] * eff2[j];
+//             fprintf( stderr, "i1 = %s\n", seq1[i] );
+//             fprintf( stderr, "i2 = %s\n", seq2[j] );
+//             fprintf( stderr, "s1 = %s\n", s1 );
+//             fprintf( stderr, "s2 = %s\n", s2 );
+//             fprintf( stderr, "penal = %d\n", penal );
+
+               valf = 0;
+               p1 = seq1[i]; p2 = seq2[j];
+               pv = 0;
+               if( *p1 == '-' && *p2 != '-' )
+                       pv = penal;
+               if( *p1 != '-' && *p2 == '-' )
+                       pv = penal;
+               if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, (int)(p1-seq1[i]), (int)(p2-seq2[j]) );
+               p1p = p1; p2p = p2;
+               valf += (float)amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+               while( *p1p )
+               {
+                       pv = 0;
+                       if( *p1p != '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       pv = penal;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p == '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 == '-' && *p2 == '-' )
+                                       ;
+                       }
+                       if( *p1p != '-' && *p2p == '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+                               if( *p1 == '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                       }
+                       if( *p1p == '-' && *p2p != '-' )
+                       {
+                               if( *p1 == '-' && *p2 != '-' )
+                                       ;
+                               if( *p1 != '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                               if( *p1 != '-' && *p2 != '-' )
+                                       pv = penal;
+                               if( *p1 == '-' && *p2 == '-' )
+//                                     pv = penal;
+                                       ;
+                       }
+//                     fprintf( stderr, "adding %c-%c, %d\n", *p1, *p2, amino_dis[*p1][*p2] );
+//                     if( pv ) fprintf( stderr, "Penal!, %f, %d-%d, pos1,pos2=%d,%d\n", pv * deff * 0.5,  i, j, p1-seq1[i], p2-seq2[j] );
+                       valf += amino_dis[(int)*p1++][(int)*p2++] + 0.5 * pv;
+                       p1p++; p2p++;
+               }
+//             fprintf( stderr, "valf = %d\n", valf );
+               val += deff * ( valf );
+       }
+       fprintf( stderr, "val = %f\n", val );
+       return( val );
+//     exit( 1 );
+}
+
+float naivepairscore11( char *seq1, char *seq2, int penal )
+{
+       float  vali;
+       int len = strlen( seq1 );
+       char *s1, *s2, *p1, *p2;
+       s1 = calloc( len+1, sizeof( char ) );
+       s2 = calloc( len+1, sizeof( char ) );
+       {
+               vali = 0.0;
+               commongappickpair( s1, s2, seq1, seq2 );
+//             fprintf( stderr, "###i1 = %s\n", seq1 );
+//             fprintf( stderr, "###i2 = %s\n", seq2 );
+//             fprintf( stderr, "###penal = %d\n", penal );
+
+               p1 = s1; p2 = s2;
+               while( *p1 )
+               {
+                       if( *p1 == '-' )
+                       {
+//                             fprintf( stderr, "Penal! %c-%c in %d-%d, %f\n", *(p1-1), *(p2-1), i, j, feff );
+                               vali += (float)penal;
+//                             while( *p1 == '-' || *p2 == '-' ) 
+                               while( *p1 == '-' )  // SP
+                               {
+                                       p1++;
+                                       p2++;
+                               }
+                               continue;
+                       }
+                       if( *p2 == '-' )
+                       {
+//                             fprintf( stderr, "Penal! %c-%c in %d-%d, %f\n", *(p1-1), *(p2-1), i, j, feff );
+                               vali +=  (float)penal;
+//                             while( *p2 == '-' || *p1 == '-' ) 
+                               while( *p2 == '-' )  // SP
+                               {
+                                       p1++;
+                                       p2++;
+                               }
+                               continue;
+                       }
+//                     fprintf( stderr, "adding %c-%c, %d\n", *p1, *p2, amino_dis[*p1][*p2] );
+                       vali += (float)amino_dis[(int)*p1++][(int)*p2++];
+               }
+       }
+       free( s1 );
+       free( s2 );
+//     fprintf( stderr, "###vali = %d\n", vali );
+       return( vali );
+}
+
+float naivepairscore( int n1, int n2, char **seq1, char **seq2, double *eff1, double *eff2, int penal )
+{
+//     return( 0.0 );
+       int i, j;
+       float val;
+       int  vali;
+       float feff;
+       int len = strlen( seq1[0] );
+       char *s1, *s2, *p1, *p2;
+       s1 = calloc( len+1, sizeof( char ) );
+       s2 = calloc( len+1, sizeof( char ) );
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               vali = 0;
+               feff = eff1[i] * eff2[j];
+//             fprintf( stderr, "feff %d-%d = %f\n", i, j, feff );
+               commongappickpair( s1, s2, seq1[i], seq2[j] );
+//             fprintf( stderr, "i1 = %s\n", seq1[i] );
+//             fprintf( stderr, "i2 = %s\n", seq2[j] );
+//             fprintf( stderr, "s1 = %s\n", s1 );
+//             fprintf( stderr, "s2 = %s\n", s2 );
+//             fprintf( stderr, "penal = %d\n", penal );
+
+               p1 = s1; p2 = s2;
+               while( *p1 )
+               {
+                       if( *p1 == '-' )
+                       {
+//                             fprintf( stderr, "Penal! %c-%c in %d-%d, %f\n", *(p1-1), *(p2-1), i, j, feff );
+                               vali += penal;
+//                             while( *p1 == '-' || *p2 == '-' ) 
+                               while( *p1 == '-' )  // SP
+                               {
+                                       p1++;
+                                       p2++;
+                               }
+                               continue;
+                       }
+                       if( *p2 == '-' )
+                       {
+//                             fprintf( stderr, "Penal! %c-%c in %d-%d, %f\n", *(p1-1), *(p2-1), i, j, feff );
+                               vali +=  penal;
+//                             while( *p2 == '-' || *p1 == '-' ) 
+                               while( *p2 == '-' )  // SP
+                               {
+                                       p1++;
+                                       p2++;
+                               }
+                               continue;
+                       }
+//                     fprintf( stderr, "adding %c-%c, %d\n", *p1, *p2, amino_dis[*p1][*p2] );
+                       vali += amino_dis[(int)*p1++][(int)*p2++];
+               }
+//             fprintf( stderr, "vali = %d\n", vali );
+               val += feff * vali;
+       }
+       free( s1 );
+       free( s2 );
+       fprintf( stderr, "val = %f\n", val );
+       return( val );
+//     exit( 1 );
+}
+
+double plainscore( int nseq, char **s )
+{
+       int i, j, ilim;
+       double v = 0.0;
+       
+       ilim = nseq-1;
+       for( i=0; i<ilim; i++ ) for( j=i+1; j<nseq; j++ )
+       {
+               v += (double)naivepairscore11( s[i], s[j], penalty );
+       }
+
+       fprintf( stderr, "penalty = %d\n", penalty );
+
+       return( v );
+}
+
diff --git a/binaries/src/mafft/core/mtxutl.c b/binaries/src/mafft/core/mtxutl.c
new file mode 100644 (file)
index 0000000..d88e79f
--- /dev/null
@@ -0,0 +1,562 @@
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include "mtxutl.h"
+
+void MtxuntDouble( double **mtx, int n )
+{
+    int i, j;
+    for( i=0; i<n; i++ ) for( j=0; j<n; j++ ) mtx[i][j] = 0.0;
+    for( i=0; i<n; i++ ) mtx[i][i] = 1.0;
+}
+
+void MtxmltDouble( double **mtx1, double **mtx2, int n )
+{
+    int i, j, k;
+    double s, *tmp;
+
+       tmp = (double *)calloc( n, sizeof( double ) );
+    for( i=0; i<n; i++ ) 
+    {
+        for( k=0; k<n; k++ ) tmp[k] = mtx1[i][k];
+        for( j=0; j<n; j++ ) 
+        {
+            s = 0.0;
+            for( k=0; k<n; k++ ) s += tmp[k] * mtx2[k][j];
+            mtx1[i][j] = s;
+        }
+    }
+       free( tmp );
+}
+
+char *AllocateCharVec( int l1 )
+{
+       char *cvec;
+       
+       cvec = (char *)calloc( l1, sizeof( char ) );
+       if( cvec == NULL )
+       {
+               fprintf( stderr, "Cannot allocate %d character vector.\n", l1 );
+               exit( 1 );
+       }
+       return( cvec );
+}
+       
+#if 0
+void ReallocateCharMtx( char **mtx, int l1, int l2 )
+{
+       int i;
+       char *bk = (char *)malloc( l2+1 ); // hontou ha iranai
+       if( bk == NULL )
+       {
+               fprintf( stderr, "Cannot allocate bk in ReallocateCharMtx\n" );
+               exit( 1 );
+       }
+       for( i=0; i<l1; i++ ) 
+       {
+#if 1
+               strcpy( bk, mtx[i] );
+               mtx[i] = (char *)realloc( mtx[i], (l2+1) * sizeof( char ) );
+               if( mtx[i] == NULL )
+               {
+                       fprintf( stderr, "Cannot reallocate %d x %d character matrix.\n", l1, l2 );
+               }
+               if( strcmp( bk, mtx[i] ) ) // hontou ha iranai
+               {
+                       fprintf( stderr, "changed!! \n%s\n \nto\n%s\n in realloc..\n", bk, mtx[i] );
+                       strcpy( mtx[i], bk );
+               }
+#else
+               strcpy( bk, mtx[i] );
+               free( mtx[i] );
+               mtx[i] = (char *)calloc( (l2+1), sizeof( char ) );
+               strcpy( mtx[i], bk );
+#endif
+       }
+       free( bk ); // hontou ha iranai
+} 
+#else
+void ReallocateCharMtx( char **mtx, int l1, int l2 )
+{
+       int i;
+       for( i=0; i<l1; i++ ) 
+       {
+               mtx[i] = (char *)realloc( mtx[i], (l2+1) * sizeof( char ) );
+               if( mtx[i] == NULL )
+               {
+                       fprintf( stderr, "Cannot reallocate %d x %d character matrix.\n", l1, l2 );
+               }
+       }
+} 
+#endif
+
+char **AllocateCharMtx( int l1, int l2 )
+{
+       int i;
+       char **cmtx;
+       
+       cmtx = (char **)calloc( l1+1, sizeof( char * ) );
+       if( cmtx == NULL )
+       {
+               fprintf( stderr, "Cannot allocate %d x %d character matrix.\n", l1, l2 );
+               exit( 1 );
+       }   
+       if( l2 )
+       {
+               for( i=0; i<l1; i++ ) 
+               {
+                       cmtx[i] = AllocateCharVec( l2 );
+               }
+       }
+       cmtx[l1] = NULL;
+       return( cmtx );
+} 
+
+void FreeCharMtx( char **mtx )
+{
+/*
+       char **x;
+       x = mtx;
+       while( *x != NULL ) free( *x++ );
+       free( mtx );
+*/
+       int i;
+       for( i=0; mtx[i]; i++ ) 
+       {
+               free( mtx[i] );
+       }
+       free( mtx );
+}
+
+float *AllocateFloatVec( int l1 )
+{
+       float *vec;
+
+       vec = (float *)calloc( (unsigned int)l1, sizeof( float ) );
+       if( vec == NULL )
+       {
+               fprintf( stderr, "Allocation error ( %d fload vec )\n", l1 );
+               exit( 1 );
+       }
+       return( vec );
+}
+
+void FreeFloatVec( float *vec )
+{
+       free( (char *)vec );
+}
+
+float **AllocateFloatHalfMtx( int ll1 )
+{
+       float **mtx;
+       int i;
+
+       mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       if( mtx == NULL )
+       {
+               fprintf( stderr, "Allocation error ( %d fload halfmtx )\n", ll1 );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ )
+       {
+               mtx[i] = (float *)calloc( ll1-i, sizeof( float ) );
+               if( !mtx[i] )
+               {
+                       fprintf( stderr, "Allocation error( %d floathalfmtx )\n", ll1 );
+                       exit( 1 );
+               }
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
+float **AllocateFloatMtx( int ll1, int ll2 )
+{
+       float **mtx;
+       int i;
+
+       mtx = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       if( mtx == NULL )
+       {
+               fprintf( stderr, "Allocation error ( %d x %d fload mtx )\n", ll1, ll2 );
+               exit( 1 );
+       }
+       if( ll2 )
+       {
+               for( i=0; i<ll1; i++ )
+               {
+                       mtx[i] = (float *)calloc( ll2, sizeof( float ) );
+                       if( !mtx[i] )
+                       {
+                               fprintf( stderr, "Allocation error( %d x %d floatmtx )\n", ll1, ll2 );
+                               exit( 1 );
+                       }
+               }
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
+void FreeFloatHalfMtx( float **mtx, int n )
+{
+       int i;
+
+       for( i=0; i<n; i++ ) 
+       {
+               if( mtx[i] ) FreeFloatVec( mtx[i] );
+       }
+       free( mtx );
+}
+void FreeFloatMtx( float **mtx )
+{
+       int i;
+
+       for( i=0; mtx[i]; i++ ) 
+       {
+               FreeFloatVec( mtx[i] );
+       }
+       free( mtx );
+}
+
+int *AllocateIntVec( int ll1 )
+{
+       int *vec;
+
+       vec = (int *)calloc( ll1, sizeof( int ) );
+       if( vec == NULL )
+       {       
+               fprintf( stderr, "Allocation error( %d int vec )\n", ll1 );
+               exit( 1 );
+       }
+       return( vec );
+}      
+
+void FreeIntVec( int *vec )
+{
+       free( (char *)vec );
+}
+
+float **AllocateFloatTri( int ll1 )
+{
+       float **tri;
+       int i;
+
+       tri = (float **)calloc( (unsigned int)ll1+1, sizeof( float * ) );
+       if( !tri )
+       {
+               fprintf( stderr, "Allocation error ( float tri )\n" );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ ) 
+       {
+               tri[i] = AllocateFloatVec( i+3 );
+       }
+       tri[ll1] = NULL;
+               
+       return( tri );
+}
+
+void FreeFloatTri( float **tri )
+{
+/*
+       float **x;
+       x = tri;
+       while( *tri != NULL ) free( *tri++ );
+       free( x );
+*/
+       int i;
+       for( i=0; tri[i]; i++ ) 
+               free( tri[i] );
+       free( tri );
+}
+               
+int **AllocateIntMtx( int ll1, int ll2 )
+{
+       int i;
+       int **mtx;
+
+       mtx = (int **)calloc( ll1+1, sizeof( int * ) );
+       if( !mtx )
+       {
+               fprintf( stderr, "Allocation error( %d x %d int mtx )\n", ll1, ll2 );
+               exit( 1 );
+       }
+       if( ll2 )
+       {
+               for( i=0; i<ll1; i++ ) 
+               {
+                       mtx[i] = AllocateIntVec( ll2 );
+               }
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
+/*
+void FreeIntMtx( int **mtx )
+{
+*
+       int **x;
+       x = mtx;
+       while( !*mtx ) free( *mtx++ );
+       free( x );
+*
+       int i;
+       for( i=0; mtx[i] != NULL; i++ ) 
+               free( (char *)mtx[i] );
+       free( (char *)mtx );
+}
+*/
+
+char ***AllocateCharCub( int ll1, int ll2, int  ll3 )
+{
+       int i;
+       char ***cub;
+
+       cub = (char ***)calloc( ll1+1, sizeof( char ** ) );
+       if( !cub ) 
+       {
+               fprintf( stderr, "Allocation error( %d x %d x %d char cube\n", ll1, ll2, ll3 );
+               exit( 1 );
+       }
+       if( ll2 )
+       {
+               for( i=0; i<ll1; i++ ) 
+               {
+                       cub[i] = AllocateCharMtx( ll2, ll3 );
+               }
+       }
+       cub[ll1] = NULL;
+       return( cub );
+}
+
+void FreeCharCub( char ***cub )
+{
+       int i;
+
+       for( i=0; cub[i]; i++ ) 
+       {
+               FreeCharMtx( cub[i] );
+       }
+       free( cub );
+}
+
+void freeintmtx( int **mtx, int ll1, int ll2 )
+{
+    int i;
+
+    for( i=0; i<ll1; i++ ) 
+        free( (char *)mtx[i] );
+    free( (char *)mtx );
+}
+      
+void FreeIntMtx( int **mtx )
+{
+       int i;
+
+       for( i=0; mtx[i]; i++ ) 
+               free( (char *)mtx[i] );
+       free( (char *)mtx );
+}
+
+char ****AllocateCharHcu( int ll1, int ll2, int ll3, int ll4 )
+{
+       int i;
+       char ****hcu;
+
+       hcu = (char ****)calloc( ll1+1, sizeof( char *** ) );
+       if( hcu == NULL ) exit( 1 );
+       for( i=0; i<ll1; i++ ) 
+               hcu[i] = AllocateCharCub( ll2, ll3, ll4 );
+       hcu[ll1] = NULL;
+       return( hcu );
+}
+
+void FreeCharHcu( char ****hcu )
+{
+       int i;
+       for( i=0; hcu[i]; i++ )
+       {
+               FreeCharCub( hcu[i] );
+       }
+       free ( (char *)hcu );
+}
+
+double *AllocateDoubleVec( int ll1 )
+{
+       double *vec;
+
+       vec = (double *)calloc( ll1, sizeof( double ) );
+       return( vec );
+}
+
+void FreeDoubleVec( double *vec )
+{
+       free( vec );
+}
+
+int ***AllocateIntCub( int ll1, int ll2, int ll3 )
+{
+       int i;
+       int ***cub;
+
+       cub = (int ***)calloc( ll1+1, sizeof( int ** ) );
+       if( cub == NULL )
+       {
+               fprintf( stderr, "cannot allocate IntCub\n" );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ ) 
+               cub[i] = AllocateIntMtx( ll2, ll3 );
+       cub[ll1] = NULL;
+
+       return cub;
+}
+
+void FreeIntCub( int ***cub )
+{
+       int i;
+       for( i=0; cub[i]; i++ ) 
+       {
+               FreeIntMtx( cub[i] );
+       }
+       free( cub );
+}
+
+double **AllocateDoubleMtx( int ll1, int ll2 )
+{
+       int i;
+       double **mtx;
+       mtx = (double **)calloc( ll1+1, sizeof( double * ) );
+       if( !mtx )
+       {
+               fprintf( stderr, "cannot allocate DoubleMtx\n" );
+               exit( 1 );
+       }
+       if( ll2 )
+       {
+               for( i=0; i<ll1; i++ ) 
+                       mtx[i] = AllocateDoubleVec( ll2 );
+       }
+       mtx[ll1] = NULL;
+
+       return mtx;
+}
+
+void FreeDoubleMtx( double **mtx )
+{
+       int i;
+       for( i=0; mtx[i]; i++ )
+               FreeDoubleVec( mtx[i] );
+       free( mtx );
+}
+
+float ***AllocateFloatCub( int ll1, int ll2, int  ll3 )
+{
+       int i;
+       float ***cub;
+
+       cub = (float ***)calloc( ll1+1, sizeof( float ** ) );
+       if( !cub ) 
+       {
+               fprintf( stderr, "cannot allocate float cube.\n" );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ ) 
+       {
+               cub[i] = AllocateFloatMtx( ll2, ll3 );
+       }
+       cub[ll1] = NULL;
+       return( cub );
+}
+
+void FreeFloatCub( float ***cub )
+{
+       int i;
+
+       for( i=0; cub[i]; i++ ) 
+       {
+               FreeFloatMtx( cub[i] );
+       }
+       free( cub );
+}
+
+double ***AllocateDoubleCub( int ll1, int ll2, int  ll3 )
+{
+       int i;
+       double ***cub;
+
+       cub = (double ***)calloc( ll1+1, sizeof( double ** ) );
+       if( !cub ) 
+       {
+               fprintf( stderr, "cannot allocate double cube.\n" );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ ) 
+       {
+               cub[i] = AllocateDoubleMtx( ll2, ll3 );
+       }
+       cub[ll1] = NULL;
+       return( cub );
+}
+
+void FreeDoubleCub( double ***cub )
+{
+       int i;
+
+       for( i=0; cub[i]; i++ ) 
+       {
+               FreeDoubleMtx( cub[i] );
+       }
+       free( cub );
+}
+
+
+short *AllocateShortVec( int ll1 )
+{
+       short *vec;
+
+       vec = (short *)calloc( ll1, sizeof( short ) );
+       if( vec == NULL )
+       {       
+               fprintf( stderr, "Allocation error( %d short vec )\n", ll1 );
+               exit( 1 );
+       }
+       return( vec );
+}      
+
+void FreeShortVec( short *vec )
+{
+       free( (char *)vec );
+}
+
+short **AllocateShortMtx( int ll1, int ll2 )
+{
+       int i;
+       short **mtx;
+
+
+       mtx = (short **)calloc( ll1+1, sizeof( short * ) );
+       if( !mtx )
+       {
+               fprintf( stderr, "Allocation error( %d x %d short mtx ) \n", ll1, ll2 );
+               exit( 1 );
+       }
+       for( i=0; i<ll1; i++ ) 
+       {
+               mtx[i] = AllocateShortVec( ll2 );
+       }
+       mtx[ll1] = NULL;
+       return( mtx );
+}
+
+void FreeShortMtx( short **mtx )
+{
+       int i;
+
+       for( i=0; mtx[i]; i++ ) 
+               free( (char *)mtx[i] );
+       free( (char *)mtx );
+}
+
diff --git a/binaries/src/mafft/core/mtxutl.h b/binaries/src/mafft/core/mtxutl.h
new file mode 100644 (file)
index 0000000..dd31321
--- /dev/null
@@ -0,0 +1,50 @@
+void MtxuntDouble( double **, int );
+void MtxmltDouble( double **, double **, int );
+
+char *AllocateCharVec( int );
+void FreeCharVec( char * );
+
+char **AllocateCharMtx( int, int);
+void ReallocateCharMtx( char **, int, int);
+void FreeCharMtx( char ** );
+
+float *AllocateFloatVec( int );
+void FreeFloatVec( float * );
+
+float **AllocateFloatHalfMtx( int );
+float **AllocateFloatMtx( int, int );
+void FreeFloatHalfMtx( float **, int );
+void FreeFloatMtx( float ** );
+
+float **AlocateFloatTri( int );
+void FreeFloatTri( float ** );
+
+int *AllocateIntVec( int );
+void FreeIntVec( int * );
+
+int **AllocateIntMtx( int, int );
+void FreeIntMtx( int ** );
+
+char ***AllocateCharCub( int, int, int );
+void FreeCharCub( char *** );
+
+int ***AllocateIntCub( int, int, int );
+void FreeIntCub( int *** );
+
+double *AllocateDoubleVec( int );
+void FreeDoubleVec( double * );
+
+double **AllocateDoubleMtx( int, int );
+void FreeDoubleMtx( double ** );
+
+double ***AllocateDoubleCub( int, int, int );
+void FreeDoubleCub( double *** );
+
+float ***AllocateFloatCub( int, int, int );
+void FreeFloatCub( float *** );
+
+short *AllocateShortVec( int );
+void FreeShortVec( short * );
+
+short **AllocateShortMtx( int, int );
+void FreeShortMtx( short ** );
diff --git a/binaries/src/mafft/core/multi2hat3s.c b/binaries/src/mafft/core/multi2hat3s.c
new file mode 100644 (file)
index 0000000..f747218
--- /dev/null
@@ -0,0 +1,388 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 1
+#define TSUYOSAFACTOR 100
+
+
+static int nhomologs;
+static int seedoffset;
+
+void strip( char *s )
+{
+       char *pt = s;
+       while( *++pt )
+               if( *pt == '\n' ) *pt = 0;
+}
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       seedoffset = 0;
+       nhomologs = 1;
+       inputfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "seed = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 't':
+                                       nhomologs = atoi( *++argv );
+                                       fprintf( stderr, "nhomologs = %d\n", nhomologs );
+                                       --argc;
+                                       goto nextoption;
+                               case 'o':
+                                       seedoffset = atoi( *++argv );
+                                       fprintf( stderr, "seedoffset = %d\n", seedoffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+static void pairalign( char name[M][B], int nlen[M], char **seq, double *effarr, int alloclen )
+{
+       int i, j;
+       FILE *hat3p;
+       float pscore = 0.0; // by D.Mathog
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       char *aseq;
+       static char **pseq;
+       LocalHom **localhomtable, *tmpptr;
+       double tsuyosa;
+
+       if( nhomologs < 1 ) nhomologs = 1; // tsuyosa=0.0 wo sakeru
+       tsuyosa = (double)nhomologs * nhomologs * TSUYOSAFACTOR;
+       fprintf( stderr, "tsuyosa = %f\n", tsuyosa );
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++)
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1; 
+                       localhomtable[i][j].end2 = -1; 
+                       localhomtable[i][j].opt = -1.0;
+                       localhomtable[i][j].next = NULL;
+               }
+       }
+
+       if( effarr1 == NULL ) 
+       {
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               pseq = AllocateCharMtx( 2, 0 );
+               aseq = AllocateCharVec( nlenmax*9+1 );
+#if 0
+#else
+#endif
+       }
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       fprintf( stderr, "\n" );
+       for( i=0; i<njob-1; i++ )
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       pseq[0] = seq[i];
+                       pseq[1] = seq[j];
+
+                       if( strlen( pseq[0] ) != strlen( pseq[1] ) )
+                       {
+                               fprintf( stderr, "## ERROR  ###\n" );
+                               fprintf( stderr, "Not aligned,  %s - %s\n", name[i], name[j] );
+                               fprintf( stderr, "## ERROR  ###\n" );
+                               exit( 1 );
+                       }
+
+
+                       fprintf( stderr, "adding %d-%d\r", i, j );
+                       putlocalhom2( pseq[0], pseq[1], localhomtable[i]+j, 0, 0, (int)pscore, strlen( pseq[0] ) );
+                       for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               if( tmpptr->start1 == -1 ) continue;
+                               fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d k\n", i+seedoffset, j+seedoffset, tmpptr->overlapaa, tmpptr->opt * tsuyosa, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2 ); 
+                       }
+               }
+       }
+       fprintf( stderr, "\n" );
+       fclose( hat3p );
+
+#if DEBUG
+       fprintf( stderr, "calling FreeLocalHomTable\n" );
+#endif
+       FreeLocalHomTable( localhomtable, njob );
+#if DEBUG
+       fprintf( stderr, "done. FreeLocalHomTable\n" );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'x' )
+               fprintf( fp, "Tree = UPGMA (3).\n" );
+       else if( treemethod == 's' )
+               fprintf( fp, "Tree = UPGMA (2).\n" );
+       else if( treemethod == 'p' )
+               fprintf( fp, "Tree = UPGMA (1).\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char name[M][B], **seq;
+       static char **bseq;
+       static double *eff;
+       int i;
+       char c;
+       int alloclen;
+       FILE *infp;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       alloclen = nlenmax*9;
+
+       eff = AllocateDoubleVec( njob );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+
+       for( i=0; i<njob; i++ ) fprintf( stdout, ">_seed_%s\n%s\n", name[i]+1, bseq[i] );
+
+       pairalign( name, nlen, seq, eff, alloclen );
+
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/newick2mafft.rb b/binaries/src/mafft/core/newick2mafft.rb
new file mode 100644 (file)
index 0000000..b74ba36
--- /dev/null
@@ -0,0 +1,132 @@
+#! /usr/bin/env ruby
+
+#version 2, 2009/01/24
+
+
+if ARGV.length == 1
+       scale = 1.0
+elsif ARGV.length == 2
+       scale = ARGV.shift.to_f
+else
+       STDERR.puts "USAGE: newick2mafft.rb scale input_tree > output"
+       exit
+end
+
+if scale <= 0.0 then
+       STDERR.puts "Inappropriate scale, #{scale.to_s}"
+       exit
+end
+
+STDERR.puts "scale = " + scale.to_s
+
+infp = File.open( ARGV.shift, "r" )
+
+tree = ""
+while line = infp.gets
+       tree += line.strip
+       break if tree =~ /;$/
+end
+infp.close
+
+
+#tree = tree.gsub( /_.*?:/, ":" ).gsub(/[0-9]\.[0-9]*e-[0-9][0-9]/, "0").gsub(/\[.*?\]/,"").gsub(/ /, "").gsub(/:\-[0-9\.]+/, ":0.0" )
+tree = tree.gsub( /_.*?:/, ":" ).gsub(/[0-9]\.[0-9]*e-[0-9][0-9]/, "0").gsub(/\[.*?\]/,"").gsub(/ /, "")
+
+
+STDERR.puts "Initial tree = " +  tree
+
+def resolve( tree )
+
+
+while 1
+#      p tree
+       tree.sub!( /\,([0-9]+):(\-?[0-9\.]+)\,([0-9]+):(\-?[0-9\.]+)/, ",XXX" )
+       hit1 = $1
+       hit2 = $2
+       hit3 = $3
+       hit4 = $4
+
+#      p hit1
+#      p hit2
+#      p hit3
+#      p hit4
+
+#      puts "introduce XXX"
+#      p tree
+
+       break unless tree.index(/XXX/)
+
+       poshit = tree.index(/XXX/)
+#      puts "poshit=" + poshit.to_s
+
+       i = poshit
+       height = 0
+       while i >= 0
+               break if height == 0 && tree[i..i] == '('
+               if tree[i..i] == ')' then
+                       height += 1
+               elsif tree[i..i] == '(' then
+                       height -= 1
+               end
+               i -= 1
+       end
+
+       poskakko = i
+#      puts "poskakko = " + poskakko.to_s
+       zenhan = tree[0..poskakko]
+       zenhan = "" if poskakko == -1
+#      puts "zenhan = " + zenhan
+
+       treelen = tree.length
+       tree = zenhan + "(" + tree[poskakko+1..treelen]
+#      puts "add ("
+#      p tree
+       tree.sub!( /XXX/, "#{hit1}:#{hit2}):0,#{hit3}:#{hit4}" )
+
+#      p tree
+end
+
+
+return tree
+
+end
+
+memi = [-1,-1]
+leni = [-1,-1]
+
+while tree.index( /\(/ ) 
+
+       tree = resolve( tree )
+
+       tree.sub!( /\(([0-9]+):(\-?[0-9\.]+),([0-9]+):(\-?[0-9\.]+)\)/, "XXX" )
+       memi[0] = $1.to_i
+       leni[0] = $2.to_f * scale
+       memi[1] = $3.to_i
+       leni[1] = $4.to_f * scale
+
+       if leni[0] > 10 || leni[1] > 10 then
+               STDERR.puts ""
+               STDERR.puts "Please check the scale of branch length!"
+               STDERR.puts "The unit of branch lengths must be 'substitution/site'"
+               STDERR.puts "If the unit is 'substition' in your tree, please"
+               STDERR.puts "use the scale argument,"
+               STDERR.puts "% newick2mafft scale in > out"
+               STDERR.puts "where scale = 1/(alignment length)"
+               STDERR.puts ""
+               exit 1
+       end
+
+#      STDERR.puts "subtree = " + $&
+
+       if memi[1] < memi[0] then
+               memi.reverse!
+               leni.reverse!
+       end
+
+       tree.sub!( /XXX/, memi[0].to_s )
+
+       STDERR.puts "Tree = " + tree
+
+       printf( "%5d %5d %10.5f %10.5f\n", memi[0], memi[1], leni[0], leni[1] )
+
+end
diff --git a/binaries/src/mafft/core/nj.c b/binaries/src/mafft/core/nj.c
new file mode 100644 (file)
index 0000000..0adf4e5
--- /dev/null
@@ -0,0 +1,195 @@
+#include "mltaln.h"
+#define DEBUG 0
+
+
+void topolcpy( int s1[], int s2[], int *mpt1, int *mpt2 )
+{
+    int i;
+
+    *mpt1 = *mpt2;
+    for( i=0; i<*mpt2; i++ )
+    {
+        s1[i] = s2[i];
+    }
+}
+
+void topolcat( int s1[], int s2[], int *mpt1, int *mpt2 )
+{
+    int i;
+
+    for( i=*mpt1; i<*mpt1+*mpt2; i++ )
+    {
+        s1[i] = s2[i-*mpt1];
+    }
+    *mpt1 += *mpt2;
+}
+   
+void topolsort( int m, int s[] )
+{
+    int i, j, im;
+    int sm;
+
+    for( j=0; j<m-1; j++ )
+    {
+        sm = s[j]; im = j;
+        for( i=j+1; i<m; i++ )
+        {
+            if( s[i] < sm )
+            {
+                sm = s[i];
+                im = i;
+            }
+        }
+        s[im] = s[j]; s[j] = sm;
+    }
+}
+
+void topolswap( int s1[], int s2[], int *mpt1, int *mpt2 )
+{
+    int i;
+    int im;
+    int b;
+    b = *mpt1; *mpt1 = *mpt2; *mpt2 = b;
+    im = MAX(*mpt1,*mpt2);
+    for( i=0; i<im; i++ )
+    {
+        b = s1[i]; s1[i] = s2[i]; s2[i] = b;
+    /*
+    printf( "s1[%d]=%d\ns2[%d]=%d\n", i, s1[i], i, s2[i] );
+    */
+    }
+}
+
+void reduc( double **mtx, int nseq, int im, int jm )
+{
+    int i;
+    for( i=0; i<nseq; i++ )
+    {
+        if(    i==im || i==jm
+            || mtx[MIN(i,im)][MAX(i,im)] == 9999.9
+            || mtx[MIN(i,jm)][MAX(i,jm)] == 9999.9
+          ) continue;
+        mtx[MIN(i,im)][MAX(i,im)]
+        = 0.5 * ( mtx[MIN(i,im)][MAX(i,im)] + mtx[MIN(i,jm)][MAX(i,jm)]
+                  - mtx[MIN(im,jm)][MAX(im,jm)] );
+        mtx[MIN(i,jm)][MAX(i,jm)] = 9999.9;
+    }
+    mtx[MIN(im,jm)][MAX(im,jm)] = 9999.9;
+}
+
+
+void  nj( int nseq, double **omtx, int ***topol, double **dis )
+{
+    int i, j, l, n, m;
+    int count;
+    double r[M];
+    double t;
+    double s, sm;
+    double totallen = 0.0;
+    int im=0, jm=0;
+    double len1, len2;
+#if 1
+       static char **par = NULL;
+       static double **mtx = NULL;
+       static int **mem = NULL;
+       if( par == NULL )
+       {
+               par = AllocateCharMtx( njob, njob );
+               mtx = AllocateDoubleMtx( njob, njob );
+               mem = AllocateIntMtx( njob, 2 );
+       }
+#else
+    char par[njob][njob];
+       double mtx[njob][njob];
+       int mem[njob][2];
+#endif
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) mtx[i][j] = omtx[i][j];
+    for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) par[i][j] = 0;
+    for( i=0; i<nseq; i++ ) par[i][i] = 1;
+//     for( i=0; i<nseq; i++ ) for( j=0; j<2; j++ ) for( l=0; l<nseq+1; l++ ) topol[i][j][l] = -1;
+       for( i=0; i<nseq; i++ ) for( j=0; j<2; j++ ) for( l=0; l<nseq; l++ ) topol[i][j][l] = -1;
+    for( n=nseq, m=0; n>2; n--, m=nseq-n )
+    {
+        t = 0.0;
+        for( i=0; i<nseq-1; i++ ) for( j=0; j<nseq; j++ ) if( mtx[i][j] < 9999.9 )
+            t += mtx[i][j];
+        for( i=0; i<nseq; i++ )
+        {
+            r[i] = 0.0;
+            for( l=0; l<nseq; l++ ) 
+                if( ( l != i ) && ( mtx[MIN(i,l)][MAX(i,l)] < 9999.9 ) )
+                    r[i] += mtx[MIN(i,l)][MAX(i,l)];
+        }
+        sm = 9999.9;
+        for( i=0; i<nseq-1; i++ ) for( j=i+1; j<nseq; j++ ) if( mtx[i][j] < 9999.9)
+        {
+            s = ( ( 2.0 * t - r[i] - r[j] + (n-2.0)*mtx[i][j] ) ) / ( 2.0*(n-2.0) );
+            if ( s < sm )
+            {
+                sm = s;
+                im = i; jm = j;
+            }
+        }
+        len1 = ( (n-2)*mtx[im][jm] + r[im] - r[jm] ) / (2*(n-2));
+        len2 = ( (n-2)*mtx[im][jm] - r[im] + r[jm] ) / (2*(n-2));
+
+#if DEBUG
+        fprintf( stderr, "STEP-%3d  %3d: L = %5.5f\n", m+1, im+1, len1 );
+        fprintf( stderr, "          %3d: L = %5.5f\n",      jm+1, len2 );
+#endif
+
+        totallen += len1;
+        totallen += len2;
+
+        dis[m][0] = len1;
+        dis[m][1] = len2;
+
+        for( l=0, count=0; l<nseq; l++ )
+            if( par[im][l] > 0 )
+            {
+                topol[m][0][count] = l;
+                count++;
+            }
+        mem[m][0] = count;
+        for( l=0, count=0; l<nseq; l++ )
+            if( par[jm][l] > 0 )
+            {
+                topol[m][1][count] = l;
+                count++;
+            }
+        mem[m][1] = count;
+        for( l=0; l<nseq; l++ )
+            par[im][l] += ( par[jm][l] > 0 );
+        if( n > 3 ) reduc( mtx, nseq, im, jm );
+    }
+    for( i=0; i<nseq; i++ )
+        if( i!=im && i!=jm && mtx[MIN(i,im)][MAX(i,im)]<9999.9 )
+            break;
+    len2 = ( mtx[MIN(i,im)][MAX(i,im)] - r[im] + r[i] ) / 2;
+
+/*
+    printf("          %3d: L = %5.5f\n", i+1, len2 );
+*/
+    totallen += len2;
+
+    dis[m][0] = len2;
+    dis[m][1] = 0.0;
+    for( l=0, count=0; l<nseq; l++ )
+        if( par[i][l] > 0 )
+        {
+            topol[m][0][count] = l;
+            count++;
+        }
+    mem[m][0] = count;
+    /*
+    printf( " total length == %f\n", totallen );
+    */
+
+    topolcpy( topol[nseq-2][1], topol[nseq-3][0], mem[nseq-2]+1, mem[nseq-3] );
+    topolcat( topol[nseq-2][1], topol[nseq-3][1], mem[nseq-2]+1, mem[nseq-3]+1 );
+    topolsort( mem[nseq-2][1], topol[nseq-2][1] );
+       
+       if( topol[nseq-2][0][0] > topol[nseq-2][1][0] )
+               topolswap( topol[nseq-2][0], topol[nseq-2][1], mem[nseq-2], mem[nseq-2]+1 );
+
+}
diff --git a/binaries/src/mafft/core/pair2hat3s.c b/binaries/src/mafft/core/pair2hat3s.c
new file mode 100644 (file)
index 0000000..e6e76f5
--- /dev/null
@@ -0,0 +1,467 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 1
+#define TSUYOSAFACTOR 100
+
+
+static char *pairfile;
+static int nhomologs;
+
+void strip( char *s )
+{
+       char *pt = s;
+       while( *++pt )
+               if( *pt == '\n' ) *pt = 0;
+}
+
+int searchused( char *q, char **keys, int n )
+{
+       int i;
+       for( i=0; i<n; i++ )
+       {
+//             fprintf( stderr, "%s ? %s\n", q, names[i] );
+               if( !strcmp( q, keys[i] ) ) return( i );
+       }
+       return( -1 );
+}
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nhomologs = 2;
+       inputfile = NULL;
+       pairfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'p':
+                                       pairfile = *++argv;
+                                       fprintf( stderr, "pairfile = %s\n", pairfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 't':
+                                       nhomologs = atoi( *++argv );
+                                       fprintf( stderr, "nhomologs = %d\n", nhomologs );
+                                       --argc;
+                                       goto nextoption;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+static void pairalign( char name[M][B], int nlen[M], char **seq, double *effarr, int alloclen )
+{
+       FILE *tmpfp;
+       static char dumm1[B], dumm0[B];
+       int i, j;
+       char *res;
+       FILE *hat3p;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       static char **pseq;
+       LocalHom **localhomtable, *tmpptr;
+       float pscore = 0.0; // by D.Mathog, aguess
+       char *aseq = NULL; // by D.Mathog
+       char **usedseqs = NULL; // by D.Mathog
+       char **usednames = NULL; // by D.Mathog
+       int nused;
+       double tsuyosa;
+
+       tsuyosa = (double)nhomologs * (nhomologs-1) / njob * TSUYOSAFACTOR;
+       fprintf( stderr, "tsuyosa = %f\n", tsuyosa );
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++)
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1; 
+                       localhomtable[i][j].end2 = -1; 
+                       localhomtable[i][j].opt = -1.0;
+                       localhomtable[i][j].next = NULL;
+               }
+       }
+
+       if( effarr1 == NULL ) 
+       {
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               pseq = AllocateCharMtx( 2, nlenmax*9+1 );
+               aseq = AllocateCharVec( nlenmax*9+1 );
+               usedseqs = AllocateCharMtx( njob, nlenmax*9+1 );
+               usednames = AllocateCharMtx( njob, B );
+#if 0
+#else
+#endif
+       }
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       fprintf( stderr, "opening %s\n", pairfile  );
+       tmpfp = fopen( pairfile, "r" );
+       if( !tmpfp )
+       {
+               fprintf( stderr, "Cannot open %s\n", pairfile );
+               exit( 1 );
+       }
+       searchKUorWA( tmpfp );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       nused = 0;
+       while( 1 )
+       {
+               res = fgets( dumm0, B-1, tmpfp );
+               strip( dumm0 );
+               if( res == NULL )
+               {
+                       break;
+               }
+               load1SeqWithoutName_new( tmpfp, pseq[0] );
+               gappick0( aseq, pseq[0] );
+               i =  searchused( aseq, usedseqs, nused );
+               if( i == -1 )
+               {
+                       strcpy( usednames[nused], dumm0+1 );
+                       strcpy( usedseqs[nused], aseq );
+                       i = nused;
+                       nused++;
+               }
+               fprintf( stderr, "i = %d\n", i );
+
+               res = fgets( dumm1, B-1, tmpfp );
+               strip( dumm1 );
+               if( res == NULL )
+               {
+                       fprintf( stderr, "ERROR: The number of sequences in %s must be even.\n", pairfile );
+                       exit( 1 );
+               }
+               load1SeqWithoutName_new( tmpfp, pseq[1] );
+               gappick0( aseq, pseq[1] );
+               j =  searchused( aseq, usedseqs, nused );
+               if( j == -1 )
+               {
+                       strcpy( usednames[nused], dumm1+1 );
+                       strcpy( usedseqs[nused], aseq );
+                       j = nused;
+                       nused++;
+               }
+               fprintf( stderr, "j = %d\n", j );
+
+               if( strlen( pseq[0] ) != strlen( pseq[1] ) )
+               {
+                       fprintf( stderr, "Not aligned,  %s - %s\n", dumm0, dumm1 );
+                       exit( 1 );
+               }
+
+
+               fprintf( stderr, "adding %d-%d\n", i, j );
+               putlocalhom2( pseq[0], pseq[1], localhomtable[i]+j, 0, 0, (int)pscore, strlen( pseq[0] ) );
+               for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+               {
+                       if( tmpptr->opt == -1.0 ) continue;
+                       fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt * tsuyosa, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next ); 
+               }
+       }
+       fclose( tmpfp );
+       fclose( hat3p );
+
+       for( i=0; i<nused; i++ )
+               fprintf( stdout, ">%s\n%s\n", usednames[i], usedseqs[i] );
+
+
+#if 0
+       fprintf( stderr, "##### writing hat3\n" );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       ilim = njob-1;  
+       for( i=0; i<ilim; i++ ) 
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               fprintf( hat3p, "%d %d %d %6.3f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt * tsuyosa, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, tmpptr->next ); 
+                       }
+               }
+       }
+       fclose( hat3p );
+#endif
+#if DEBUG
+       fprintf( stderr, "calling FreeLocalHomTable\n" );
+#endif
+       FreeLocalHomTable( localhomtable, njob );
+#if DEBUG
+       fprintf( stderr, "done. FreeLocalHomTable\n" );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'x' )
+               fprintf( fp, "Tree = UPGMA (3).\n" );
+       else if( treemethod == 's' )
+               fprintf( fp, "Tree = UPGMA (2).\n" );
+       else if( treemethod == 'p' )
+               fprintf( fp, "Tree = UPGMA (1).\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char name[M][B], **seq;
+       static char **bseq;
+       static double *eff;
+       int i;
+       char c;
+       int alloclen;
+       FILE *infp;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       if( !pairfile )
+       {
+               fprintf( stderr, "Usage: %s -p pairfile -i inputfile \n", argv[0] );
+               exit( 1 );
+       }
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       alloclen = nlenmax*9;
+
+       eff = AllocateDoubleVec( njob );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+
+       pairalign( name, nlen, bseq, eff, alloclen );
+
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/pairash.c b/binaries/src/mafft/core/pairash.c
new file mode 100644 (file)
index 0000000..1e83e72
--- /dev/null
@@ -0,0 +1,1412 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+static int usecache;
+static char *whereispairalign;
+static double scale;
+static int *alreadyoutput;
+static int equivthreshold;
+static int equivwinsize;
+static int equivshortestlen;
+
+static void cutpath( char *s )
+{
+       char *pos;
+       pos = s + strlen( s );
+
+       while( --pos >= s )
+       {
+               if( *pos == '/' ) break;
+       }
+
+       strcpy( s, pos+1 );
+}
+
+static char getchainid( char *s )
+{
+       s += strlen( s ) - 2;
+       if( isspace( s[0] ) && isalnum( s[1] ) )
+               return( s[1] );
+       else
+               return( 'A' );
+}
+
+static void extractfirstword( char *s )
+{
+       while( *s )
+       {
+               if( isspace( *s ) ) break;
+               s++;
+       }
+       *s = 0;
+}
+
+static char *strip( char *s )
+{
+       char *v;
+
+       while( *s )
+       {
+               if( !isspace( *s ) ) break;
+               s++;
+       }
+       v = s;
+
+       s += strlen( v ) - 1;
+       while( s>=v )
+       {
+               if( !isspace( *s ) ) 
+               {
+                       *(s+1) = 0;
+                       break;
+               }
+               s--;
+       }
+
+       return( v );
+}
+
+#if 0
+static void makeequivdouble( double *d, char *c )
+{
+       while( *c )
+       {
+               *d++ = (double)( *c++ - '0' );
+       }
+}
+
+static void maskequiv( double *d, int n )
+{
+       int halfwin;
+       int ok;
+       int i, j;
+
+       halfwin = (int)( equivwinsize / 2 );
+
+       for( i=0; i<n; i++ )
+       {
+               ok = 1;
+               for( j = i-halfwin; j<i+halfwin; j++ )
+               {
+                       if( j<0 || n=<j ) continue;
+                       if( d[j] <= 0.0 )
+                       {
+                               ok = 0;
+                               break;
+                       }
+               }
+               if( ok == 0 ) d[i] = 0.0;
+       }
+}
+#else
+static void maskequiv( double *d, int n )
+{
+       int i, len;
+       int count;
+       len = 0;
+       double *dbk, *dori, *dbkori;
+
+       dbk = calloc( n, sizeof( double ) );
+
+       dbkori = dbk;
+       dori = d;
+       count = n;
+       while( count-- )
+       {
+               *dbk++ = *d++;
+       }
+
+       dbk = dbkori;
+       d = dori;
+       len = 0;
+
+
+       for( i=0; i<n; i++ )
+       {
+               if( d[i] > 0.0 )
+               {
+                       len += 1;
+                       d[i] = 0.0;
+               }
+               else
+               {
+                       d[i] = 0.0;
+                       if( len >= equivshortestlen ) 
+                       {
+                               len++;
+                               while( len-- ) d[i-len] = dbk[i-len];
+                       }
+                       len = 0;
+               }
+       }
+
+       if( len >= equivshortestlen )
+       {
+               len++;
+               while( len-- ) d[n-len] = dbk[n-len];
+       }
+
+       free( dbk );
+}
+#endif
+
+static void makeequivdouble_tmalign( double *d, char *c, int n )
+{
+       double tmpd;
+       double *dbk;
+       int tmpi;
+       char s;
+       dbk = d;
+       while( *c )
+       {
+               if( ( s=*c++ ) == ':' )
+                       tmpi = 9;
+               else if( s == '.' )
+                       tmpi = 4;
+               else
+                       tmpi = 0;
+//             tmpd = (double)( tmpi + 1 - equivthreshold ) / ( 10 - equivthreshold ) * 9.0;
+//             if( tmpd < 0.0 ) tmpd = 0.0;
+               tmpd = (double)( tmpi );
+//             *d++ = (int)tmpd;
+               *d++ = tmpd;
+       }
+
+       d = dbk;
+//     maskequiv( d, n );
+}
+
+static void makeequivdouble_threshold( double *d, char *c, int n )
+{
+       double tmpd;
+       double *dbk;
+       int tmpi;
+       dbk = d;
+       while( *c )
+       {
+               tmpi = (int)( *c++ - '0' );
+               tmpd = (double)( tmpi + 1 - equivthreshold ) / ( 10 - equivthreshold ) * 9.0;
+               if( tmpd < 0.0 ) tmpd = 0.0;
+//             *d++ = (int)tmpd;
+               *d++ = tmpd;
+       }
+
+       d = dbk;
+       maskequiv( d, n );
+}
+
+static void readtmalign( FILE *fp, char *seq1, char *seq2, double *equiv )
+{
+       static char *line = NULL;
+       static char *equivchar = NULL;
+       int n;
+
+       
+       if( equivchar == NULL )
+       {
+               equivchar = calloc( nlenmax * 2 + 1, sizeof( char ) );
+               line = calloc( nlenmax * 2 + 1, sizeof( char ) );
+       }
+       seq1[0] = 0;
+       seq2[0] = 0;
+       equivchar[0] = 0;
+
+
+//     system( "vi _tmalignout" );
+       while( 1 )
+       {
+               if( feof( fp ) ) 
+               {
+                       fprintf( stderr, "Error in TMalign\n" );
+                       exit( 1 );
+               }
+               fgets( line, 999, fp );
+//             fprintf( stdout, "line = :%s:\n", line );
+               if( !strncmp( line+5, "denotes the residue pairs", 20 ) ) break;
+       }
+       fgets( line, nlenmax*2, fp );
+       strcat( seq1, strip( line ) );
+
+       fgets( line, nlenmax*2, fp );
+       strcat( equivchar, strip( line ) );
+
+       fgets( line, nlenmax*2, fp );
+       strcat( seq2, strip( line ) );
+
+#if 0
+       printf( "seq1=%s\n", seq1 );
+       printf( "seq2=%s\n", seq2 );
+       printf( "equi=%s\n", equivchar );
+exit( 1 );
+#endif
+       n = strlen( seq1 );
+       makeequivdouble_tmalign( equiv, equivchar, n );
+
+#if 0
+       fprintf( stdout, "\n" );
+       for( i=0; i<n; i++ )
+       {
+               fprintf( stdout, "%1.0f", equiv[i] );
+       }
+       fprintf( stdout, "\n" );
+       exit( 1 );
+#endif
+}
+static void readrash( FILE *fp, char *seq1, char *seq2, double *equiv )
+{
+       char line[1000];
+       static char *equivchar = NULL;
+       int n;
+
+       
+       if( equivchar == NULL )
+       {
+               equivchar = calloc( nlenmax * 2, sizeof( char ) );
+       }
+       seq1[0] = 0;
+       seq2[0] = 0;
+       equivchar[0] = 0;
+
+       while( 1 )
+       {
+               fgets( line, 999, fp );
+//             fprintf( stdout, "line = :%s:\n", line );
+               if( !strncmp( line, "Query ", 6 ) ) break;
+               if( feof( fp ) ) break;
+               if( !strncmp( line, "QUERY ", 6 ) )
+               {
+                       strcat( seq1, strip( line+5 ) );
+                       fgets( line, 999, fp );
+               }
+               if( !strncmp( line, "TEMPL ", 6 ) )
+               {
+                       strcat( seq2, strip( line+5 ) );
+                       fgets( line, 999, fp );
+               }
+               if( !strncmp( line, "Equiva", 6 ) )
+               {
+                       strcat( equivchar, strip( line+11 ) );
+                       fgets( line, 999, fp );
+               }
+       }
+#if 0
+       printf( "seq1=:%s:\n", seq1 );
+       printf( "seq2=:%s:\n", seq2 );
+       printf( "equi=:%s:\n", equivchar );
+exit( 1 );
+#endif
+       n = strlen( seq1 );
+       makeequivdouble_threshold( equiv, equivchar, n );
+
+#if 0
+       fprintf( stdout, "\n" );
+       for( i=0; i<n; i++ )
+       {
+               fprintf( stdout, "%1.0f", equiv[i] );
+       }
+       fprintf( stdout, "\n" );
+#endif
+}
+
+static int checkcbeta( FILE *fp )
+{
+       char linec[1000];
+       while( 1 )
+       {
+               fgets( linec, 999, fp );
+               if( feof( fp ) ) break;
+               if( !strncmp( "ATOM ", linec, 5 ) )
+               {
+                       if( !strncmp( "CB ", linec+13, 3 ) ) return( 0 );
+               }
+       }
+       return( 1 );
+}
+
+
+static float calltmalign( char **mseq1, char **mseq2, double *equiv, char *fname1, char *chain1, char *fname2, char *chain2, int alloclen )
+{
+       FILE *fp;
+       int res;
+       static char com[10000];
+       float value;
+       char cachedir[10000];
+       char cachefile[10000];
+       int runnow;
+
+
+       if( usecache )
+       {
+               sprintf( cachedir, "%s/.tmalignoutcache", getenv( "HOME" ) );
+               sprintf( com, "mkdir -p %s", cachedir );
+               system( com );
+
+               sprintf( cachefile, "%s/%s%s-%s%s", cachedir, fname1, chain1, fname2, chain2 );
+
+               runnow = 0;
+               fp = fopen( cachefile, "r" );
+               if( fp == NULL ) runnow = 1;
+               else
+               {
+                       fgets( com, 100, fp );
+                       if( strncmp( com, "successful", 10 ) ) runnow = 1;
+                       fclose( fp );
+               }
+       }
+       else
+       {
+               runnow = 1;
+       }
+
+       if( runnow )
+       {
+#if 0
+               sprintf( com, "ln -s %s %s.pdb 2>_dum", fname1, fname1 );
+               res = system( com );
+               sprintf( com, "ln -s %s %s.pdb 2>_dum", fname2, fname2 );
+               res = system( com );
+#endif
+               sprintf( com, "\"%s/TMalign\"  %s.pdb %s.pdb > _tmalignout 2>_dum", whereispairalign, fname1, fname2 );
+               fprintf( stderr, "command = %s\n", com );
+               res = system( com );
+               if( res )
+               {
+                       fprintf( stderr, "Error in TMalign\n" );
+                       exit( 1 );
+               }
+       
+       }
+       else
+       {
+               fprintf( stderr, "Cache is not supported!\n" );
+               exit( 1 );
+       }
+
+       fp = fopen( "_tmalignout", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _tmalignout\n" );
+               exit( 1 );
+       }
+
+       readtmalign( fp, *mseq1, *mseq2, equiv );
+
+       fclose( fp );
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+       return( value );
+}
+
+static float callrash( int mem1, int mem2, char **mseq1, char **mseq2, double *equiv, char *fname1, char *chain1, char *fname2, char *chain2, int alloclen )
+{
+       FILE *fp;
+       int res;
+       static char com[10000];
+       float value;
+       char cachedir[10000];
+       char cachefile[10000];
+       int runnow;
+       char pairid[1000];
+
+       sprintf( pairid, "%d-%d", mem1, mem2 );
+//     fprintf( stderr, "pairid = %s\n", pairid );
+
+       if( usecache )
+       {
+               sprintf( cachedir, "%s/.rashoutcache", getenv( "HOME" ) );
+               sprintf( com, "mkdir -p %s", cachedir );
+               system( com );
+
+               sprintf( cachefile, "%s/%s%s-%s%s", cachedir, fname1, chain1, fname2, chain2 );
+
+               runnow = 0;
+               fp = fopen( cachefile, "r" );
+               if( fp == NULL ) runnow = 1;
+               else
+               {
+                       fgets( com, 100, fp );
+                       if( strncmp( com, "successful", 10 ) ) runnow = 1;
+                       fclose( fp );
+               }
+       }
+       else
+       {
+               runnow = 1;
+       }
+
+       if( runnow )
+       {
+#if 0
+               sprintf( com, "ln -s %s %s.pdb 2>_dum", fname1, fname1 );
+               res = system( com );
+               sprintf( com, "ln -s %s %s.pdb 2>_dum", fname2, fname2 );
+               res = system( com );
+#endif
+#if 0  // 091127, pdp nai!
+               sprintf( com, "env PATH=%s PDP_ASH.pl --qf %s.pdb --qc %s --tf %s.pdb --tc %s > _rashout 2>_dum", whereispairalign, fname1, chain1, fname2, chain2 );
+#else
+               sprintf( com, "\"%s/rash\" --qf %s.pdb --qc %s --tf %s.pdb --tc %s --of %s.pdbpair > %s.rashout 2>%s.dum", whereispairalign, fname1, chain1, fname2, chain2, pairid, pairid, pairid );
+#endif
+               fprintf( stderr, "command = %s\n", com );
+               res = system( com );
+               if( res )
+               {
+                       fprintf( stderr, "Error in structural alignment\n" );
+                       exit( 1 );
+               }
+               sprintf( com, "awk '/^REMARK/,/^TER/' %s.pdbpair > %s.%s-x-%s.%s.pdbpair", pairid, fname1, chain1, fname2, chain2 );
+               res = system( com );
+
+               sprintf( com, "awk '/^REMARK/,/^TER/{next} 1' %s.pdbpair > %s.%s-x-%s.%s.pdbpair", pairid, fname2, chain2, fname1, chain1 );
+               res = system( com );
+
+               sprintf( com, "rm %s.pdbpair", pairid );
+               res = system( com );
+
+       
+       }
+       else
+       {
+               fprintf( stderr, "Use cache!\n" );
+               sprintf( com, "grep -v successful %s > %s.rashout", cachefile, pairid );
+               system( com );
+       }
+
+       if( usecache && runnow )
+       {
+               sprintf( com, "echo successful >  %s", cachefile );
+               system( com );
+               sprintf( com, "cat %s.rashout >>  %s", pairid, cachefile );
+               system( com );
+       }
+
+       sprintf( com, "%s.rashout", pairid );
+       fp = fopen( com, "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open %s\n", com );
+               exit( 1 );
+       }
+
+       readrash( fp, *mseq1, *mseq2, equiv );
+
+       fclose( fp );
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+       return( value );
+}
+
+static void preparetmalign( FILE *fp, char ***strfiles, char ***chainids, char ***seqpt, char ***mseq1pt, char ***mseq2pt, double **equivpt, int *alloclenpt )
+{
+       int i, res;
+       char *dumseq;
+       char line[1000];
+       char fname[1000];
+       char command[1000];
+       int linenum, istr, nstr;
+       FILE *checkfp;
+       char *sline; 
+       int use[1000];
+       linenum = 0;
+       nstr = 0;
+       while( 1 )
+       {
+               fgets( line, 999, fp );
+               if( feof( fp ) ) break;
+               sline = strip( line );
+               use[linenum] = 1;
+               if( sline[0] == '#' || strlen( sline ) < 2 )
+               {
+                       use[linenum] = 0;
+                       linenum++;
+                       continue;
+               }
+               extractfirstword( sline );
+               checkfp = fopen( sline, "r" );
+               if( checkfp == NULL )
+               {
+                       fprintf( stderr, "Cannot open %s.\n", sline );
+                       exit( 1 );
+               }
+#if 0
+               fgets( linec, 999, checkfp );
+               if( strncmp( "HEADER ", linec, 7 ) )
+               {
+                       fprintf( stderr, "Check the format of %s.\n", sline );
+                       exit( 1 );
+               }
+#endif
+               if( checkcbeta( checkfp ) ) 
+               {
+                       fprintf( stderr, "%s has no C-beta atoms.\n", sline );
+                       exit( 1 );
+               }
+               else
+                       nstr++;
+               fclose( checkfp );
+               linenum++;
+       }
+       njob = nstr;
+       fprintf( stderr, "nstr = %d\n", nstr );
+
+       *strfiles = AllocateCharMtx( nstr, 1000 );
+       *chainids = AllocateCharMtx( nstr, 2 );
+
+       rewind( fp );
+       istr = 0;
+       linenum = 0;
+       while( 1 )
+       {
+               fgets( line, 999, fp );
+               if( feof( fp ) ) break;
+               sline = strip( line );
+               if( use[linenum++] ) 
+               {
+                       (*chainids)[istr][0] = getchainid( sline );
+                       (*chainids)[istr][1] = 0;
+                       extractfirstword( sline );
+                       sprintf( fname, "%s", sline );
+                       cutpath( fname );
+                       sprintf( command, "cp %s %s.pdb", sline, fname );
+                       system( command );
+                       sprintf( command, "perl \"%s/clean.pl\" %s.pdb", whereispairalign, fname );
+                       res = system( command );
+                       if( res )
+                       {
+                               fprintf( stderr, "error: Install clean.pl\n" );
+                               exit( 1 );
+                       }
+                       strcpy( (*strfiles)[istr++], fname );
+               }
+       }
+
+       *seqpt = AllocateCharMtx( njob, nlenmax*2+1 );
+       *mseq1pt = AllocateCharMtx( njob, 0 );
+       *mseq2pt = AllocateCharMtx( njob, 0 );
+       *equivpt = AllocateDoubleVec( nlenmax*2+1 );
+       *alloclenpt = nlenmax*2;
+       dumseq = AllocateCharVec( nlenmax*2+1 );
+       alreadyoutput = AllocateIntVec( njob );
+       for( i=0; i<njob; i++ ) alreadyoutput[i] = 0;
+
+       for( i=0; i<istr; i++ )
+       {
+               fprintf( stderr, "i=%d\n", i );
+               (*seqpt)[i][0] = 0;
+
+               (*mseq1pt)[0] = (*seqpt)[i];
+               (*mseq2pt)[0] = dumseq;
+
+               calltmalign( *mseq1pt, *mseq2pt, *equivpt, (*strfiles)[i], (*chainids)[i], (*strfiles)[i], (*chainids)[i], *alloclenpt );
+               fprintf( stdout, ">%d_%s-%s\n%s\n", i+1, (*strfiles)[i], (*chainids)[i], (*seqpt)[i] );
+               alreadyoutput[i] = 1;
+       }
+}
+
+static void prepareash( FILE *fp, char ***strfiles, char ***chainids, char ***seqpt, char ***mseq1pt, char ***mseq2pt, double **equivpt, int *alloclenpt )
+{
+       int i, res;
+       char *dumseq;
+       char line[1000];
+       char fname[1000];
+       char command[1000];
+       int linenum, istr, nstr;
+       FILE *checkfp;
+       char *sline; 
+       int use[1000];
+       linenum = 0;
+       nstr = 0;
+       while( 1 )
+       {
+               fgets( line, 999, fp );
+               if( feof( fp ) ) break;
+               sline = strip( line );
+               use[linenum] = 1;
+               if( sline[0] == '#' || strlen( sline ) < 2 )
+               {
+                       use[linenum] = 0;
+                       linenum++;
+                       continue;
+               }
+               extractfirstword( sline );
+               checkfp = fopen( sline, "r" );
+               if( checkfp == NULL )
+               {
+                       fprintf( stderr, "Cannot open %s.\n", sline );
+                       exit( 1 );
+               }
+#if 0
+               fgets( linec, 999, checkfp );
+               if( strncmp( "HEADER ", linec, 7 ) )
+               {
+                       fprintf( stderr, "Check the format of %s.\n", sline );
+                       exit( 1 );
+               }
+#endif
+               if( checkcbeta( checkfp ) ) 
+               {
+                       fprintf( stderr, "%s has no C-beta atoms.\n", sline );
+                       exit( 1 );
+               }
+               else
+                       nstr++;
+               fclose( checkfp );
+               linenum++;
+       }
+       njob = nstr;
+       fprintf( stderr, "nstr = %d\n", nstr );
+
+       *strfiles = AllocateCharMtx( nstr, 1000 );
+       *chainids = AllocateCharMtx( nstr, 2 );
+
+       rewind( fp );
+       istr = 0;
+       linenum = 0;
+       while( 1 )
+       {
+               fgets( line, 999, fp );
+               if( feof( fp ) ) break;
+               sline = strip( line );
+               if( use[linenum++] ) 
+               {
+                       (*chainids)[istr][0] = getchainid( sline );
+                       (*chainids)[istr][1] = 0;
+                       extractfirstword( sline );
+                       sprintf( fname, "%s", sline );
+                       cutpath( fname );
+                       sprintf( command, "cp %s %s.pdb", sline, fname );
+                       system( command );
+                       sprintf( command, "perl \"%s/clean.pl\" %s.pdb", whereispairalign, fname );
+                       res = system( command );
+                       if( res )
+                       {
+                               fprintf( stderr, "error: Install clean.pl\n" );
+                               exit( 1 );
+                       }
+                       strcpy( (*strfiles)[istr++], fname );
+               }
+       }
+
+       *seqpt = AllocateCharMtx( njob, nlenmax*2+1 );
+       *mseq1pt = AllocateCharMtx( njob, 0 );
+       *mseq2pt = AllocateCharMtx( njob, 0 );
+       *equivpt = AllocateDoubleVec( nlenmax*2+1 );
+       *alloclenpt = nlenmax*2;
+       dumseq = AllocateCharVec( nlenmax*2+1 );
+       alreadyoutput = AllocateIntVec( njob );
+       for( i=0; i<njob; i++ ) alreadyoutput[i] = 0;
+
+       for( i=0; i<istr; i++ )
+       {
+               fprintf( stderr, "i=%d\n", i );
+               (*seqpt)[i][0] = 0;
+
+               (*mseq1pt)[0] = (*seqpt)[i];
+               (*mseq2pt)[0] = dumseq;
+
+               callrash( i, i, *mseq1pt, *mseq2pt, *equivpt, (*strfiles)[i], (*chainids)[i], (*strfiles)[i], (*chainids)[i], *alloclenpt );
+               fprintf( stdout, ">%d_%s-%s\n%s\n", i+1, (*strfiles)[i], (*chainids)[i], (*seqpt)[i] );
+               alreadyoutput[i] = 1;
+       }
+}
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       usecache = 0;
+       scale = 1.0;
+       equivthreshold = 5;
+       equivwinsize = 5;
+       equivshortestlen = 1;
+       inputfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'R';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'O':
+                                       ppenalty_OP = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'E':
+                                       ppenalty_EX = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+//                                     fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+//                                     fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "TM %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'd':
+                                       whereispairalign = *++argv;
+                                       fprintf( stderr, "whereispairalign = %s\n", whereispairalign );
+                                       --argc; 
+                                       goto nextoption;
+                               case 't':
+                                       equivthreshold = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'w':
+                                       equivwinsize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       equivshortestlen = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 's':
+                                       scale = atof( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'c':
+                                       usecache = 1;
+                                       break;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+#if 0
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#endif
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 'x':
+                                       disp = 1;
+                                       break;
+#if 0
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 'L':
+                                       alg = 'L';
+                                       break;
+                               case 'B':
+                                       alg = 'B';
+                                       break;
+                               case 'T':
+                                       alg = 'T';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'N':
+                                       alg = 'N';
+                                       break;
+                               case 'K':
+                                       alg = 'K';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'V':
+                                       alg = 'V';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'y':
+                                       divpairscore = 1;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+#if 0
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+#endif
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+static void pairalign( char name[M][B], int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *equiv, double *effarr, char **strfiles, char **chainids, int alloclen )
+{
+       int i, j, ilim;
+       int clus1, clus2;
+       int off1, off2;
+       float pscore = 0.0; // by D.Mathog
+       static char *indication1, *indication2;
+       FILE *hat2p, *hat3p;
+       static double **distancemtx;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       char *pt;
+       char *hat2file = "hat2";
+       LocalHom **localhomtable, *tmpptr;
+       static char **pair;
+//     int intdum;
+       double bunbo;
+       char **checkseq;
+
+
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++)
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1; 
+                       localhomtable[i][j].end2 = -1; 
+                       localhomtable[i][j].opt = -1.0;
+                       localhomtable[i][j].next = NULL;
+                       localhomtable[i][j].nokori = 0;
+               }
+       }
+
+       if( effarr1 == NULL ) 
+       {
+               distancemtx = AllocateDoubleMtx( njob, njob );
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+               checkseq = AllocateCharMtx( njob, alloclen );
+#if 0
+#else
+               pair = AllocateCharMtx( njob, njob );
+#endif
+       }
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
+       for( i=0; i<njob; i++ ) pair[i][i] = 1;
+
+       for( i=0; i<njob; i++ )
+       {
+               strcpy( checkseq[i], seq[i] );
+//             fprintf( stderr, "checkseq[%d] = %s\n", i, checkseq[i] );
+       }
+
+
+       ilim = njob - 1;
+       for( i=0; i<ilim; i++ ) 
+       {
+               fprintf( stderr, "% 5d / %d\r", i, njob );
+
+
+               for( j=i+1; j<njob; j++ )
+               {
+
+
+#if 0
+                       if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
+                       {
+                               distancemtx[i][j] = pscore;
+                               continue;
+                       }
+#endif
+
+                       strcpy( aseq[i], seq[i] );
+                       strcpy( aseq[j], seq[j] );
+                       clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
+                       clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
+       //              fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
+       //              fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
+       
+#if 0
+                       fprintf( stderr, "group1 = %.66s", indication1 );
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "group2 = %.66s", indication2 );
+                       fprintf( stderr, "\n" );
+#endif
+//                     for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
+       
+#if 1
+                       {
+                               switch( alg )
+                               {
+                                       case( 'T' ):
+                                               fprintf( stderr, "  Calling tmalign %d-%d/%d    \r", i+1, j+1, njob );
+                                               pscore = calltmalign( mseq1, mseq2, equiv, strfiles[i], chainids[i], strfiles[j], chainids[j], alloclen );
+                                               off1 = off2 = 0;
+                                               break;
+                                       case( 'R' ):
+                                               fprintf( stderr, "  Calling PDP_ASH.pl %d-%d/%d    \r", i+1, j+1, njob );
+                                               pscore = callrash( i, j, mseq1, mseq2, equiv, strfiles[i], chainids[i], strfiles[j], chainids[j], alloclen );
+                                               off1 = off2 = 0;
+                                               break;
+                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                               }
+                       }
+#endif
+                       distancemtx[i][j] = pscore;
+#if SCOREOUT
+                       fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
+#endif
+
+                       putlocalhom_str( mseq1[0], mseq2[0], equiv, scale, localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+#if 1
+
+                       if( alreadyoutput[i] == 0 )
+                       {
+                               alreadyoutput[i] = 1;
+                               gappick0( seq[i], mseq1[0] );
+                               fprintf( stdout, ">%d_%s-%s\n%s\n", i+1, strfiles[i], chainids[i], seq[i] );
+                               strcpy( checkseq[i], seq[i] );
+                       }
+                       else
+                       {
+                               gappick0( seq[i], mseq1[0] );
+                               fprintf( stderr, "checking seq%d\n", i );
+
+//                             fprintf( stderr, "     seq=%s\n", seq[i] );
+//                             fprintf( stderr, "checkseq=%s\n", checkseq[i] );
+
+                               if( strcmp( checkseq[i], seq[i] ) )
+                               {
+                                       fprintf( stderr, "\n\nWARNING: Sequence changed!!\n" );
+                                       fprintf( stderr, "i=%d\n", i );
+                                       fprintf( stderr, "     seq=%s\n", seq[i] );
+                                       fprintf( stderr, "checkseq=%s\n", checkseq[i] );
+                                       exit( 1 );
+                               }
+                       }
+                       if( alreadyoutput[j] == 0 )
+                       {
+                               alreadyoutput[j] = 1;
+                               gappick0( seq[j], mseq2[0] );
+                               fprintf( stdout, ">%d_%s-%s\n%s\n", j+1, strfiles[j], chainids[j], seq[j] );
+                               strcpy( checkseq[j], seq[j] );
+                       }
+                       else
+                       {
+                               gappick0( seq[j], mseq2[0] );
+                               fprintf( stderr, "checking seq%d\n", j );
+                               if( strcmp( checkseq[j], seq[j] ) )
+                               {
+                                       fprintf( stderr, "\n\nWARNING: Sequence changed!!\n" );
+                                       fprintf( stderr, "j=%d\n", j );
+                                       fprintf( stderr, "     seq=%s\n", seq[j] );
+                                       fprintf( stderr, "checkseq=%s\n", checkseq[j] );
+                                       exit( 1 );
+                               }
+                       }
+#endif
+               }
+       }
+       for( i=0; i<njob; i++ )
+       {
+               pscore = 0.0;
+               for( pt=seq[i]; *pt; pt++ )
+                       pscore += amino_dis[(int)*pt][(int)*pt];
+               distancemtx[i][i] = pscore;
+
+       }
+
+       ilim = njob-1;  
+       for( i=0; i<ilim; i++ )
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       bunbo = MIN( distancemtx[i][i], distancemtx[j][j] );
+                       if( bunbo == 0.0 )
+                               distancemtx[i][j] = 2.0;
+                       else
+                               distancemtx[i][j] = ( 1.0 - distancemtx[i][j] / bunbo ) * 2.0;
+               }
+       }
+
+       hat2p = fopen( hat2file, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( hat2p, njob, name, distancemtx );
+       fclose( hat2p );
+
+       fprintf( stderr, "##### writing hat3\n" );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       ilim = njob-1;  
+       for( i=0; i<ilim; i++ ) 
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d k\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2 ); 
+                       }
+               }
+       }
+       fclose( hat3p );
+#if DEBUG
+       fprintf( stderr, "calling FreeLocalHomTable\n" );
+#endif
+       FreeLocalHomTable( localhomtable, njob );
+#if DEBUG
+       fprintf( stderr, "done. FreeLocalHomTable\n" );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char name[M][B], **seq;
+       static char **mseq1, **mseq2;
+       static char **aseq;
+       static char **bseq;
+       static double *eff;
+       static double *equiv;
+       char **strfiles;
+       char **chainids;
+       int i;
+       FILE *infp;
+       char c;
+       int alloclen;
+
+       arguments( argc, argv );
+
+       if( equivthreshold < 1 || 9 < equivthreshold )
+       {
+               fprintf( stderr, "-t n, n must be 1..9\n" );
+               exit( 1 );
+       }
+
+       if( ( equivwinsize + 1 ) % 2 != 0 )
+       {
+               fprintf( stderr, "equivwinsize = %d\n", equivwinsize );
+               fprintf( stderr, "It must be an odd number.\n" );
+               exit( 1 );
+       }
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       nlenmax = 10000; // tekitou
+
+       if( alg == 'R' )
+               prepareash( infp, &strfiles, &chainids, &seq, &mseq1, &mseq2, &equiv, &alloclen );
+       else if( alg == 'T' )
+               preparetmalign( infp, &strfiles, &chainids, &seq, &mseq1, &mseq2, &equiv, &alloclen );
+
+       fclose( infp );
+
+       aseq = AllocateCharMtx( njob, nlenmax*2+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*2+1 );
+       eff = AllocateDoubleVec( njob );
+
+       for( i=0; i<njob; i++ )
+       {
+               fprintf( stderr, "str%d = %s-%s\n", i, strfiles[i], chainids[i] );
+       }
+
+       if( njob < 1 )
+       {
+               fprintf( stderr, "No structure found.\n" ); 
+               exit( 1 );
+       }
+       if( njob < 2 )
+       {
+               fprintf( stderr, "Only %d structure found.\n", njob ); 
+               exit( 0 );
+       }
+       if( njob > M )
+       {
+               fprintf( stderr, "The number of structures must be < %d\n", M );
+               fprintf( stderr, "Please try sequence-based methods for such large data.\n" );
+               exit( 1 );
+       }
+
+
+
+#if 0
+       readData( infp, name, nlen, seq );
+#endif
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+       pairalign( name, nlen, bseq, aseq, mseq1, mseq2, equiv, eff, strfiles, chainids, alloclen );
+
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+//     writePre( njob, name, nlen, aseq, !contin );
+#if 0
+       writeData( stdout, njob, name, nlen, aseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/pairlara.c b/binaries/src/mafft/core/pairlara.c
new file mode 100644 (file)
index 0000000..2f474ec
--- /dev/null
@@ -0,0 +1,942 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+static char *whereispairalign;
+static char *laraparams;
+static char foldalignopt[1000];
+
+static void t2u( char *seq )
+{
+       while( *seq )
+       {
+               if     ( *seq == 'A' ) *seq = 'a';
+               else if( *seq == 'a' ) *seq = 'a';
+               else if( *seq == 'T' ) *seq = 'u';
+               else if( *seq == 't' ) *seq = 'u';
+               else if( *seq == 'U' ) *seq = 'u';
+               else if( *seq == 'u' ) *seq = 'u';
+               else if( *seq == 'G' ) *seq = 'g';
+               else if( *seq == 'g' ) *seq = 'g';
+               else if( *seq == 'C' ) *seq = 'c';
+               else if( *seq == 'c' ) *seq = 'c';
+               else *seq = 'n';
+               seq++;
+       }
+}
+
+static float recallpairfoldalign( char **mseq1, char **mseq2, int m1, int m2, int *of1pt, int *of2pt, int alloclen )
+{
+       static FILE *fp = NULL;
+       float value;
+       char *aln1;
+       char *aln2;
+       int of1tmp, of2tmp;
+
+       if( fp == NULL )
+       {
+               fp = fopen( "_foldalignout", "r" );
+               if( fp == NULL )
+               {
+                       fprintf( stderr, "Cannot open _foldalignout\n" );
+                       exit( 1 );
+               }
+       }
+
+       aln1 = calloc( alloclen, sizeof( char ) );
+       aln2 = calloc( alloclen, sizeof( char ) );
+
+       readpairfoldalign( fp, *mseq1, *mseq2, aln1, aln2, m1, m2, &of1tmp, &of2tmp, alloclen );
+
+       if( strstr( foldalignopt, "-global") )
+       {
+               fprintf( stderr, "Calling G__align11\n" );
+               value = G__align11( mseq1, mseq2, alloclen );
+               *of1pt = 0;
+               *of2pt = 0;
+       }
+       else
+       {
+               fprintf( stderr, "Calling L__align11\n" );
+               value = L__align11( mseq1, mseq2, alloclen, of1pt, of2pt );
+       }
+
+//     value = (float)naivepairscore11( *mseq1, *mseq2, penalty ); // nennnotame
+
+       if( aln1[0] == 0 )
+       {
+               fprintf( stderr, "FOLDALIGN returned no alignment between %d and %d.  Sequence alignment is used instead.\n", m1+1, m2+1 );
+       }
+       else
+       {
+               strcpy( *mseq1, aln1 );
+               strcpy( *mseq2, aln2 );
+               *of1pt = of1tmp;
+               *of2pt = of2tmp;
+       }
+
+//     value = naivepairscore11( *mseq1, *mseq2, penalty ); // v6.511 ha kore wo tsukau, global nomi dakara.
+
+//     fclose( fp ); // saigo dake yatta houga yoi.
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+
+       free( aln1 );
+       free( aln2 );
+
+       return( value );
+}
+
+static void callfoldalign( int nseq, char **mseq )
+{
+       FILE *fp;
+       int i;
+       int res;
+       static char com[10000];
+
+       for( i=0; i<nseq; i++ )
+               t2u( mseq[i] );
+
+       fp = fopen( "_foldalignin", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _foldalignin\n" );
+               exit( 1 );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               fprintf( fp, ">%d\n", i+1 );
+               fprintf( fp, "%s\n", mseq[i] );
+       }
+       fclose( fp );
+
+       sprintf( com, "env PATH=%s  foldalign210 %s _foldalignin > _foldalignout ", whereispairalign, foldalignopt );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in foldalign\n" );
+               exit( 1 );
+       }
+
+}
+
+static void calllara( int nseq, char **mseq, char *laraarg )
+{
+       FILE *fp;
+       int i;
+       int res;
+       static char com[10000];
+
+       for( i=0; i<nseq; i++ )
+
+       fp = fopen( "_larain", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _larain\n" );
+               exit( 1 );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               fprintf( fp, ">%d\n", i+1 );
+               fprintf( fp, "%s\n", mseq[i] );
+       }
+       fclose( fp );
+
+
+//     fprintf( stderr, "calling LaRA\n" );
+       sprintf( com, "env PATH=%s:/bin:/usr/bin mafft_lara -i _larain -w _laraout -o _lara.params %s", whereispairalign, laraarg );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in lara\n" );
+               exit( 1 );
+       }
+}
+
+static float recalllara( char **mseq1, char **mseq2, int alloclen )
+{
+       static FILE *fp = NULL;
+       static char *ungap1;
+       static char *ungap2;
+       static char *ori1;
+       static char *ori2;
+       int res;
+       static char com[10000];
+       float value;
+
+
+       if( fp == NULL )
+       {
+               fp = fopen( "_laraout", "r" );
+               if( fp == NULL )
+               {
+                       fprintf( stderr, "Cannot open _laraout\n" );
+                       exit( 1 );
+               }
+               ungap1 = AllocateCharVec( alloclen );
+               ungap2 = AllocateCharVec( alloclen );
+               ori1 = AllocateCharVec( alloclen );
+               ori2 = AllocateCharVec( alloclen );
+       }
+
+
+       strcpy( ori1, *mseq1 );
+       strcpy( ori2, *mseq2 );
+
+       fgets( com, 999, fp );
+       myfgets( com, 9999, fp );
+       strcpy( *mseq1, com );
+       myfgets( com, 9999, fp );
+       strcpy( *mseq2, com );
+
+       gappick0( ungap1, *mseq1 );
+       gappick0( ungap2, *mseq2 );
+       t2u( ungap1 );
+       t2u( ungap2 );
+
+       if( strcmp( ungap1, ori1 ) || strcmp( ungap2, ori2 ) )
+       {
+               fprintf( stderr, "SEQUENCE CHANGED!!\n" );
+               fprintf( stderr, "*mseq1  = %s\n", *mseq1 );
+               fprintf( stderr, "ungap1  = %s\n", ungap1 );
+               fprintf( stderr, "ori1    = %s\n", ori1 );
+               fprintf( stderr, "*mseq2  = %s\n", *mseq2 );
+               fprintf( stderr, "ungap2  = %s\n", ungap2 );
+               fprintf( stderr, "ori2    = %s\n", ori2 );
+               exit( 1 );
+       }
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+//     fclose( fp ); // saigo dake yatta houga yoi.
+
+       return( value );
+}
+
+static float callmxscarna( char **mseq1, char **mseq2, int alloclen )
+{
+       FILE *fp;
+       int res;
+       static char com[10000];
+       float value;
+
+
+       t2u( *mseq1 );
+       t2u( *mseq2 );
+       fp = fopen( "_mxscarnain", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _mxscarnain\n" );
+               exit( 1 );
+       }
+       fprintf( fp, ">1\n" );
+       fprintf( fp, "%s\n", *mseq1 );
+       fprintf( fp, ">2\n" );
+       fprintf( fp, "%s\n", *mseq2 );
+       fclose( fp );
+
+       sprintf( com, "env PATH=%s mxscarna _mxscarnain > _mxscarnaout 2>/dev/null", whereispairalign );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in mxscarna\n" );
+               exit( 1 );
+       }
+
+       fp = fopen( "_mxscarnaout", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _mxscarnaout\n" );
+               exit( 1 );
+       }
+
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq1 );
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq2 );
+
+       fclose( fp );
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+       return( value );
+}
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       foldalignopt[0] = 0;
+       laraparams = NULL;
+       inputfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'O':
+                                       ppenalty_OP = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'E':
+                                       ppenalty_EX = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+//                                     fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+//                                     fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "TM %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       ppslocal = (int)( atof( *++argv ) * 1000 + 0.5 );
+                                       pslocal = (int)( 600.0 / 1000.0 * ppslocal + 0.5);
+//                                     fprintf( stderr, "ppslocal = %d\n", ppslocal );
+//                                     fprintf( stderr, "pslocal = %d\n", pslocal );
+                                       --argc;
+                                       goto nextoption;
+                               case 'd':
+                                       whereispairalign = *++argv;
+                                       fprintf( stderr, "whereispairalign = %s\n", whereispairalign );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'p':
+                                       laraparams = *++argv;
+                                       fprintf( stderr, "laraparams = %s\n", laraparams );
+                                       --argc; 
+                                       goto nextoption;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+#if 0
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#endif
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 'x':
+                                       disp = 1;
+                                       break;
+#if 0
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 'L':
+                                       alg = 'L';
+                                       break;
+                               case 's':
+                                       alg = 's';
+                                       break;
+                               case 'B':
+                                       alg = 'B';
+                                       break;
+                               case 'T':
+                                       alg = 'T';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'N':
+                                       alg = 'N';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'V':
+                                       alg = 'V';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'y':
+                                       divpairscore = 1;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'o':
+//                                     foldalignopt = *++argv;
+                                       strcat( foldalignopt, " " );
+                                       strcat( foldalignopt, *++argv );
+                                       fprintf( stderr, "foldalignopt = %s\n", foldalignopt );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+static void pairalign( char name[M][B], int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *effarr, int alloclen )
+{
+       int i, j, ilim;
+       int clus1, clus2;
+       int off1, off2;
+       float pscore = 0.0; // by D.Mathog
+       static char *indication1, *indication2;
+       FILE *hat2p, *hat3p;
+       static double **distancemtx;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       char *pt;
+       char *hat2file = "hat2";
+       LocalHom **localhomtable, *tmpptr;
+       static char **pair;
+       int intdum;
+       double bunbo;
+
+       localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       for( i=0; i<njob; i++)
+       {
+               localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+               for( j=0; j<njob; j++)
+               {
+                       localhomtable[i][j].start1 = -1;
+                       localhomtable[i][j].end1 = -1;
+                       localhomtable[i][j].start2 = -1; 
+                       localhomtable[i][j].end2 = -1; 
+                       localhomtable[i][j].opt = -1.0;
+                       localhomtable[i][j].next = NULL;
+                       localhomtable[i][j].nokori = 0;
+               }
+       }
+
+       if( effarr1 == NULL ) 
+       {
+               distancemtx = AllocateDoubleMtx( njob, njob );
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+#if 0
+#else
+               pair = AllocateCharMtx( njob, njob );
+#endif
+       }
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
+       for( i=0; i<njob; i++ ) pair[i][i] = 1;
+
+       if( alg == 'H' )
+       {
+               fprintf( stderr, "Calling FOLDALIGN with option '%s'\n", foldalignopt );
+               callfoldalign( njob, seq );
+               fprintf( stderr, "done.\n" );
+       }
+       if( alg == 'B' )
+       {
+               fprintf( stderr, "Calling LARA\n" );
+               calllara( njob, seq, "" );
+               fprintf( stderr, "done.\n" );
+       }
+       if( alg == 'T' )
+       {
+               fprintf( stderr, "Calling SLARA\n" );
+               calllara( njob, seq, "-s" );
+               fprintf( stderr, "done.\n" );
+       }
+
+       ilim = njob - 1;
+       for( i=0; i<ilim; i++ ) 
+       {
+               fprintf( stderr, "% 5d / %d\r", i, njob );
+               for( j=i+1; j<njob; j++ )
+               {
+
+                       if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
+                       {
+                               distancemtx[i][j] = pscore;
+                               continue;
+                       }
+
+                       strcpy( aseq[i], seq[i] );
+                       strcpy( aseq[j], seq[j] );
+                       clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
+                       clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
+       //              fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
+       //              fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
+       
+#if 0
+                       fprintf( stderr, "group1 = %.66s", indication1 );
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "group2 = %.66s", indication2 );
+                       fprintf( stderr, "\n" );
+#endif
+       //              for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
+       
+#if 1
+                       if( use_fft )
+                       {
+                               pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
+                               off1 = off2 = 0;
+                       }
+                       else
+#endif
+                       {
+                               switch( alg )
+                               {
+                                       case( 'a' ):
+                                               pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+                                               off1 = off2 = 0;
+                                               break;
+                                       case( 'A' ):
+                                               pscore = G__align11( mseq1, mseq2, alloclen, NULL, 0, NULL );
+                                               off1 = off2 = 0;
+                                               break;
+#if 0
+                                       case( 'V' ):
+                                               pscore = VAalign11( mseq1, mseq2, alloclen, &off1, &off2, localhomtable[i]+j );
+                                               fprintf( stderr, "i,j = %d,%d, score = %f\n", i,j, pscore );
+                                               break;
+                                       case( 'S' ):
+                                               fprintf( stderr, "aligning %d-%d\n", i, j );
+                                               pscore = suboptalign11( mseq1, mseq2, alloclen, &off1, &off2, localhomtable[i]+j );
+                                               fprintf( stderr, "i,j = %d,%d, score = %f\n", i,j, pscore );
+                                               break;
+#endif
+                                       case( 'N' ):
+                                               pscore = genL__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+//                                             fprintf( stderr, "pscore = %f\n", pscore );
+                                               break;
+                                       case( 'L' ):
+                                               pscore = L__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+//                                             fprintf( stderr, "pscore (1) = %f\n", pscore );
+//                                             pscore = (float)naivepairscore11( *mseq1, *mseq2, penalty ); // nennnotame
+//                                             fprintf( stderr, "pscore (2) = %f\n\n", pscore );
+                                               break;
+                                       case( 'H' ):
+                                               pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen );
+                                               break;
+                                       case( 'B' ):
+                                       case( 'T' ):
+                                               pscore = recalllara( mseq1, mseq2, alloclen );
+                                               off1 = off2 = 0;
+//                                             fprintf( stderr, "lara, pscore = %f\n", pscore );
+                                               break;
+                                       case( 's' ):
+                                               pscore = callmxscarna( mseq1, mseq2, alloclen );
+                                               off1 = off2 = 0;
+//                                             fprintf( stderr, "scarna, pscore = %f\n", pscore );
+                                               break;
+                                       case( 'M' ):
+//                                             pscore = MSalign11( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL );
+                                               pscore = MSalign11( mseq1, mseq2, alloclen );
+//                                             fprintf( stderr, "pscore = %f\n", pscore );
+                                               break;
+                                               ErrorExit( "ERROR IN SOURCE FILE" );
+                               }
+                       }
+                       distancemtx[i][j] = pscore;
+#if SCOREOUT
+                       fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
+#endif
+//                     fprintf( stderr, "pslocal = %d\n", pslocal );
+//                     offset = makelocal( *mseq1, *mseq2, pslocal );
+#if 0
+                       fprintf( stderr, "off1 = %d, off2 = %d\n", off1, off2 );
+                       fprintf( stderr, ">%d\n%s\n>%d\n%s\n>\n", i, mseq1[0], j, mseq2[0] );
+#endif
+
+//                     putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, countamino( *mseq1, off1 ), countamino( *mseq2, off2 ), pscore, strlen( mseq1[0] ) );
+//                     fprintf( stderr, "pscore = %f\n", pscore );
+                       if( alg == 'H' )
+//                     if( alg == 'H' || alg == 's' || alg == 'B' ) // next version
+                               putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+                       else if( alg != 'S' && alg != 'V' )
+                               putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+               }
+       }
+       for( i=0; i<njob; i++ )
+       {
+               pscore = 0.0;
+               for( pt=seq[i]; *pt; pt++ )
+                       pscore += amino_dis[(int)*pt][(int)*pt];
+               distancemtx[i][i] = pscore;
+
+       }
+
+       ilim = njob-1;  
+       for( i=0; i<ilim; i++ )
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       bunbo = MIN( distancemtx[i][i], distancemtx[j][j] );
+                       if( bunbo == 0.0 )
+                               distancemtx[i][j] = 2.0;
+                       else
+                               distancemtx[i][j] = ( 1.0 - distancemtx[i][j] / bunbo ) * 2.0;
+               }
+       }
+
+       hat2p = fopen( hat2file, "w" );
+       if( !hat2p ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( hat2p, njob, name, distancemtx );
+       fclose( hat2p );
+
+       fprintf( stderr, "##### writing hat3\n" );
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       ilim = njob-1;  
+       for( i=0; i<ilim; i++ ) 
+       {
+               for( j=i+1; j<njob; j++ )
+               {
+                       for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                       {
+                               if( tmpptr->opt == -1.0 ) continue;
+                               fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next ); 
+                       }
+               }
+       }
+       fclose( hat3p );
+#if DEBUG
+       fprintf( stderr, "calling FreeLocalHomTable\n" );
+#endif
+       FreeLocalHomTable( localhomtable, njob );
+#if DEBUG
+       fprintf( stderr, "done. FreeLocalHomTable\n" );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char name[M][B], **seq;
+       static char **mseq1, **mseq2;
+       static char **aseq;
+       static char **bseq;
+       static double *eff;
+       int i;
+       FILE *infp;
+       char c;
+       int alloclen;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+       if( njob > M )
+       {
+               fprintf( stderr, "The number of sequences must be < %d\n", M );
+               fprintf( stderr, "Please try the splittbfast program for such large data.\n" );
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       aseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       alloclen = nlenmax*9;
+
+       eff = AllocateDoubleVec( njob );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+       pairalign( name, nlen, bseq, aseq, mseq1, mseq2, eff, alloclen );
+
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+//     writePre( njob, name, nlen, aseq, !contin );
+#if 0
+       writeData( stdout, njob, name, nlen, aseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/pairlocalalign.c b/binaries/src/mafft/core/pairlocalalign.c
new file mode 100644 (file)
index 0000000..82fa7f3
--- /dev/null
@@ -0,0 +1,1516 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+#define NODIST -9999
+
+static char *whereispairalign;
+static char *laraparams;
+static char foldalignopt[1000];
+static int stdout_align;
+static int stdout_dist;
+static int store_localhom;
+static int store_dist;
+
+typedef struct _jobtable
+{
+       int i;
+       int j;
+} Jobtable;
+
+#ifdef enablemultithread
+typedef struct _thread_arg
+{
+       int thread_no;
+       int njob;
+       Jobtable *jobpospt;
+       char **name;
+       char **seq;
+       LocalHom **localhomtable;
+       double **distancemtx;
+       double *selfscore;
+       char ***bpp;
+       int alloclen;
+       pthread_mutex_t *mutex_counter;
+       pthread_mutex_t *mutex_stdout;
+} thread_arg_t;
+#endif
+
+static void t2u( char *seq )
+{
+       while( *seq )
+       {
+               if     ( *seq == 'A' ) *seq = 'a';
+               else if( *seq == 'a' ) *seq = 'a';
+               else if( *seq == 'T' ) *seq = 'u';
+               else if( *seq == 't' ) *seq = 'u';
+               else if( *seq == 'U' ) *seq = 'u';
+               else if( *seq == 'u' ) *seq = 'u';
+               else if( *seq == 'G' ) *seq = 'g';
+               else if( *seq == 'g' ) *seq = 'g';
+               else if( *seq == 'C' ) *seq = 'c';
+               else if( *seq == 'c' ) *seq = 'c';
+               else *seq = 'n';
+               seq++;
+       }
+}
+
+static float recallpairfoldalign( char **mseq1, char **mseq2, int m1, int m2, int *of1pt, int *of2pt, int alloclen )
+{
+       static FILE *fp = NULL;
+       float value;
+       char *aln1;
+       char *aln2;
+       int of1tmp, of2tmp;
+
+       if( fp == NULL )
+       {
+               fp = fopen( "_foldalignout", "r" );
+               if( fp == NULL )
+               {
+                       fprintf( stderr, "Cannot open _foldalignout\n" );
+                       exit( 1 );
+               }
+       }
+
+       aln1 = calloc( alloclen, sizeof( char ) );
+       aln2 = calloc( alloclen, sizeof( char ) );
+
+       readpairfoldalign( fp, *mseq1, *mseq2, aln1, aln2, m1, m2, &of1tmp, &of2tmp, alloclen );
+
+       if( strstr( foldalignopt, "-global") )
+       {
+               fprintf( stderr, "Calling G__align11\n" );
+               value = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
+               *of1pt = 0;
+               *of2pt = 0;
+       }
+       else
+       {
+               fprintf( stderr, "Calling L__align11\n" );
+               value = L__align11( mseq1, mseq2, alloclen, of1pt, of2pt );
+       }
+
+//     value = (float)naivepairscore11( *mseq1, *mseq2, penalty ); // nennnotame
+
+       if( aln1[0] == 0 )
+       {
+               fprintf( stderr, "FOLDALIGN returned no alignment between %d and %d.  Sequence alignment is used instead.\n", m1+1, m2+1 );
+       }
+       else
+       {
+               strcpy( *mseq1, aln1 );
+               strcpy( *mseq2, aln2 );
+               *of1pt = of1tmp;
+               *of2pt = of2tmp;
+       }
+
+//     value = naivepairscore11( *mseq1, *mseq2, penalty ); // v6.511 ha kore wo tsukau, global nomi dakara.
+
+//     fclose( fp ); // saigo dake yatta houga yoi.
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+
+       free( aln1 );
+       free( aln2 );
+
+       return( value );
+}
+
+static void callfoldalign( int nseq, char **mseq )
+{
+       FILE *fp;
+       int i;
+       int res;
+       static char com[10000];
+
+       for( i=0; i<nseq; i++ )
+               t2u( mseq[i] );
+
+       fp = fopen( "_foldalignin", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _foldalignin\n" );
+               exit( 1 );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               fprintf( fp, ">%d\n", i+1 );
+               fprintf( fp, "%s\n", mseq[i] );
+       }
+       fclose( fp );
+
+       sprintf( com, "env PATH=%s  foldalign210 %s _foldalignin > _foldalignout ", whereispairalign, foldalignopt );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in foldalign\n" );
+               exit( 1 );
+       }
+
+}
+
+static void calllara( int nseq, char **mseq, char *laraarg )
+{
+       FILE *fp;
+       int i;
+       int res;
+       static char com[10000];
+
+//     for( i=0; i<nseq; i++ )
+
+       fp = fopen( "_larain", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _larain\n" );
+               exit( 1 );
+       }
+       for( i=0; i<nseq; i++ )
+       {
+               fprintf( fp, ">%d\n", i+1 );
+               fprintf( fp, "%s\n", mseq[i] );
+       }
+       fclose( fp );
+
+
+//     fprintf( stderr, "calling LaRA\n" );
+       sprintf( com, "env PATH=%s:/bin:/usr/bin mafft_lara -i _larain -w _laraout -o _lara.params %s", whereispairalign, laraarg );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in lara\n" );
+               exit( 1 );
+       }
+}
+
+static float recalllara( char **mseq1, char **mseq2, int alloclen )
+{
+       static FILE *fp = NULL;
+       static char *ungap1;
+       static char *ungap2;
+       static char *ori1;
+       static char *ori2;
+//     int res;
+       static char com[10000];
+       float value;
+
+
+       if( fp == NULL )
+       {
+               fp = fopen( "_laraout", "r" );
+               if( fp == NULL )
+               {
+                       fprintf( stderr, "Cannot open _laraout\n" );
+                       exit( 1 );
+               }
+               ungap1 = AllocateCharVec( alloclen );
+               ungap2 = AllocateCharVec( alloclen );
+               ori1 = AllocateCharVec( alloclen );
+               ori2 = AllocateCharVec( alloclen );
+       }
+
+
+       strcpy( ori1, *mseq1 );
+       strcpy( ori2, *mseq2 );
+
+       fgets( com, 999, fp );
+       myfgets( com, 9999, fp );
+       strcpy( *mseq1, com );
+       myfgets( com, 9999, fp );
+       strcpy( *mseq2, com );
+
+       gappick0( ungap1, *mseq1 );
+       gappick0( ungap2, *mseq2 );
+       t2u( ungap1 );
+       t2u( ungap2 );
+       t2u( ori1 );
+       t2u( ori2 );
+
+       if( strcmp( ungap1, ori1 ) || strcmp( ungap2, ori2 ) )
+       {
+               fprintf( stderr, "SEQUENCE CHANGED!!\n" );
+               fprintf( stderr, "*mseq1  = %s\n", *mseq1 );
+               fprintf( stderr, "ungap1  = %s\n", ungap1 );
+               fprintf( stderr, "ori1    = %s\n", ori1 );
+               fprintf( stderr, "*mseq2  = %s\n", *mseq2 );
+               fprintf( stderr, "ungap2  = %s\n", ungap2 );
+               fprintf( stderr, "ori2    = %s\n", ori2 );
+               exit( 1 );
+       }
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+//     fclose( fp ); // saigo dake yatta houga yoi.
+
+       return( value );
+}
+
+
+static float callmxscarna_giving_bpp( char **mseq1, char **mseq2, char **bpp1, char **bpp2, int alloclen, int i, int j )
+{
+       FILE *fp;
+       int res;
+       char *com;
+       float value;
+       char *dirname;
+
+
+       dirname = calloc( 100, sizeof( char ) );
+       com = calloc( 1000, sizeof( char ) );
+       sprintf( dirname, "_%d-%d", i, j );
+       sprintf( com, "rm -rf %s", dirname );
+       system( com );
+       sprintf( com, "mkdir %s", dirname );
+       system( com );
+
+
+       sprintf( com, "%s/_bpporg", dirname );
+       fp = fopen( com, "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot write to %s/_bpporg\n", dirname );
+               exit( 1 );
+       }
+       fprintf( fp, ">a\n" );
+       while( *bpp1 )
+               fprintf( fp, "%s", *bpp1++ );
+
+       fprintf( fp, ">b\n" );
+       while( *bpp2 )
+               fprintf( fp, "%s", *bpp2++ );
+       fclose( fp );
+
+       sprintf( com, "tr -d '\\r' < %s/_bpporg > %s/_bpp", dirname, dirname );
+       system( com ); // for cygwin, wakaran
+
+       t2u( *mseq1 );
+       t2u( *mseq2 );
+
+       sprintf( com, "%s/_mxscarnainorg", dirname );
+       fp = fopen( com, "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open %s/_mxscarnainorg\n", dirname );
+               exit( 1 );
+       }
+       fprintf( fp, ">1\n" );
+//     fprintf( fp, "%s\n", *mseq1 );
+       write1seq( fp, *mseq1 );
+       fprintf( fp, ">2\n" );
+//     fprintf( fp, "%s\n", *mseq2 );
+       write1seq( fp, *mseq2 );
+       fclose( fp );
+
+       sprintf( com, "tr -d '\\r' < %s/_mxscarnainorg > %s/_mxscarnain", dirname, dirname );
+       system( com ); // for cygwin, wakaran
+
+#if 0
+       sprintf( com, "cd %s; %s/mxscarnamod -readbpp _mxscarnain > _mxscarnaout 2>_dum", dirname, whereispairalign );
+#else
+       sprintf( com, "_mxscarnash%s", dirname );
+       fp = fopen( com, "w" );
+       fprintf( fp, "cd %s\n", dirname );
+       fprintf( fp, "%s/mxscarnamod -readbpp _mxscarnain > _mxscarnaout 2>_dum\n", whereispairalign );
+       fprintf( fp, "exit $tatus\n" );
+       fclose( fp );
+
+       sprintf( com, "tr -d '\\r' < _mxscarnash%s > _mxscarnash%s.unix", dirname, dirname );
+       system( com ); // for cygwin, wakaran
+
+       sprintf( com, "sh _mxscarnash%s.unix 2>_dum%s", dirname, dirname );
+#endif
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in mxscarna\n" );
+               exit( 1 );
+       }
+
+       sprintf( com, "%s/_mxscarnaout", dirname );
+
+       fp = fopen( com, "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open %s/_mxscarnaout\n", dirname );
+               exit( 1 );
+       }
+
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq1 );
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq2 );
+
+       fclose( fp );
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+#if 0
+       sprintf( com, "rm -rf %s > /dev/null 2>&1", dirname );
+       if( system( com ) )
+       {
+               fprintf( stderr, "retrying to rmdir\n" );
+               usleep( 2000 );
+               system( com );
+       }
+#endif
+
+       free( dirname );
+       free( com );
+
+
+       return( value );
+}
+
+#if 0
+static float callmxscarna_slow( char **mseq1, char **mseq2, int alloclen )
+{
+       FILE *fp;
+       int res;
+       static char com[10000];
+       float value;
+
+
+       t2u( *mseq1 );
+       t2u( *mseq2 );
+       fp = fopen( "_mxscarnain", "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _mxscarnain\n" );
+               exit( 1 );
+       }
+       fprintf( fp, ">1\n" );
+       fprintf( fp, "%s\n", *mseq1 );
+       fprintf( fp, ">2\n" );
+       fprintf( fp, "%s\n", *mseq2 );
+       fclose( fp );
+
+       sprintf( com, "env PATH=%s mxscarnamod _mxscarnain > _mxscarnaout 2>_dum", whereispairalign );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "Error in mxscarna\n" );
+               exit( 1 );
+       }
+
+       fp = fopen( "_mxscarnaout", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open _mxscarnaout\n" );
+               exit( 1 );
+       }
+
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq1 );
+       fgets( com, 999, fp );
+       load1SeqWithoutName_new( fp, *mseq2 );
+
+       fclose( fp );
+
+//     fprintf( stderr, "*mseq1 = %s\n", *mseq1 );
+//     fprintf( stderr, "*mseq2 = %s\n", *mseq2 );
+
+       value = (float)naivepairscore11( *mseq1, *mseq2, penalty );
+
+       return( value );
+}
+#endif
+
+static void readhat4( FILE *fp, char ***bpp )
+{
+       char oneline[1000];
+       int bppsize;
+       int onechar;
+//     double prob;
+//     int posi, posj;
+
+       bppsize = 0;
+//     fprintf( stderr, "reading hat4\n" );
+       onechar = getc(fp);
+//     fprintf( stderr, "onechar = %c\n", onechar );
+       if( onechar != '>' )
+       {
+               fprintf( stderr, "Format error\n" );
+               exit( 1 );
+       }
+       ungetc( onechar, fp );
+       fgets( oneline, 999, fp );
+       while( 1 )
+       {
+               onechar = getc(fp);
+               ungetc( onechar, fp );
+               if( onechar == '>' || onechar == EOF )
+               {
+//                     fprintf( stderr, "Next\n" );
+                       *bpp = realloc( *bpp, (bppsize+2) * sizeof( char * ) );
+                       (*bpp)[bppsize] = NULL;
+                       break;
+               }
+               fgets( oneline, 999, fp );
+//             fprintf( stderr, "oneline=%s\n", oneline );
+//             sscanf( oneline, "%d %d %f", &posi, &posj, &prob );
+//             fprintf( stderr, "%d %d -> %f\n", posi, posj, prob );
+               *bpp = realloc( *bpp, (bppsize+2) * sizeof( char * ) );
+               (*bpp)[bppsize] = calloc( 100, sizeof( char ) );
+               strcpy( (*bpp)[bppsize], oneline );
+               bppsize++;
+       }
+}
+
+static void preparebpp( int nseq, char ***bpp )
+{
+       FILE *fp;
+       int i;
+
+       fp = fopen( "hat4", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open hat4\n" );
+               exit( 1 );
+       }
+       for( i=0; i<nseq; i++ )
+               readhat4( fp, bpp+i );
+       fclose( fp );
+}
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nthread = 1;
+       foldalignopt[0] = 0;
+       laraparams = NULL;
+       inputfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       stdout_align = 0;
+       stdout_dist = 0;
+       store_dist = 1;
+       store_localhom = 1;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'O':
+                                       ppenalty_OP = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'E':
+                                       ppenalty_EX = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+//                                     fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+//                                     fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "TM %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       ppslocal = (int)( atof( *++argv ) * 1000 + 0.5 );
+                                       pslocal = (int)( 600.0 / 1000.0 * ppslocal + 0.5);
+//                                     fprintf( stderr, "ppslocal = %d\n", ppslocal );
+//                                     fprintf( stderr, "pslocal = %d\n", pslocal );
+                                       --argc;
+                                       goto nextoption;
+                               case 'd':
+                                       whereispairalign = *++argv;
+                                       fprintf( stderr, "whereispairalign = %s\n", whereispairalign );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'p':
+                                       laraparams = *++argv;
+                                       fprintf( stderr, "laraparams = %s\n", laraparams );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'c':
+                                       stdout_dist = 1;
+                                       break;
+                               case 'n':
+                                       stdout_align = 1;
+                                       break;
+                               case 'x':
+                                       store_localhom = 0;
+                                       store_dist = 0;
+                                       break;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+#if 0
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#endif
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+#if 0
+                               case 'x':
+                                       disp = 1;
+                                       break;
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 't':
+                                       alg = 't';
+                                       store_localhom = 0;
+                                       break;
+                               case 'L':
+                                       alg = 'L';
+                                       break;
+                               case 's':
+                                       alg = 's';
+                                       break;
+                               case 'B':
+                                       alg = 'B';
+                                       break;
+                               case 'T':
+                                       alg = 'T';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'N':
+                                       alg = 'N';
+                                       break;
+                               case 'K':
+                                       alg = 'K';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'V':
+                                       alg = 'V';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'y':
+                                       divpairscore = 1;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'o':
+//                                     foldalignopt = *++argv;
+                                       strcat( foldalignopt, " " );
+                                       strcat( foldalignopt, *++argv );
+                                       fprintf( stderr, "foldalignopt = %s\n", foldalignopt );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+#if enablemultithread
+static void *athread( void *arg )
+{
+       thread_arg_t *targ = (thread_arg_t *)arg;
+       int i, j;
+       int clus1, clus2;
+       int off1, off2;
+       int intdum;
+       double bunbo;
+       float pscore = 0.0; // by D.Mathog
+       double *effarr;
+       double *effarr1;
+       double *effarr2;
+       char **pair;
+       char *indication1, *indication2;
+       char **mseq1, **mseq2;
+       char **aseq;
+
+// thread_arg
+       int thread_no = targ->thread_no;
+       int njob = targ->njob;
+       Jobtable *jobpospt = targ->jobpospt;
+       char **name = targ->name;
+       char **seq = targ->seq;
+       LocalHom **localhomtable = targ->localhomtable;
+       double **distancemtx = targ->distancemtx;
+       double *selfscore = targ->selfscore;
+       char ***bpp = targ->bpp;
+       int alloclen = targ->alloclen;
+
+//     fprintf( stderr, "thread %d start!\n", thread_no );
+
+       effarr = AllocateDoubleVec( njob );
+       for( i=0; i<njob; i++ ) effarr[i] = 1.0;
+       effarr1 = AllocateDoubleVec( njob );
+       effarr2 = AllocateDoubleVec( njob );
+       indication1 = AllocateCharVec( 150 );
+       indication2 = AllocateCharVec( 150 );
+       pair = AllocateCharMtx( njob, njob );
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
+       for( i=0; i<njob; i++ ) pair[i][i] = 1;
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       aseq = AllocateCharMtx( njob, alloclen+10 );
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex_counter );
+               j = jobpospt->j;
+               i = jobpospt->i;
+               j++;
+               if( j == njob )
+               {
+                       i++;
+                       j = i + 1;
+                       if( i == njob-1 )
+                       {
+//                             fprintf( stderr, "thread %d end!\n", thread_no );
+                               pthread_mutex_unlock( targ->mutex_counter );
+
+                               if( commonIP ) FreeIntMtx( commonIP );
+                               commonIP = NULL;
+                               if( commonJP ) FreeIntMtx( commonJP );
+                               commonJP = NULL;
+                               Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL );
+                               G__align11_noalign( NULL, 0, 0, NULL, NULL, 0 );
+                               L__align11( NULL, NULL, 0, NULL, NULL );
+                               genL__align11( NULL, NULL, 0, NULL, NULL );
+                               free( effarr );
+                               free( effarr1 );
+                               free( effarr2 );
+                               free( indication1 );
+                               free( indication2 );
+                               FreeCharMtx( pair  );
+                               free( mseq1 );
+                               free( mseq2 );
+                               FreeCharMtx( aseq  );
+                               return( NULL );
+                       }
+               }
+               jobpospt->j = j;
+               jobpospt->i = i;
+               pthread_mutex_unlock( targ->mutex_counter );
+
+
+               if( j == i+1 || j % 100 == 0 ) 
+               {
+                       fprintf( stderr, "% 5d / %d (by thread %3d) \r", i, njob, thread_no );
+//                     fprintf( stderr, "% 5d - %5d / %d (thread %d)\n", i, j, njob, thread_no );
+               }
+
+
+               if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
+               {
+                       if( store_dist ) distancemtx[i][j] = 2.0;
+                       if( stdout_dist) 
+                       {
+                               pthread_mutex_lock( targ->mutex_stdout );
+                               fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, 2.0 );
+                               pthread_mutex_unlock( targ->mutex_stdout );
+                       }
+                       continue;
+               }
+
+               strcpy( aseq[i], seq[i] );
+               strcpy( aseq[j], seq[j] );
+               clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
+               clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
+//             fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
+//             fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
+       
+#if 0
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               fprintf( stderr, "\n" );
+#endif
+//             for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
+
+               if( use_fft )
+               {
+                       pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
+//                     fprintf( stderr, "pscore (fft) = %f\n", pscore );
+                       off1 = off2 = 0;
+               }
+               else
+               {
+                       switch( alg )
+                       {
+                               case( 'L' ):
+                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                       L__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+                                       break;
+                               case( 'A' ):
+                                       pscore = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
+                                       off1 = off2 = 0;
+                                       break;
+                               case( 'N' ):
+                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                       genL__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+                                       break;
+                               case( 't' ):
+                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                       off1 = off2 = 0;
+                                       break;
+                               case( 's' ):
+                                       pscore = callmxscarna_giving_bpp( mseq1, mseq2, bpp[i], bpp[j], alloclen, i, j );
+                                       off1 = off2 = 0;
+                                       break;
+#if 0 
+                               case( 'a' ):
+                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+                                       off1 = off2 = 0;
+                                       break;
+                               case( 'K' ):
+                                       pscore = genG__align11( mseq1, mseq2, alloclen );
+                                       off1 = off2 = 0;
+                                       break;
+                               case( 'H' ):
+                                       pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen );
+                                       break;
+                               case( 'B' ):
+                               case( 'T' ):
+                                       pscore = recalllara( mseq1, mseq2, alloclen );
+                                       off1 = off2 = 0;
+                                       break;
+                               case( 'M' ):
+                                       pscore = MSalign11( mseq1, mseq2, alloclen );
+                                       break;
+#endif
+                               default:
+                                       ErrorExit( "\n\nERROR IN SOURCE FILE\n\n" );
+                       }
+               }
+
+               if( alg == 't' || ( mseq1[0][0] != 0 && mseq2[0][0] != 0  ) ) // 't' no jouken ha iranai to omou. if( ( mseq1[0][0] != 0 && mseq2[0][0] != 0  ) )
+               {
+#if SCOREOUT
+                       fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
+#endif
+                       if( !store_localhom )
+                               ;
+                       else if( alg == 'H' )
+                               putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+                       else if( alg != 'S' && alg != 'V' )
+                       {
+                               putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+                       }
+
+                       if( (bunbo=MIN( selfscore[i], selfscore[j] )) == 0.0 || bunbo < pscore )
+                               pscore = 2.0;
+                       else
+                               pscore = ( 1.0 - pscore / bunbo ) * 2.0;
+               }
+               else
+               {
+                       pscore = 2.0;
+               }
+
+#if 1 // mutex
+               if( stdout_align )
+               {
+                       pthread_mutex_lock( targ->mutex_stdout );
+                       if( alg != 't' )
+                       {
+                               fprintf( stdout, "sequence %d - sequence %d, pairwise distance = %10.5f\n", i+1, j+1, pscore );
+                               fprintf( stdout, ">%s\n", name[i] );
+                               write1seq( stdout, mseq1[0] );
+                               fprintf( stdout, ">%s\n", name[j] );
+                               write1seq( stdout, mseq2[0] );
+                               fprintf( stdout, "\n" );
+                       }
+                       pthread_mutex_unlock( targ->mutex_stdout );
+               }
+               if( stdout_dist )
+               {
+                       pthread_mutex_lock( targ->mutex_stdout );
+                       if( j == i+1 ) fprintf( stdout, "%d %d d=%.3f\n", i+1, i+1, 0.0 );
+                       fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, pscore );
+                       pthread_mutex_unlock( targ->mutex_stdout );
+               }
+#endif // mutex
+               if( store_dist) distancemtx[i][j] = pscore;
+       }
+}
+#endif
+
+static void pairalign( char **name, int nlen[M], char **seq, char **aseq, char **mseq1, char **mseq2, double *effarr, int alloclen )
+{
+       int i, j, ilim;
+       int clus1, clus2;
+       int off1, off2;
+       float pscore = 0.0; // by D.Mathog
+       static char *indication1, *indication2;
+       FILE *hat2p, *hat3p;
+       double **distancemtx;
+       double *selfscore;
+       double *effarr1;
+       double *effarr2;
+       char *pt;
+       char *hat2file = "hat2";
+       LocalHom **localhomtable = NULL, *tmpptr;
+       static char **pair;
+       int intdum;
+       double bunbo;
+       char ***bpp = NULL; // mxscarna no toki dake
+
+       if( store_localhom )
+       {
+               localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+               for( i=0; i<njob; i++)
+               {
+                       localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+                       for( j=0; j<njob; j++)
+                       {
+                               localhomtable[i][j].start1 = -1;
+                               localhomtable[i][j].end1 = -1;
+                               localhomtable[i][j].start2 = -1; 
+                               localhomtable[i][j].end2 = -1; 
+                               localhomtable[i][j].opt = -1.0;
+                               localhomtable[i][j].next = NULL;
+                               localhomtable[i][j].nokori = 0;
+                       }
+               }
+       }
+
+       if( store_dist ) distancemtx = AllocateDoubleMtx( njob, njob );
+       else distancemtx = NULL;
+       selfscore = AllocateDoubleVec( njob );
+       effarr1 = AllocateDoubleVec( njob );
+       effarr2 = AllocateDoubleVec( njob );
+       indication1 = AllocateCharVec( 150 );
+       indication2 = AllocateCharVec( 150 );
+#if 0
+#else
+       pair = AllocateCharMtx( njob, njob );
+#endif
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       for( i=0; i<njob; i++ ) for( j=0; j<njob; j++ ) pair[i][j] = 0;
+       for( i=0; i<njob; i++ ) pair[i][i] = 1;
+
+       if( alg == 'H' )
+       {
+               fprintf( stderr, "Calling FOLDALIGN with option '%s'\n", foldalignopt );
+               callfoldalign( njob, seq );
+               fprintf( stderr, "done.\n" );
+       }
+       if( alg == 'B' )
+       {
+               fprintf( stderr, "Running LARA (Bauer et al. http://www.planet-lisa.net/)\n" );
+               calllara( njob, seq, "" );
+               fprintf( stderr, "done.\n" );
+       }
+       if( alg == 'T' )
+       {
+               fprintf( stderr, "Running SLARA (Bauer et al. http://www.planet-lisa.net/)\n" );
+               calllara( njob, seq, "-s" );
+               fprintf( stderr, "done.\n" );
+       }
+       if( alg == 's' )
+       {
+               fprintf( stderr, "Preparing bpp\n" );
+//             bpp = AllocateCharCub( njob, nlenmax, 0 );
+               bpp = calloc( njob, sizeof( char ** ) );
+               preparebpp( njob, bpp );
+               fprintf( stderr, "done.\n" );
+               fprintf( stderr, "Running MXSCARNA (Tabei et al. http://www.ncrna.org/software/mxscarna)\n" );
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               pscore = 0.0;
+               for( pt=seq[i]; *pt; pt++ )
+                       pscore += amino_dis[(int)*pt][(int)*pt];
+               selfscore[i] = pscore;
+
+       }
+
+#if enablemultithread
+       if( nthread > 0 )
+       {
+               Jobtable jobpos;
+               pthread_t *handle;
+               pthread_mutex_t mutex_counter;
+               pthread_mutex_t mutex_stdout;
+               thread_arg_t *targ;
+
+               jobpos.i = 0;
+               jobpos.j = 0;
+
+               targ = calloc( nthread, sizeof( thread_arg_t ) );
+               handle = calloc( nthread, sizeof( pthread_t ) );
+               pthread_mutex_init( &mutex_counter, NULL );
+               pthread_mutex_init( &mutex_stdout, NULL );
+
+               for( i=0; i<nthread; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].njob = njob;
+                       targ[i].jobpospt = &jobpos;
+                       targ[i].name = name;
+                       targ[i].seq = seq;
+                       targ[i].localhomtable = localhomtable;
+                       targ[i].distancemtx = distancemtx;
+                       targ[i].selfscore = selfscore;
+                       targ[i].bpp = bpp; 
+                       targ[i].alloclen = alloclen;
+                       targ[i].mutex_counter = &mutex_counter;
+                       targ[i].mutex_stdout = &mutex_stdout;
+
+//                     athread( (void *)targ );
+                       pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
+//                     pthread_create( handle+i, NULL, bthread, (void *)(targ+i) );
+               }
+
+
+               for( i=0; i<nthread; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+               pthread_mutex_destroy( &mutex_counter );
+               pthread_mutex_destroy( &mutex_stdout );
+               free( handle );
+               free( targ );
+       }
+       else
+#endif
+       {
+               ilim = njob - 1;
+               for( i=0; i<ilim; i++ ) 
+               {
+                       if( stdout_dist) fprintf( stdout, "%d %d d=%.3f\n", i+1, i+1, 0.0 );
+                       fprintf( stderr, "% 5d / %d\r", i, njob );
+                       fflush( stderr );
+                       for( j=i+1; j<njob; j++ )
+                       {
+       
+                               if( strlen( seq[i] ) == 0 || strlen( seq[j] ) == 0 )
+                               {
+                                       if( store_dist ) distancemtx[i][j] = 2.0;
+                                       if( stdout_dist) fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, 2.0 );
+                                       continue;
+                               }
+       
+                               strcpy( aseq[i], seq[i] );
+                               strcpy( aseq[j], seq[j] );
+                               clus1 = conjuctionfortbfast( pair, i, aseq, mseq1, effarr1, effarr, indication1 );
+                               clus2 = conjuctionfortbfast( pair, j, aseq, mseq2, effarr2, effarr, indication2 );
+       //                      fprintf( stderr, "mseq1 = %s\n", mseq1[0] );
+       //                      fprintf( stderr, "mseq2 = %s\n", mseq2[0] );
+               
+#if 0
+                               fprintf( stderr, "group1 = %.66s", indication1 );
+                               fprintf( stderr, "\n" );
+                               fprintf( stderr, "group2 = %.66s", indication2 );
+                               fprintf( stderr, "\n" );
+#endif
+       //                      for( l=0; l<clus1; l++ ) fprintf( stderr, "## STEP-eff for mseq1-%d %f\n", l, effarr1[l] );
+       
+                               if( use_fft )
+                               {
+                                       pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
+//                                     fprintf( stderr, "pscore (fft) = %f\n", pscore );
+                                       off1 = off2 = 0;
+                               }
+                               else
+                               {
+                                       switch( alg )
+                                       {
+                                               case( 'a' ):
+                                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 't' ):
+                                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 'A' ):
+                                                       pscore = G__align11( mseq1, mseq2, alloclen, outgap, outgap );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 'N' ):
+                                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                                       genL__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+                                                       break;
+                                               case( 'K' ):
+                                                       pscore = genG__align11( mseq1, mseq2, alloclen );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 'L' ):
+                                                       pscore = G__align11_noalign( amino_dis, penalty, penalty_ex, mseq1, mseq2, alloclen );
+                                                       L__align11( mseq1, mseq2, alloclen, &off1, &off2 );
+                                                       break;
+                                               case( 'H' ):
+                                                       pscore = recallpairfoldalign( mseq1, mseq2, i, j, &off1, &off2, alloclen );
+                                                       break;
+                                               case( 'B' ):
+                                               case( 'T' ):
+                                                       pscore = recalllara( mseq1, mseq2, alloclen );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 's' ):
+                                                       pscore = callmxscarna_giving_bpp( mseq1, mseq2, bpp[i], bpp[j], alloclen, i, j );
+                                                       off1 = off2 = 0;
+                                                       break;
+                                               case( 'M' ):
+                                                       pscore = MSalign11( mseq1, mseq2, alloclen );
+                                                       break;
+                                               default:
+                                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                                       }
+                               }
+       
+                               if( alg == 't' || ( mseq1[0][0] != 0 && mseq2[0][0] != 0  ) ) // 't' no jouken ha iranai to omou. if( ( mseq1[0][0] != 0 && mseq2[0][0] != 0  ) )
+                               {
+#if SCOREOUT
+                                       fprintf( stderr, "score = %10.2f (%d,%d)\n", pscore, i, j );
+#endif
+                                       if( !store_localhom )
+                                               ;
+                                       else if( alg == 'H' )
+                                               putlocalhom_ext( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+                                       else if( alg != 'S' && alg != 'V' )
+                                               putlocalhom2( mseq1[0], mseq2[0], localhomtable[i]+j, off1, off2, (int)pscore, strlen( mseq1[0] ) );
+       
+       
+                                       if( (bunbo=MIN( selfscore[i], selfscore[j] )) == 0.0 || bunbo < pscore )
+                                               pscore = 2.0;
+                                       else
+                                               pscore = ( 1.0 - pscore / bunbo ) * 2.0;
+                               }
+                               else
+                               {
+                                       pscore = 2.0;
+                               }
+       
+                               if( stdout_align )
+                               {
+                                       if( alg != 't' )
+                                       {
+                                               fprintf( stdout, "sequence %d - sequence %d, pairwise distance = %10.5f\n", i+1, j+1, pscore );
+                                               fprintf( stdout, ">%s\n", name[i] );
+                                               write1seq( stdout, mseq1[0] );
+                                               fprintf( stdout, ">%s\n", name[j] );
+                                               write1seq( stdout, mseq2[0] );
+                                               fprintf( stdout, "\n" );
+                                       }
+                               }
+                               if( stdout_dist ) fprintf( stdout, "%d %d d=%.3f\n", i+1, j+1, pscore );
+                               if( store_dist) distancemtx[i][j] = pscore;
+                       }
+               }
+       }
+
+
+       if( store_dist )
+       {
+               hat2p = fopen( hat2file, "w" );
+               if( !hat2p ) ErrorExit( "Cannot open hat2." );
+               WriteHat2_pointer( hat2p, njob, name, distancemtx );
+               fclose( hat2p );
+       }
+
+       hat3p = fopen( "hat3", "w" );
+       if( !hat3p ) ErrorExit( "Cannot open hat3." );
+       if( store_localhom )
+       {
+               fprintf( stderr, "\n\n##### writing hat3\n" );
+               ilim = njob-1;  
+               for( i=0; i<ilim; i++ ) 
+               {
+                       for( j=i+1; j<njob; j++ )
+                       {
+                               for( tmpptr=localhomtable[i]+j; tmpptr; tmpptr=tmpptr->next )
+                               {
+                                       if( tmpptr->opt == -1.0 ) continue;
+// tmptmptmptmptmp
+//                                     if( alg == 'B' || alg == 'T' )
+//                                             fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d %p\n", i, j, tmpptr->overlapaa, 1.0, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2, (void *)tmpptr->next ); 
+//                                     else
+                                               fprintf( hat3p, "%d %d %d %7.5f %d %d %d %d h\n", i, j, tmpptr->overlapaa, tmpptr->opt, tmpptr->start1, tmpptr->end1, tmpptr->start2, tmpptr->end2 ); 
+                               }
+                       }
+               }
+#if DEBUG
+               fprintf( stderr, "calling FreeLocalHomTable\n" );
+#endif
+               FreeLocalHomTable( localhomtable, njob );
+#if DEBUG
+               fprintf( stderr, "done. FreeLocalHomTable\n" );
+#endif
+       }
+       fclose( hat3p );
+
+       if( alg == 's' )
+       {
+               char **ptpt;
+               for( i=0; i<njob; i++ )
+               {
+                       ptpt = bpp[i];
+                       while( 1 )
+                       {
+                               if( *ptpt ) free( *ptpt );
+                               else break;
+                               ptpt++;
+                       }
+                       free( bpp[i] );
+               }
+               free( bpp );
+       }
+       free( selfscore );
+       free( effarr1 );
+       free( effarr2 );
+       free( indication1 );
+       free( indication2 );
+       if( store_dist ) FreeDoubleMtx( distancemtx );
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       int  nlen[M];   
+       char **name, **seq;
+       char **mseq1, **mseq2;
+       char **aseq;
+       char **bseq;
+       double *eff;
+       int i;
+       FILE *infp;
+       char c;
+       int alloclen;
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+       if( njob > M )
+       {
+               fprintf( stderr, "The number of sequences must be < %d\n", M );
+               fprintf( stderr, "Please try the splittbfast program for such large data.\n" );
+               exit( 1 );
+       }
+
+       alloclen = nlenmax*2;
+       seq = AllocateCharMtx( njob, alloclen+10 );
+       aseq = AllocateCharMtx( njob, alloclen+10 );
+       bseq = AllocateCharMtx( njob, alloclen+10 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       name = AllocateCharMtx( njob, B );
+
+       eff = AllocateDoubleVec( njob );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData_pointer( infp, name, nlen, seq );
+#endif
+       fclose( infp );
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+
+       for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+       pairalign( name, nlen, bseq, aseq, mseq1, mseq2, eff, alloclen );
+
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+//     writePre( njob, name, nlen, aseq, !contin );
+#if 0
+       writeData( stdout, njob, name, nlen, aseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+
+       if( stdout_dist && nthread > 1 )
+       {
+               fprintf( stderr, "\nThe order of distances is not identical to that in the input file, because of the parallel calculation.  Reorder them by yourself, using sort -n -k 2 | sort -n -k 1 -s\n" );
+       }
+       if( stdout_align && nthread > 1 )
+       {
+               fprintf( stderr, "\nThe order of pairwise alignments is not identical to that in the input file, because of the parallel calculation.  Reorder them by yourself.\n" );
+       }
+       FreeCharMtx( seq );
+       FreeCharMtx( aseq );
+       FreeCharMtx( bseq );
+       FreeCharMtx( name );
+       free( mseq1 );
+       free( mseq2 );
+       free( eff );
+
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/partQalignmm.c b/binaries/src/mafft/core/partQalignmm.c
new file mode 100644 (file)
index 0000000..d89e186
--- /dev/null
@@ -0,0 +1,1262 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 1
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+
+static int impalloclen = 0;
+static float **impmtx = NULL;
+float part_imp_match_out_scQ( int i1, int j1 )
+{
+//     fprintf( stderr, "impalloclen = %d\n", impalloclen );
+//     fprintf( stderr, "i1,j1=%d,%d -> impmtx=%f\n", i1, j1, impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+#if 0
+       if( i1 == l1 || j1 == l2 ) return( 0.0 );
+       return( impmtx[i1+start1][j1+start2] );
+#endif
+}
+static void part_imp_match_out_vead_gapmapQ( float *imp, int i1, int lgth2, int start2, int *gapmap2 )
+{
+#if FASTMACHCALC
+       float *pt = imp;
+       int *gapmappt = gapmap2;
+       while( lgth2-- )
+               *pt++ += impmtx[i1][start2+*gapmappt++];
+#else
+       int j;
+       for( j=0; j<lgth2; j++ )
+       {
+               imp[j] += impmtx[i1][start2+gapmap2[j]];
+       }
+#endif
+}
+
+static void part_imp_match_out_vead_tate_gapmapQ( float *imp, int j1, int lgth1, int start1, int *gapmap1 )
+{
+#if FASTMACHCALC
+       float *pt = imp;
+       int *gapmappt = gapmap1;
+       while( lgth1-- )
+               *pt++ = impmtx[start1+*gapmappt++][j1];
+#else
+       int i;
+       for( i=0; i<lgth1; i++ )
+       {
+               imp[i] += impmtx[start1+gapmap1[i]][j1];
+       }
+#endif
+}
+
+void part_imp_match_init_strictQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       double effij, effijx; 
+       char *pt, *pt1, *pt2;
+       LocalHom *tmpptr;
+
+       if( impalloclen <= lgth1 + 2 || impalloclen <= lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen+100, impalloclen+100 );
+       }
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx = 1.0 * fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = eff1[i] * eff2[j] * effijx;
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = (int)( pt - seq1[i] ) - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = (int)( pt - seq1[i] ) - 1;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = (int)( pt - seq1[i] ) - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = (int)( pt - seq2[j] ) - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = (int)( pt - seq2[j] ) - 1;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = (int)( pt - seq2[j] ) - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+                                               impmtx[k1][k2] += tmpptr->fimportance * effij;
+//                                             fprintf( stderr, "k1=%d, k2=%d, impalloclen=%d\n", k1, k2, impalloclen );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+#if 0
+       fprintf( stderr, "impmtx = \n" );
+       for( k2=0; k2<lgth2; k2++ )
+               fprintf( stderr, "%6.3f ", (double)k2 );
+       fprintf( stderr, "\n" );
+       for( k1=0; k1<lgth1; k1++ )
+       {
+               fprintf( stderr, "%d", k1 );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+               fprintf( stderr, "\n" );
+       }
+       exit( 1 );
+#endif
+}
+
+
+void part_imp_rnaQ( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
+{
+       foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
+}
+
+
+void part_imp_match_initQ( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom )
+{
+       int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       static int impalloclen = 0;
+       char *pt;
+       static char *nocount1 = NULL;
+       static char *nocount2 = NULL;
+
+       if( impalloclen < lgth1 || impalloclen < lgth2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+               impalloclen -= 2;
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       for( i=0; i<clus1; i++ )
+       {
+               fprintf( stderr, "i = %d, seq1 = %s\n", i, seq1[i] );
+               for( j=0; j<clus2; j++ )
+               {
+                       fprintf( stderr, "start1 = %d\n", localhom[i][j]->start1 );
+                       fprintf( stderr, "end1   = %d\n", localhom[i][j]->end1   );
+                       fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] );
+                       pt = seq1[i];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start1 ) break;
+                       }
+                       start1 = pt - seq1[i] - 1;
+
+                       while( *pt != 0 )
+                       {
+//                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] );
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end1 ) break;
+                       }
+                       end1 = pt - seq1[i] - 1;
+
+                       pt = seq2[j];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start2 ) break;
+                       }
+                       start2 = pt - seq2[j] - 1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end2 ) break;
+                       }
+                       end2 = pt - seq2[j] - 1;
+//                     fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                       k1 = start1;
+                       k2 = start2;
+                       fprintf( stderr, "step 0\n" );
+                       while( k1 <= end1 && k2 <= end2 )
+                       {
+#if 0
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#else
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#endif
+                       }
+
+                       dif = ( end1 - start1 ) - ( end2 - start2 );
+                       fprintf( stderr, "dif = %d\n", dif );
+                       if( dif > 0 )
+                       {
+                               do
+                               {
+                                       fprintf( stderr, "dif = %d\n", dif );
+                                       k1 = start1;
+                                       k2 = start2 - dif;
+                                       while( k1 <= end1 && k2 <= end2 )
+                                       {
+                                               if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif-- );
+                       }
+                       else
+                       {
+                               do
+                               {
+                                       k1 = start1 + dif;
+                                       k2 = start2;
+                                       while( k1 <= end1 )
+                                       {
+                                               if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif++ );
+                       }
+               }
+       }
+#if 0
+       fprintf( stderr, "impmtx = \n" );
+       for( k2=0; k2<lgth2; k2++ )
+               fprintf( stderr, "%6.3f ", (double)k2 );
+       fprintf( stderr, "\n" );
+       for( k1=0; k1<lgth1; k1++ )
+       {
+               fprintf( stderr, "%d", k1 );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", impmtx[k1][k2] );
+               fprintf( stderr, "\n" );
+       }
+       exit( 1 );
+#endif
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+//                             scarr[l] += n_dis[j][l] * cpmx1[j][i1];
+                               scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       // simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+//                     scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+                       scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int start1, int end1, int start2, int end2,
+                                               int *gapmap1, int *gapmap2 )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+//     char gap[] = "-";
+       char *gap;
+       float wm;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin != lgth1 && jin != lgth2 ) // ??
+               {
+                       *impwmpt += part_imp_match_out_scQ( gapmap1[iin]+start1, gapmap2[jin]+start2 );
+//                     fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+}
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, lastk;
+//     char gap[] = "-";
+       char *gap;
+       float wm = 0.0;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       lastk = lgth1+lgth2;
+       for( k=0; k<=lastk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+float partQ__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *sgap1, char *sgap2, char *egap1, char *egap2 )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static float mi, *m;
+       static int **ijp;
+       static int mpi, *mp;
+       static float *w1, *w2;
+       static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static char **mseq;
+       static float *digf1; 
+       static float *digf2; 
+       static float *diaf1; 
+       static float *diaf2; 
+       static float *gapz1; 
+       static float *gapz2; 
+       static float *gapf1; 
+       static float *gapf2; 
+       static float *ogcp1g;
+       static float *ogcp2g;
+       static float *fgcp1g;
+       static float *fgcp2g;
+       static float *og_h_dg_n1_p;
+       static float *og_h_dg_n2_p;
+       static float *fg_h_dg_n1_p;
+       static float *fg_h_dg_n2_p;
+       static float *og_t_fg_h_dg_n1_p;
+       static float *og_t_fg_h_dg_n2_p;
+       static float *fg_t_og_h_dg_n1_p;
+       static float *fg_t_og_h_dg_n2_p;
+       static float *gapz_n1;
+       static float *gapz_n2;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+       float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+       float tmppenal;
+       float *fg_t_og_h_dg_n2_p_pt;
+       float *og_t_fg_h_dg_n2_p_pt;
+       float *og_h_dg_n2_p_pt;
+       float *fg_h_dg_n2_p_pt;
+       float *gapz_n2_pt0;
+       float *gapz_n2_pt1;
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fg_t_og_h_dg_n1_p_va;
+       float og_t_fg_h_dg_n1_p_va;
+       float og_h_dg_n1_p_va;
+       float fg_h_dg_n1_p_va;
+       float gapz_n1_va0;
+       float gapz_n1_va1;
+       float fgcp1va;
+       float ogcp1va;
+
+
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( digf1 );
+                       FreeFloatVec( digf2 );
+                       FreeFloatVec( diaf1 );
+                       FreeFloatVec( diaf2 );
+                       FreeFloatVec( gapz1 );
+                       FreeFloatVec( gapz2 );
+                       FreeFloatVec( gapf1 );
+                       FreeFloatVec( gapf2 );
+                       FreeFloatVec( ogcp1g );
+                       FreeFloatVec( ogcp2g );
+                       FreeFloatVec( fgcp1g );
+                       FreeFloatVec( fgcp2g );
+                       FreeFloatVec( og_h_dg_n1_p );
+                       FreeFloatVec( og_h_dg_n2_p );
+                       FreeFloatVec( fg_h_dg_n1_p );
+                       FreeFloatVec( fg_h_dg_n2_p );
+                       FreeFloatVec( og_t_fg_h_dg_n1_p );
+                       FreeFloatVec( og_t_fg_h_dg_n2_p );
+                       FreeFloatVec( fg_t_og_h_dg_n1_p );
+                       FreeFloatVec( fg_t_og_h_dg_n2_p );
+                       FreeFloatVec( gapz_n1 );
+                       FreeFloatVec( gapz_n2 );
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               digf1 = AllocateFloatVec( ll1+2 );
+               digf2 = AllocateFloatVec( ll2+2 );
+               diaf1 = AllocateFloatVec( ll1+2 );
+               diaf2 = AllocateFloatVec( ll2+2 );
+               gapz1 = AllocateFloatVec( ll1+2 );
+               gapz2 = AllocateFloatVec( ll2+2 );
+               gapf1 = AllocateFloatVec( ll1+2 );
+               gapf2 = AllocateFloatVec( ll2+2 );
+               ogcp1g = AllocateFloatVec( ll1+2 );
+               ogcp2g = AllocateFloatVec( ll2+2 );
+               fgcp1g = AllocateFloatVec( ll1+2 );
+               fgcp2g = AllocateFloatVec( ll2+2 );
+               og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               og_t_fg_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               og_t_fg_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               fg_t_og_h_dg_n1_p = AllocateFloatVec( ll1 + 2 );
+               fg_t_og_h_dg_n2_p = AllocateFloatVec( ll2 + 2 );
+               gapz_n1 = AllocateFloatVec( ll1+2 );
+               gapz_n2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount_zure( ogcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_OpeningGapCount_zure( ogcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               new_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               new_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdigapfreq_part( digf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdigapfreq_part( digf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getdiaminofreq_part( diaf1, icyc, seq1, eff1, lgth1, sgap1, egap1 );
+               getdiaminofreq_part( diaf2, jcyc, seq2, eff2, lgth2, sgap2, egap2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure_part( gapz1, icyc, seq1, eff1, lgth1, sgap1 );
+               getgapfreq_zure_part( gapz2, jcyc, seq2, eff2, lgth2, sgap1 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1g, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2g, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount_zure( fgcp1g, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount_zure( fgcp2g, jcyc, seq2, eff2, lgth2 );
+               getdigapfreq_st( digf1, icyc, seq1, eff1, lgth1 );
+               getdigapfreq_st( digf2, jcyc, seq2, eff2, lgth2 );
+               getdiaminofreq_x( diaf1, icyc, seq1, eff1, lgth1 );
+               getdiaminofreq_x( diaf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq( gapf1, icyc, seq1, eff1, lgth1 );
+               getgapfreq( gapf2, jcyc, seq2, eff2, lgth2 );
+               getgapfreq_zure( gapz1, icyc, seq1, eff1, lgth1 );
+               getgapfreq_zure( gapz2, jcyc, seq2, eff2, lgth2 );
+       }
+
+#if 1
+       lastj = lgth2+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n2_p[i] = ( 1.0-ogcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               fg_h_dg_n2_p[i] = ( 1.0-fgcp2g[i]-digf2[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n2_p[i] = (1.0-ogcp2g[i]+fgcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n2_p[i] = (1.0-fgcp2g[i]+ogcp2g[i]-digf2[i]) * 0.5 * fpenalty;
+               gapz_n2[i] = (1.0-gapz2[i]);
+       }
+       lastj = lgth1+2;
+       for( i=0; i<lastj; i++ )
+       {
+               og_h_dg_n1_p[i] = ( 1.0-ogcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               fg_h_dg_n1_p[i] = ( 1.0-fgcp1g[i]-digf1[i] ) * fpenalty * 0.5;
+               og_t_fg_h_dg_n1_p[i] = (1.0-ogcp1g[i]+fgcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               fg_t_og_h_dg_n1_p[i] = (1.0-fgcp1g[i]+ogcp1g[i]-digf1[i]) * 0.5 * fpenalty;
+               gapz_n1[i] = (1.0-gapz1[i]);
+       }
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               part_imp_match_out_vead_tate_gapmapQ( initverticalw, gapmap2[0]+start2, lgth1, start1, gapmap1 );
+
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               part_imp_match_out_vead_gapmapQ( currentw, gapmap1[0]+start1, lgth2, start2, gapmap2 );
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+       if( outgap == 1 )
+       {
+               g = 0.0;
+
+               g += ogcp1g[0] * og_h_dg_n2_p[0];
+
+               g += ogcp2g[0] * og_h_dg_n1_p[0];
+
+               g += fgcp1g[0] * fg_h_dg_n2_p[0];
+
+               g += fgcp2g[0] * fg_h_dg_n1_p[0];
+
+               initverticalw[0] += g;
+               currentw[0] += g;
+
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       tmppenal = gapz_n2[0]*og_t_fg_h_dg_n1_p[0];
+                       initverticalw[i] += tmppenal;
+
+                       tmppenal = gapz_n2[1]*fg_t_og_h_dg_n1_p[i];
+                       initverticalw[i] += tmppenal;
+
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       tmppenal = gapz_n1[0]*og_t_fg_h_dg_n2_p[0];
+                       currentw[j] += tmppenal;
+
+                       tmppenal = gapz_n1[1]*fg_t_og_h_dg_n2_p[j];
+                       currentw[j] += tmppenal;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                               currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       m[0] = 0.0; // iranai
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               mp[j] = 0;
+               m[j] = currentw[j-1] + 10000 * fpenalty; //iinoka?
+       }
+       if( lgth2 == 0 )
+               lastverticalw[0] = 0.0; // Falign kara yobaretatoki kounarukanousei ari
+       else
+               lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+       lastj = lgth2+1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+//                     imp_match_out_vead( currentw, i, lgth2 );
+                       part_imp_match_out_vead_gapmapQ( currentw, gapmap1[i]+start1, lgth2, start2, gapmap2 );
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mpi = 0;
+               mi = previousw[0] + 10000 * fpenalty;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fg_t_og_h_dg_n2_p_pt = fg_t_og_h_dg_n2_p + 1;
+               og_t_fg_h_dg_n2_p_pt = og_t_fg_h_dg_n2_p + 1;
+               og_h_dg_n2_p_pt = og_h_dg_n2_p + 1;
+               fg_h_dg_n2_p_pt = fg_h_dg_n2_p + 1;
+               gapz_n2_pt0 = gapz_n2 + 1;
+               gapz_n2_pt1 = gapz_n2 + 2;
+               fgcp2pt = fgcp2g + 1;
+               ogcp2pt = ogcp2g + 1;
+
+               fg_t_og_h_dg_n1_p_va = fg_t_og_h_dg_n1_p[i];
+               og_t_fg_h_dg_n1_p_va = og_t_fg_h_dg_n1_p[i];
+               og_h_dg_n1_p_va = og_h_dg_n1_p[i];
+               fg_h_dg_n1_p_va = fg_h_dg_n1_p[i];
+               gapz_n1_va0 = gapz_n1[i];
+               gapz_n1_va1 = gapz_n1[i+1];
+               fgcp1va = fgcp1g[i];
+               ogcp1va = ogcp1g[i];
+
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+
+                       g = ogcp1va * *og_h_dg_n2_p_pt;
+                       wm += g;
+
+                       g = *ogcp2pt * og_h_dg_n1_p_va;
+                       wm += g;
+
+                       g = fgcp1va * *fg_h_dg_n2_p_pt;
+                       wm += g;
+
+                       g = *fgcp2pt * fg_h_dg_n1_p_va;
+                       wm += g;
+
+                       *ijppt = 0;
+
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       tmppenal = gapz_n1_va1 * *fg_t_og_h_dg_n2_p_pt;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=mi+tmppenal) > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+
+                       tmppenal = gapz_n1_va0 * *og_t_fg_h_dg_n2_p_pt;
+                       if( (g=*prept+tmppenal) >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       tmppenal = *gapz_n2_pt1 * fg_t_og_h_dg_n1_p_va;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( (g=*mjpt+tmppenal) > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+
+                       tmppenal = *gapz_n2_pt0 * og_t_fg_h_dg_n1_p_va;
+                       if( (g=*prept+tmppenal) >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt++ += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       fg_t_og_h_dg_n2_p_pt++;
+                       og_t_fg_h_dg_n2_p_pt++;
+                       og_h_dg_n2_p_pt++;
+                       fg_h_dg_n2_p_pt++;
+                       gapz_n2_pt0++;
+                       gapz_n2_pt1++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, start1, end1, start2, end2, gapmap1, gapmap2 );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+//     fprintf( stderr, "wm = %f\n", wm );
+
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/partSalignmm.c b/binaries/src/mafft/core/partSalignmm.c
new file mode 100644 (file)
index 0000000..b670b73
--- /dev/null
@@ -0,0 +1,1266 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MACHIGAI 0
+#define OUTGAP0TRY 1
+#define DEBUG 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  0
+#define FASTMATCHCALC 1
+
+#if 0
+static void st_OpeningGapCount( float *ogcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) ogcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = 0;
+               for( i=0; i<len; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( !gb *  gc ) ogcp[i] += feff;
+                       }
+               }
+       }
+}
+
+static void st_FinalGapCount( float *fgcp, int clus, char **seq, double *eff, int len )
+{
+       int i, j, gc, gb; 
+       float feff;
+       
+       for( i=0; i<len; i++ ) fgcp[i] = 0.0;
+       for( j=0; j<clus; j++ ) 
+       {
+               feff = (float)eff[j];
+               gc = ( seq[j][0] == '-' );
+               for( i=1; i<len+1; i++ ) 
+               {
+                       gb = gc;
+                       gc = ( seq[j][i] == '-' );
+                       {
+                               if( gb * !gc ) fgcp[i-1] += feff;
+                       }
+               }
+       }
+}
+#endif
+
+
+                       
+               
+
+static TLS int impalloclen = 0;
+static TLS float **impmtx = NULL;
+float part_imp_match_out_sc( int i1, int j1 )
+{
+//     fprintf( stderr, "impalloclen = %d\n", impalloclen );
+//     fprintf( stderr, "i1,j1=%d,%d -> impmtx=%f\n", i1, j1, impmtx[i1][j1] );
+       return( impmtx[i1][j1] );
+#if 0
+       if( i1 == l1 || j1 == l2 ) return( 0.0 );
+       return( impmtx[i1+start1][j1+start2] );
+#endif
+}
+static void part_imp_match_out_vead_gapmap( float *imp, int i1, int lgth2, int start2, int *gapmap2 )
+{
+#if FASTMACHCALC
+       float *pt = imp;
+       int *gapmappt = gapmap2;
+       while( lgth2-- )
+               *pt++ += impmtx[i1][start2+*gapmappt++];
+#else
+       int j;
+       for( j=0; j<lgth2; j++ )
+       {
+               imp[j] += impmtx[i1][start2+gapmap2[j]];
+       }
+#endif
+}
+
+static void part_imp_match_out_vead_tate_gapmap( float *imp, int j1, int lgth1, int start1, int *gapmap1 )
+{
+#if FASTMACHCALC
+       float *pt = imp;
+       int *gapmappt = gapmap1;
+       while( lgth1-- )
+               *pt++ = impmtx[start1+*gapmappt++][j1];
+#else
+       int i;
+       for( i=0; i<lgth1; i++ )
+       {
+               imp[i] += impmtx[start1+gapmap1[i]][j1];
+       }
+#endif
+}
+
+void part_imp_match_init_strict( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, double *eff1_kozo, double *eff2_kozo, LocalHom ***localhom, int forscore )
+{
+       int i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       double effij, effijx, effij_kozo; 
+       char *pt, *pt1, *pt2;
+       LocalHom *tmpptr;
+
+       if( seq1 == NULL )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               impmtx = NULL;
+               return;
+       }
+
+       if( impalloclen <= lgth1 + 2 || impalloclen <= lgth2 + 2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen+100, impalloclen+100 );
+       }
+
+
+#if 0
+       fprintf( stderr, "eff1 in _init_strict = \n" );
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "eff1[] = %f\n", eff1[i] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "eff2[] = %f\n", eff2[i] );
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       effijx = 1.0 * fastathreshold;
+       for( i=0; i<clus1; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+               {
+                       effij = eff1[i] * eff2[j] * effijx;
+                       effij_kozo = eff1_kozo[i] * eff2_kozo[j] * effijx;
+                       tmpptr = localhom[i][j];
+                       while( tmpptr )
+                       {
+//                             fprintf( stderr, "start1 = %d\n", tmpptr->start1 );
+//                             fprintf( stderr, "end1   = %d\n", tmpptr->end1   );
+//                             fprintf( stderr, "i = %d, seq1 = \n%s\n", i, seq1[i] );
+//                             fprintf( stderr, "j = %d, seq2 = \n%s\n", j, seq2[j] );
+                               pt = seq1[i];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start1 ) break;
+                               }
+                               start1 = (int)( pt - seq1[i] ) - 1;
+       
+                               if( tmpptr->start1 == tmpptr->end1 ) end1 = start1;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end1 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end1 = (int)( pt - seq1[i] ) - 1;
+#else
+                                       while( *pt != 0 )
+                                       {
+//                                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, tmpptr->end1, pt-seq1[i] );
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end1 ) break;
+                                       }
+                                       end1 = (int)( pt - seq1[i] ) - 1;
+#endif
+                               }
+       
+                               pt = seq2[j];
+                               tmpint = -1;
+                               while( *pt != 0 )
+                               {
+                                       if( *pt++ != '-' ) tmpint++;
+                                       if( tmpint == tmpptr->start2 ) break;
+                               }
+                               start2 = (int)( pt - seq2[j] ) - 1;
+                               if( tmpptr->start2 == tmpptr->end2 ) end2 = start2;
+                               else
+                               {
+#if MACHIGAI
+                                       while( *pt != 0 )
+                                       {
+                                               if( tmpint == tmpptr->end2 ) break;
+                                               if( *pt++ != '-' ) tmpint++;
+                                       }
+                                       end2 = (int)( pt - seq2[j] ) - 1;
+#else
+                                       while( *pt != 0 )
+                                       {
+                                               if( *pt++ != '-' ) tmpint++;
+                                               if( tmpint == tmpptr->end2 ) break;
+                                       }
+                                       end2 = (int)( pt - seq2[j] ) - 1;
+#endif
+                               }
+//                             fprintf( stderr, "start1 = %d (%c), end1 = %d (%c), start2 = %d (%c), end2 = %d (%c)\n", start1, seq1[i][start1], end1, seq1[i][end1], start2, seq2[j][start2], end2, seq2[j][end2] );
+//                             fprintf( stderr, "step 0\n" );
+                               if( end1 - start1 != end2 - start2 )
+                               {
+//                                     fprintf( stderr, "CHUUI!!, start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                               }
+
+                               k1 = start1; k2 = start2;
+                               pt1 = seq1[i] + k1;
+                               pt2 = seq2[j] + k2;
+                               while( *pt1 && *pt2 )
+                               {
+                                       if( *pt1 != '-' && *pt2 != '-' )
+                                       {
+// ½Å¤ß¤òÆó½Å¤Ë¤«¤±¤Ê¤¤¤è¤¦¤ËÃí°Õ¤·¤Æ²¼¤µ¤¤¡£
+//                                             impmtx[k1][k2] += tmpptr->wimportance * fastathreshold;
+//                                             impmtx[k1][k2] += tmpptr->importance * effij;
+//                                             impmtx[k1][k2] += tmpptr->fimportance * effij;
+                                               if( tmpptr->korh == 'k' )
+                                                       impmtx[k1][k2] += tmpptr->fimportance * effij_kozo;
+                                               else
+                                                       impmtx[k1][k2] += tmpptr->fimportance * effij;
+//                                             fprintf( stderr, "k1=%d, k2=%d, impalloclen=%d\n", k1, k2, impalloclen );
+//                                             fprintf( stderr, "mark, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; k2++;
+                                               pt1++; pt2++;
+                                       }
+                                       else if( *pt1 != '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k2++; pt2++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 != '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                       }
+                                       else if( *pt1 == '-' && *pt2 == '-' )
+                                       {
+//                                             fprintf( stderr, "skip, %d (%c) - %d (%c) \n", k1, *pt1, k2, *pt2 );
+                                               k1++; pt1++;
+                                               k2++; pt2++;
+                                       }
+                                       if( k1 > end1 || k2 > end2 ) break;
+                               }
+                               tmpptr = tmpptr->next;
+                       }
+               }
+       }
+#if 0
+       fprintf( stderr, "impmtx = \n" );
+       for( k2=0; k2<lgth2; k2++ )
+               fprintf( stderr, "%6.3f ", (double)k2 );
+       fprintf( stderr, "\n" );
+       for( k1=0; k1<lgth1; k1++ )
+       {
+               fprintf( stderr, "%d", k1 );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%2.1f ", impmtx[k1][k2] );
+               fprintf( stderr, "\n" );
+       }
+       exit( 1 );
+#endif
+}
+
+
+void part_imp_rna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, int *gapmap1, int *gapmap2, RNApair *additionalpair )
+{
+       foldrna( nseq1, nseq2, seq1, seq2, eff1, eff2, grouprna1, grouprna2, impmtx, gapmap1, gapmap2, additionalpair );
+}
+
+
+void part_imp_match_init( float *imp, int clus1, int clus2, int lgth1, int lgth2, char **seq1, char **seq2, double *eff1, double *eff2, LocalHom ***localhom )
+{
+       int dif, i, j, k1, k2, tmpint, start1, start2, end1, end2;
+       static TLS int impalloclen = 0;
+       char *pt;
+       static TLS char *nocount1 = NULL;
+       static TLS char *nocount2 = NULL;
+
+       if( impalloclen < lgth1 || impalloclen < lgth2 )
+       {
+               if( impmtx ) FreeFloatMtx( impmtx );
+               if( nocount1 ) free( nocount1 );
+               if( nocount2 ) free( nocount2 );
+               impalloclen = MAX( lgth1, lgth2 ) + 2;
+               impmtx = AllocateFloatMtx( impalloclen, impalloclen );
+               nocount1 = AllocateCharVec( impalloclen );
+               nocount2 = AllocateCharVec( impalloclen );
+               impalloclen -= 2;
+       }
+
+       for( i=0; i<lgth1; i++ )
+       {
+               for( j=0; j<clus1; j++ )
+                       if( seq1[j][i] == '-' ) break;
+               if( j != clus1 ) nocount1[i] = 1; 
+               else                     nocount1[i] = 0;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               for( j=0; j<clus2; j++ )
+                       if( seq2[j][i] == '-' ) break;
+               if( j != clus2 ) nocount2[i] = 1;
+               else                     nocount2[i] = 0;
+       }
+
+#if 0
+fprintf( stderr, "nocount2 =\n" );
+for( i = 0; i<impalloclen; i++ )
+{
+       fprintf( stderr, "nocount2[%d] = %d (%c)\n", i, nocount2[i], seq2[0][i] );
+}
+#endif
+
+       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               impmtx[i][j] = 0.0;
+       for( i=0; i<clus1; i++ )
+       {
+               fprintf( stderr, "i = %d, seq1 = %s\n", i, seq1[i] );
+               for( j=0; j<clus2; j++ )
+               {
+                       fprintf( stderr, "start1 = %d\n", localhom[i][j]->start1 );
+                       fprintf( stderr, "end1   = %d\n", localhom[i][j]->end1   );
+                       fprintf( stderr, "j = %d, seq2 = %s\n", j, seq2[j] );
+                       pt = seq1[i];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start1 ) break;
+                       }
+                       start1 = pt - seq1[i] - 1;
+
+                       while( *pt != 0 )
+                       {
+//                             fprintf( stderr, "tmpint = %d, end1 = %d pos = %d\n", tmpint, localhom[i][j].end1, pt-seq1[i] );
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end1 ) break;
+                       }
+                       end1 = pt - seq1[i] - 1;
+
+                       pt = seq2[j];
+                       tmpint = -1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->start2 ) break;
+                       }
+                       start2 = pt - seq2[j] - 1;
+                       while( *pt != 0 )
+                       {
+                               if( *pt++ != '-' ) tmpint++;
+                               if( tmpint == localhom[i][j]->end2 ) break;
+                       }
+                       end2 = pt - seq2[j] - 1;
+//                     fprintf( stderr, "start1 = %d, end1 = %d, start2 = %d, end2 = %d\n", start1, end1, start2, end2 );
+                       k1 = start1;
+                       k2 = start2;
+                       fprintf( stderr, "step 0\n" );
+                       while( k1 <= end1 && k2 <= end2 )
+                       {
+#if 0
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j].wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#else
+                               if( !nocount1[k1] && !nocount2[k2] )
+                                       impmtx[k1][k2] += localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                               k1++; k2++;
+#endif
+                       }
+
+                       dif = ( end1 - start1 ) - ( end2 - start2 );
+                       fprintf( stderr, "dif = %d\n", dif );
+                       if( dif > 0 )
+                       {
+                               do
+                               {
+                                       fprintf( stderr, "dif = %d\n", dif );
+                                       k1 = start1;
+                                       k2 = start2 - dif;
+                                       while( k1 <= end1 && k2 <= end2 )
+                                       {
+                                               if( 0 <= k2 && start2 <= k2 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif-- );
+                       }
+                       else
+                       {
+                               do
+                               {
+                                       k1 = start1 + dif;
+                                       k2 = start2;
+                                       while( k1 <= end1 )
+                                       {
+                                               if( k1 >= 0 && k1 >= start1 && !nocount1[k1] && !nocount2[k2] )
+                                                       impmtx[k1][k2] = localhom[i][j]->wimportance * eff1[i] * eff2[j];
+                                               k1++; k2++;
+                                       }
+                               }
+                               while( dif++ );
+                       }
+               }
+       }
+#if 0
+       fprintf( stderr, "impmtx = \n" );
+       for( k2=0; k2<lgth2; k2++ )
+               fprintf( stderr, "%6.3f ", (double)k2 );
+       fprintf( stderr, "\n" );
+       for( k1=0; k1<lgth1; k1++ )
+       {
+               fprintf( stderr, "%d", k1 );
+               for( k2=0; k2<lgth2; k2++ )
+                       fprintf( stderr, "%6.3f ", impmtx[k1][k2] );
+               fprintf( stderr, "\n" );
+       }
+       exit( 1 );
+#endif
+}
+
+static void match_calc( float *match, float **cpmx1, float **cpmx2, int i1, int lgth2, float **floatwork, int **intwork, int initialize )
+{
+#if FASTMATCHCALC
+       int j, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       float *matchpt, *cpmxpdpt, **cpmxpdptpt;
+       int *cpmxpdnpt, **cpmxpdnptpt;
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[j][count] = cpmx2[l][j];
+                                       cpmxpdn[j][count] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[j][count] = -1;
+               }
+       }
+
+       {
+               for( l=0; l<26; l++ )
+               {
+                       scarr[l] = 0.0;
+                       for( j=0; j<26; j++ )
+                               scarr[l] += n_dis_consweight_multi[j][l] * cpmx1[j][i1];
+//                             scarr[l] += n_dis[j][l] * cpmx1[j][i1];
+               }
+               matchpt = match;
+               cpmxpdnptpt = cpmxpdn;
+               cpmxpdptpt = cpmxpd;
+               while( lgth2-- )
+               {
+                       *matchpt = 0.0;
+                       cpmxpdnpt = *cpmxpdnptpt++;
+                       cpmxpdpt = *cpmxpdptpt++;
+                       while( *cpmxpdnpt>-1 )
+                               *matchpt += scarr[*cpmxpdnpt++] * *cpmxpdpt++;
+                       matchpt++;
+               } 
+       }
+#else
+       int j, k, l;
+       float scarr[26];
+       float **cpmxpd = floatwork;
+       int **cpmxpdn = intwork;
+       // simple
+       if( initialize )
+       {
+               int count = 0;
+               for( j=0; j<lgth2; j++ )
+               {
+                       count = 0;
+                       for( l=0; l<26; l++ )
+                       {
+                               if( cpmx2[l][j] )
+                               {
+                                       cpmxpd[count][j] = cpmx2[l][j];
+                                       cpmxpdn[count][j] = l;
+                                       count++;
+                               }
+                       }
+                       cpmxpdn[count][j] = -1;
+               }
+       }
+       for( l=0; l<26; l++ )
+       {
+               scarr[l] = 0.0;
+               for( k=0; k<26; k++ )
+                       scarr[l] += n_dis_consweight_multi[k][l] * cpmx1[k][i1];
+//                     scarr[l] += n_dis[k][l] * cpmx1[k][i1];
+       }
+       for( j=0; j<lgth2; j++ )
+       {
+               match[j] = 0.0;
+               for( k=0; cpmxpdn[k][j]>-1; k++ )
+                       match[j] += scarr[cpmxpdn[k][j]] * cpmxpd[k][j];
+       } 
+#endif
+}
+
+static void Atracking_localhom( float *impwmpt, float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc,
+                                               int start1, int end1, int start2, int end2,
+                                               int *gapmap1, int *gapmap2 )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k;
+//     char gap[] = "-";
+       char *gap;
+       float wm;
+       gap = newgapstr;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       *impwmpt = 0.0;
+       for( k=0; k<=lgth1+lgth2; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin != lgth1 && jin != lgth2 ) // ??
+               {
+                       *impwmpt += part_imp_match_out_sc( gapmap1[iin]+start1, gapmap2[jin]+start2 );
+//                     fprintf( stderr, "impwm = %f (iin=%d, jin=%d) seq1=%c, seq2=%c\n", *impwmpt, iin, jin, seq1[0][iin], seq2[0][jin] );
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+}
+static float Atracking( float *lasthorizontalw, float *lastverticalw, 
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijp, int icyc, int jcyc )
+{
+       int i, j, l, iin, jin, ifi, jfi, lgth1, lgth2, k, lastk;
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       float wm = 0.0;
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+       {
+               fprintf( stderr, "lastverticalw[%d] = %f\n", i, lastverticalw[i] );
+       }
+#endif
+       if( outgap == 1 )
+               ;
+       else
+       {
+               wm = lastverticalw[0];
+               for( i=0; i<lgth1; i++ )
+               {
+                       if( lastverticalw[i] >= wm )
+                       {
+                               wm = lastverticalw[i];
+                               iin = i; jin = lgth2-1;
+                               ijp[lgth1][lgth2] = +( lgth1 - i );
+                       }
+               }
+               for( j=0; j<lgth2; j++ )
+               {
+                       if( lasthorizontalw[j] >= wm )
+                       {
+                               wm = lasthorizontalw[j];
+                               iin = lgth1-1; jin = j;
+                               ijp[lgth1][lgth2] = -( lgth2 - j );
+                       }
+               }
+       }
+
+    for( i=0; i<lgth1+1; i++ ) 
+    {
+        ijp[i][0] = i + 1;
+    }
+    for( j=0; j<lgth2+1; j++ ) 
+    {
+        ijp[0][j] = -( j + 1 );
+    }
+
+       for( i=0; i<icyc; i++ )
+       {
+               mseq1[i] += lgth1+lgth2;
+               *mseq1[i] = 0;
+       }
+       for( j=0; j<jcyc; j++ )
+       {
+               mseq2[j] += lgth1+lgth2;
+               *mseq2[j] = 0;
+       }
+       iin = lgth1; jin = lgth2;
+       lastk = lgth1+lgth2;
+       for( k=0; k<=lastk; k++ ) 
+       {
+               if( ijp[iin][jin] < 0 ) 
+               {
+                       ifi = iin-1; jfi = jin+ijp[iin][jin];
+               }
+               else if( ijp[iin][jin] > 0 )
+               {
+                       ifi = iin-ijp[iin][jin]; jfi = jin-1;
+               }
+               else
+               {
+                       ifi = iin-1; jfi = jin-1;
+               }
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       for( i=0; i<icyc; i++ )
+                               *--mseq1[i] = seq1[i][ifi+l];
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       for( i=0; i<icyc; i++ ) 
+                               *--mseq1[i] = *gap;
+                       for( j=0; j<jcyc; j++ ) 
+                               *--mseq2[j] = seq2[j][jfi+l];
+                       k++;
+               }
+               if( iin <= 0 || jin <= 0 ) break;
+               for( i=0; i<icyc; i++ ) 
+                       *--mseq1[i] = seq1[i][ifi];
+               for( j=0; j<jcyc; j++ ) 
+                       *--mseq2[j] = seq2[j][jfi];
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       return( 0.0 );
+}
+
+float partA__align( char **seq1, char **seq2, double *eff1, double *eff2, int icyc, int jcyc, int alloclen, LocalHom ***localhom, float *impmatch, int start1, int end1, int start2, int end2, int *gapmap1, int *gapmap2, char *sgap1, char *sgap2, char *egap1, char *egap2, int *chudanpt, int chudanref, int *chudanres )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+//     int k;
+       register int i, j;
+       int lasti, lastj; /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   /* int ?????? */
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijppt;
+       float *mjpt, *prept, *curpt;
+       int *mpjpt;
+#endif
+       static TLS float mi, *m;
+       static TLS int **ijp;
+       static TLS int mpi, *mp;
+       static TLS float *w1, *w2;
+       static TLS float *match;
+       static TLS float *initverticalw;    /* kufuu sureba iranai */
+       static TLS float *lastverticalw;    /* kufuu sureba iranai */
+       static TLS char **mseq1;
+       static TLS char **mseq2;
+       static TLS char **mseq;
+       static TLS float *ogcp1;
+       static TLS float *ogcp2;
+       static TLS float *fgcp1;
+       static TLS float *fgcp2;
+       static TLS float **cpmx1;
+       static TLS float **cpmx2;
+       static TLS int **intwork;
+       static TLS float **floatwork;
+       static TLS int orlgth1 = 0, orlgth2 = 0;
+       float fpenalty = (float)penalty;
+#if USE_PENALTY_EX
+       float fpenalty_ex = (float)penalty_ex;
+#endif
+       float *fgcp2pt;
+       float *ogcp2pt;
+       float fgcp1va;
+       float ogcp1va;
+
+
+       if( seq1 == NULL )
+       {
+               if( orlgth1 )
+               {
+//                     fprintf( stderr, "## Freeing local arrays in A__align\n" );
+                       orlgth1 = 0;
+                       orlgth2 = 0;
+
+                       part_imp_match_init_strict( NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0 );
+
+                       free( mseq1 );
+                       free( mseq2 );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+
+               }
+               else
+               {
+//                     fprintf( stderr, "## Not allocated\n" );
+               }
+               return( 0.0 );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+#if 1
+       if( lgth1 == 0 ) fprintf( stderr, "WARNING: lgth1=0 in partA__align\n" );
+       if( lgth2 == 0 ) fprintf( stderr, "WARNING: lgth2=0 in partA__align\n" );
+
+       if( lgth1 == 0 && lgth2 == 0 )
+               return( 0.0 );
+
+       if( lgth1 == 0 )
+       {
+               for( i=0; i<icyc; i++ )
+               {
+                       j = lgth2;
+                       seq1[i][j] = 0;
+                       while( j ) seq1[i][--j] = '-';
+//                     fprintf( stderr, "seq1[i] = %s\n", seq1[i] );
+               }
+               return( 0.0 );
+       }
+
+       if( lgth2 == 0 )
+       {
+               for( i=0; i<jcyc; i++ )
+               {
+                       j = lgth1;
+                       seq2[i][j] = 0;
+                       while( j ) seq2[i][--j] = '-';
+//                     fprintf( stderr, "seq2[i] = %s\n", seq2[i] );
+               }
+               return( 0.0 );
+       }
+#endif
+
+#if 0
+       fprintf( stderr, "eff in SA+++align\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "eff1[%d] = %f\n", i, eff1[i] );
+#endif
+       if( orlgth1 == 0 )
+       {
+               mseq1 = AllocateCharMtx( njob, 0 );
+               mseq2 = AllocateCharMtx( njob, 0 );
+       }
+
+
+
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+                       FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+
+                       FreeCharMtx( mseq );
+
+                       FreeFloatVec( ogcp1 );
+                       FreeFloatVec( ogcp2 );
+                       FreeFloatVec( fgcp1 );
+                       FreeFloatVec( fgcp2 );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+               match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+
+               mseq = AllocateCharMtx( njob, ll1+ll2 );
+
+               ogcp1 = AllocateFloatVec( ll1+2 );
+               ogcp2 = AllocateFloatVec( ll2+2 );
+               fgcp1 = AllocateFloatVec( ll1+2 );
+               fgcp2 = AllocateFloatVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+#if FASTMATCHCALC
+               floatwork = AllocateFloatMtx( MAX( ll1, ll2 )+2, 26 ); 
+               intwork = AllocateIntMtx( MAX( ll1, ll2 )+2, 26 ); 
+#else
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+#endif
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+
+
+       for( i=0; i<icyc; i++ ) mseq1[i] = mseq[i];
+       for( j=0; j<jcyc; j++ ) mseq2[j] = mseq[icyc+j];
+
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijp = commonIP;
+
+       cpmx_calc_new( seq1, cpmx1, eff1, lgth1, icyc );
+       cpmx_calc_new( seq2, cpmx2, eff2, lgth2, jcyc );
+
+       if( sgap1 )
+       {
+               new_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1, sgap1 );
+               new_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2, sgap2 );
+               new_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1, egap1 );
+               new_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2, egap2 );
+       }
+       else
+       {
+               st_OpeningGapCount( ogcp1, icyc, seq1, eff1, lgth1 );
+               st_OpeningGapCount( ogcp2, jcyc, seq2, eff2, lgth2 );
+               st_FinalGapCount( fgcp1, icyc, seq1, eff1, lgth1 );
+               st_FinalGapCount( fgcp2, jcyc, seq2, eff2, lgth2 );
+       }
+
+       for( i=0; i<lgth1; i++ ) 
+       {
+               ogcp1[i] = 0.5 * ( 1.0 - ogcp1[i] ) * fpenalty;
+               fgcp1[i] = 0.5 * ( 1.0 - fgcp1[i] ) * fpenalty;
+       }
+       for( i=0; i<lgth2; i++ ) 
+       {
+               ogcp2[i] = 0.5 * ( 1.0 - ogcp2[i] ) * fpenalty;
+               fgcp2[i] = 0.5 * ( 1.0 - fgcp2[i] ) * fpenalty;
+       }
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       currentw = w1;
+       previousw = w2;
+
+
+       match_calc( initverticalw, cpmx2, cpmx1, 0, lgth1, floatwork, intwork, 1 );
+       if( localhom )
+               part_imp_match_out_vead_tate_gapmap( initverticalw, gapmap2[0]+start2, lgth1, start1, gapmap1 );
+
+
+       match_calc( currentw, cpmx1, cpmx2, 0, lgth2, floatwork, intwork, 1 );
+       if( localhom )
+               part_imp_match_out_vead_gapmap( currentw, gapmap1[0]+start1, lgth2, start2, gapmap2 );
+#if 0 // -> tbfast.c
+       if( localhom )
+               imp_match_calc( currentw, icyc, jcyc, lgth1, lgth2, seq1, seq2, eff1, eff2, localhom, 1, 0 );
+
+#endif
+
+       if( outgap == 1 )
+       {
+               for( i=1; i<lgth1+1; i++ )
+               {
+                       initverticalw[i] += ( ogcp1[0] + fgcp1[i-1] ) ;
+               }
+               for( j=1; j<lgth2+1; j++ )
+               {
+                       currentw[j] += ( ogcp2[0] + fgcp2[j-1] ) ;
+               }
+       }
+#if OUTGAP0TRY
+       else
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * j / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       initverticalw[i] -= offset * i / 2.0;
+       }
+#endif
+
+       for( j=1; j<lgth2+1; ++j ) 
+       {
+               m[j] = currentw[j-1] + ogcp1[1]; mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+       if( outgap ) lasti = lgth1+1; else lasti = lgth1;
+       lastj = lgth2+1;
+
+#if XXXXXXX
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "fcgp\n" );
+for( i=0; i<lgth1; i++ ) 
+       fprintf( stderr, "fgcp1[%d]=%f\n", i, ogcp1[i] );
+for( i=0; i<lgth2; i++ ) 
+       fprintf( stderr, "fgcp2[%d]=%f\n", i, ogcp2[i] );
+#endif
+
+       for( i=1; i<lasti; i++ )
+       {
+
+#ifdef enablemultithread
+//             fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+               if( chudanpt && *chudanpt != chudanref ) 
+               {
+//                     fprintf( stderr, "\n\n## CHUUDAN!!! i\n" );
+                       *chudanres = 1;
+                       return( -1.0 );
+               }
+#endif
+
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, cpmx1, cpmx2, i, lgth2, floatwork, intwork, 0 );
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               if( localhom )
+               {
+//                     fprintf( stderr, "Calling imp_match_calc (o) lgth = %d, i = %d\n", lgth1, i );
+//                     imp_match_out_vead( currentw, i, lgth2 );
+                       part_imp_match_out_vead_gapmap( currentw, gapmap1[i]+start1, lgth2, start2, gapmap2 );
+               }
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+
+               mi = previousw[0] + ogcp2[1]; mpi = 0;
+
+               ijppt = ijp[i] + 1;
+               mjpt = m + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               fgcp2pt = fgcp2;
+               ogcp2pt = ogcp2+1;
+               fgcp1va = fgcp1[i-1];
+               ogcp1va = ogcp1[i];
+               for( j=1; j<lastj; j++ )
+               {
+#ifdef xxxenablemultithread
+//                     fprintf( stderr, "chudan = %d, %d\n", *chudanpt, chudanref );
+                       if( chudanpt && *chudanpt != chudanref ) 
+                       {
+//                             fprintf( stderr, "\n\n## CHUUDAN!!! j\n" );
+                               *chudanres = 1;
+                               return( -1.0 );
+                       }
+#endif
+                       wm = *prept;
+                       *ijppt = 0;
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + *fgcp2pt;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = -( j - mpi );
+                       }
+                       g = *prept + *ogcp2pt;
+                       if( g >= mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+                       g = *mjpt + fgcp1va;
+#if 0 
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijppt = +( i - *mpjpt );
+                       }
+                       g = *prept + ogcp1va;
+                       if( g >= *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       m[j] += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f ", wm );
+#endif
+                       *curpt += wm;
+                       ijppt++;
+                       mjpt++;
+                       prept++;
+                       mpjpt++;
+                       curpt++;
+                       fgcp2pt++;
+                       ogcp2pt++;
+               }
+               lastverticalw[i] = currentw[lgth2-1];
+
+       }
+
+#if OUTGAP0TRY
+       if( !outgap )
+       {
+               for( j=1; j<lgth2+1; j++ )
+                       currentw[j] -= offset * ( lgth2 - j ) / 2.0;
+               for( i=1; i<lgth1+1; i++ )
+                       lastverticalw[i] -= offset * ( lgth1 - i  / 2.0);
+       }
+#endif
+               
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr,"%s\n", seq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr,"%s\n", seq2[j] );
+       fprintf( stderr, "====>" );
+       for( i=0; i<icyc; i++ ) strcpy( mseq1[i], seq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( mseq2[j], seq2[j] );
+       */
+       if( localhom )
+       {
+               Atracking_localhom( impmatch, currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc, start1, end1, start2, end2, gapmap1, gapmap2 );
+       }
+       else
+               Atracking( currentw, lastverticalw, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijp, icyc, jcyc );
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+       for( i=0; i<icyc; i++ ) strcpy( seq1[i], mseq1[i] );
+       for( j=0; j<jcyc; j++ ) strcpy( seq2[j], mseq2[j] );
+       /*
+       fprintf( stderr, "\n" );
+       for( i=0; i<icyc; i++ ) fprintf( stderr, "%s\n", mseq1[i] );
+       fprintf( stderr, "#####\n" );
+       for( j=0; j<jcyc; j++ ) fprintf( stderr, "%s\n", mseq2[j] );
+       */
+
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/regtable2seq.c b/binaries/src/mafft/core/regtable2seq.c
new file mode 100644 (file)
index 0000000..4251b3b
--- /dev/null
@@ -0,0 +1,212 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+char *regfile;
+char *eregfile;
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+    outnumber = 0;
+    inputfile = NULL;
+    regfile = NULL;
+    eregfile = NULL;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'e':
+                                       eregfile = *++argv;
+                                       fprintf( stderr, "eregfile = %s\n", eregfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'r':
+                                       regfile = *++argv;
+                                       fprintf( stderr, "regfile = %s\n", regfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'n' :
+                                       outnumber = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+void readereg( FILE *regfp, int **regtable, char **revtable, int *outtable, int *noutpt, int *loutpt )
+{
+       char gett[1000];
+       int j;
+       int mem;
+       char cmem;
+       char reg[5][100];
+       char out[100];
+       int startpos, endpos;
+
+       *noutpt = 0;
+       *loutpt = 0;
+       fgets( gett, 999, regfp );
+       sscanf( gett, "%c %s %s %s %s %s", &cmem, reg[0], reg[1], reg[2], reg[3], reg[4] );
+       if( cmem != 'e' )
+       {
+               fprintf( stderr, "Format error\n" );
+               exit( 1 );
+       }
+       for( j=0; j<5; j++ )
+       {
+               sscanf( reg[j], "%d-%d-%c", regtable[0]+(j*2), regtable[0]+(j*2)+1, revtable[0]+j );
+               fprintf( stderr, "%d %d-%d\n", 0, regtable[0][j*2], regtable[0][j*2+1] );
+               startpos = regtable[0][j*2];
+               endpos   = regtable[0][j*2+1];
+               if( startpos > endpos )
+               {
+                       endpos   = regtable[0][j*2];
+                       startpos = regtable[0][j*2+1];
+               }
+               if( startpos != -1 && endpos != -1 )
+                       *loutpt += endpos - startpos + 1;
+       }
+
+       while( 1 )
+       {
+               fgets( gett, 999, regfp );
+               if( feof( regfp ) ) break;
+               sscanf( gett, "%d o=%s", &mem, out );
+               if( mem >= njob )
+               {
+                       fprintf( stderr, "Out of range\n" );
+                       exit( 1 );
+               }
+               outtable[mem] = atoi( out );
+               if( outtable[mem] ) *noutpt += 1;
+       }
+}
+
+void readreg( FILE *regfp, int **regtable, char **revtable, int *outtable )
+{
+       char gett[1000];
+       int j;
+       int mem;
+       char reg[5][100];
+       char out[100];
+
+       while( 1 )
+       {
+               fgets( gett, 999, regfp );
+               if( feof( regfp ) ) break;
+               sscanf( gett, "%d %s %s %s %s %s o=%s", &mem, reg[0], reg[1], reg[2], reg[3], reg[4], out );
+               if( mem >= njob )
+               {
+                       fprintf( stderr, "Out of range\n" );
+                       exit( 1 );
+               }
+               for( j=0; j<5; j++ )
+               {
+                       sscanf( reg[j], "%d-%d-%c", regtable[mem]+(j*2), regtable[mem]+(j*2)+1, revtable[mem]+j );
+                       fprintf( stderr, "%d %d-%d\n", mem, regtable[mem][j*2], regtable[mem][j*2+1] );
+               }
+               outtable[mem] = atoi( out );
+       }
+}
+
+int main( int argc, char *argv[] )
+{
+       FILE *infp;
+       FILE *regfp;
+       int nlenmin;
+       int **regtable;
+       char **revtable;
+       int *outtable;
+       int i, nout, lout;
+       char **outseq;
+       char **name;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       dorp = NOTSPECIFIED;
+       getnumlen_nogap( infp, &nlenmin );
+
+       if( regfile )
+       {
+               regfp = fopen( regfile, "r" );
+               if( !regfp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", regfile );
+                       exit( 1 );
+               }
+               regtable = AllocateIntMtx( njob, 5*2 );
+               revtable = AllocateCharMtx( njob, 5 );
+               outtable = AllocateIntVec( njob );
+               readreg( regfp, regtable, revtable, outtable );
+               cutData( infp, regtable, revtable, outtable );
+       }
+       else if( eregfile )
+       {
+               regfp = fopen( eregfile, "r" );
+               if( !regfp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", eregfile );
+                       exit( 1 );
+               }
+               regtable = AllocateIntMtx( 1, 5*2 );
+               revtable = AllocateCharMtx( 1, 5 );
+               outtable = AllocateIntVec( njob );
+               readereg( regfp, regtable, revtable, outtable, &nout, &lout );
+               fprintf( stderr, "nout = %d, lout = %d\n", nout, lout );
+
+               outseq = AllocateCharMtx( nout, lout+1 );
+               name = AllocateCharMtx( nout, B );
+
+               cutAlignment( infp, regtable, revtable, outtable, name, outseq );
+               fprintf( stderr, "gappick! nout = %d\n", nout );
+               commongappick( nout, outseq );
+               for( i=0; i<nout; i++ )
+               {
+                       fprintf( stdout, "%s\n", name[i] );
+                       fprintf( stdout, "%s\n", outseq[i] );
+               }
+       }
+       else
+       {
+               catData( infp );
+       }
+
+       fprintf( stderr, "Strategy:\n" );
+       fprintf( stderr, " Not-Aligned\n" );
+
+//     fprintf( stdout, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp );
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/replaceu.c b/binaries/src/mafft/core/replaceu.c
new file mode 100644 (file)
index 0000000..40be746
--- /dev/null
@@ -0,0 +1,145 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+static int seedoffset;
+
+static void replace_unusual( int n, char **seq, char *usual, char unknown, int (*uporlow)( int ) )
+{
+       int i;
+       char *pt;
+       for( i=0; i<n; i++ )
+       {
+               pt = seq[i];
+               while( *pt )
+               {
+                       if( !strchr( usual, *pt ) ) *pt = unknown;
+                       else *pt = uporlow( *pt );
+                       pt++;
+               }
+       }
+}
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       seedoffset = 0;
+       inputfile = NULL;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'o':
+                                       seedoffset = atoi( *++argv );
+                                       fprintf( stderr, "seedoffset = %d\n", seedoffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+       FILE *infp;
+       int nlenmin;
+       char **name;
+       char **seq;
+       int *nlen;
+       int i;
+       char *usual;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+
+       dorp = NOTSPECIFIED;
+       getnumlen_casepreserve( infp, &nlenmin );
+
+       fprintf( stderr, "%d x %d - %d %c\n", njob, nlenmax, nlenmin, dorp );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       name = AllocateCharMtx( njob, B+1 );
+       nlen = AllocateIntVec( njob );
+
+       readData_pointer_casepreserve( infp, name, nlen, seq );
+
+//     for( i=0; i<njob; i++ ) gappick_samestring( seq[i] );
+
+#if 0
+       FILE *origfp;
+       origfp = fopen( "_original", "w" );
+       if( !origfp )
+       {
+               fprintf( stderr, "Cannot open _original\n" );
+               exit( 1 );
+       }
+       for( i=0; i<njob; i++ )
+       {
+               nlen[i] = strlen( seq[i] );
+               fprintf( origfp, ">%s\n", name[i]+1 );
+               if( seq[i][nlen[i]-1] == '\n' ) seq[i][nlen[i]-1] = 0;
+               fprintf( origfp, "%s\n", seq[i] );
+       }
+       fclose( origfp );
+#endif
+
+       if( dorp == 'p' )
+       {
+               usual = "ARNDCQEGHILKMFPSTWYVarndcqeghilkmfpstwyv-.";
+               replace_unusual( njob, seq, usual, 'X', toupper );
+       }
+       else
+       {
+               usual = "ATGCUatgcu-";
+               replace_unusual( njob, seq, usual, 'n', tolower );
+       }
+       
+
+
+       for( i=0; i<njob; i++ )
+       {
+               fprintf( stdout, ">%d_oripos_%s\n", i+seedoffset, name[i] );
+               fprintf( stdout, "%s\n", seq[i] );
+       }
+
+       free( nlen );
+       FreeCharMtx( seq );
+       FreeCharMtx( name );
+
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/restoreu.c b/binaries/src/mafft/core/restoreu.c
new file mode 100644 (file)
index 0000000..40055da
--- /dev/null
@@ -0,0 +1,229 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+char *alignmentfile;
+
+static void fillorichar( int nseq, int *oripos, char **a, char **s )
+{
+       int i;
+       char *pta, *pts;
+       for( i=0; i<nseq; i++ )
+       {
+               pta = a[i];
+               pts = s[oripos[i]];
+               while( *pta )
+               {
+                       if( *pta != '-' ) *pta = *pts++;
+                       if( *pta++ == 0 )
+                       {
+                               fprintf( stderr, "ERROR!!\n" );
+                               fprintf( stderr, "alignment is inconsistent with the original sequences\n" );
+                               exit( 1 );
+                       }
+               }
+               if( *pts != 0 )
+               {
+                       fprintf( stderr, "ERROR!!\n" );
+                       fprintf( stderr, "alignment is inconsistent with the original sequences\n" );
+                       exit( 1 );
+               }
+       }
+}
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       --argc;
+                                       goto nextoption;
+                               case 'a':
+                                       alignmentfile = *++argv;
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+
+int main( int argc, char *argv[] )
+{
+       FILE *infp;
+       FILE *alfp;
+       char **name;
+       char **aname;
+       char **oname;
+       char **seq;
+       char **aseq;
+       int *nlen;
+       int *oripos;
+       char *npt, *npt2;
+       int i, o, prelen;
+       int nlenmin;
+       int njobs, njoba;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       if( alignmentfile )
+       {
+               alfp = fopen( alignmentfile, "r" );
+               if( !alfp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", alignmentfile );
+                       exit( 1 );
+               }
+       }
+       else
+       {
+               fprintf( stderr, "No alignment is given.\n" );
+               exit( 1 );
+       }
+       
+       dorp = NOTSPECIFIED;
+       getnumlen_casepreserve( infp, &nlenmin );
+       njobs = njob;
+//     fprintf( stderr, "in infp, %d x %d - %d %c\n", njob, nlenmin, nlenmax, dorp );
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       name = AllocateCharMtx( njob, B+1 );
+       nlen = AllocateIntVec( njob );
+       oripos = AllocateIntVec( njob );
+       readData_pointer_casepreserve( infp, name, nlen, seq );
+
+       dorp = NOTSPECIFIED;
+       getnumlen( alfp );
+       njoba = njob;
+//     fprintf( stderr, "in alfp, %d x %d %c\n", njob, nlenmax, dorp );
+       aseq = AllocateCharMtx( njob, nlenmax+1 );
+       aname = AllocateCharMtx( njob, B+1 );
+       oname = AllocateCharMtx( njob, B+1 );
+       readData_pointer( alfp, aname, nlen, aseq );
+
+       for( i=0; i<njob; i++ ) gappick_samestring( seq[i] );
+
+       if( njoba != njobs )
+       {
+               fprintf( stderr, "ERROR!!\n" );
+               fprintf( stderr, "In input file,\n" );
+               fprintf( stderr, "njob = %d\n", njobs );
+               fprintf( stderr, "but in alignment file,\n" );
+               fprintf( stderr, "njob = %d\n", njoba );
+               exit( 1 );
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+#if 0
+               if( strstr( aname[i], "_seed_" ) )
+               {
+                       npt2 = aname[i] + 7;
+                       strcpy( oname[i], "=_seed_" );
+               }
+               else
+               {
+                       npt2 = aname[i] + 1;
+                       strcpy( oname[i], "=" );
+               }
+
+               fprintf( stderr, "npt2 = %s\n", npt2 );
+
+               o = oripos[i] = atoi( npt2 );
+               npt = strstr( npt2, "_oripos_" );
+               if( npt == NULL )
+               {
+                       fprintf( stderr, "Format error!\n" );
+                       exit( 1 );
+               }
+               npt += 8;
+               strcat( oname[i], npt+1 );
+#endif
+               npt = strstr( aname[i], "_oripos_" );
+               if( npt == NULL )
+               {
+                       fprintf( stderr, "Format error!\n" );
+                       exit( 1 );
+               }
+               npt2 = npt - 2;
+               while( isdigit( *npt2-- ) );
+               npt2 += 2;
+               npt += 8;
+               o = oripos[i] = atoi( npt2 );
+//             fprintf( stderr, "npt2 = :%s:\n", npt2 );
+//             fprintf( stderr, "npt = :%s:\n", npt );
+//             fprintf( stderr, "aname[i] = :%s:\n", aname[i] );
+//             fprintf( stderr, "npt2-aname[i] = :%d:\n", npt2-aname[i] );
+
+               prelen = npt2-aname[i];
+               strncpy( oname[i], aname[i], prelen ); oname[i][prelen] = 0;
+               strcat( oname[i], npt+1 );
+
+               if( strncmp( npt, name[o], 10 ) )
+               {
+                       fprintf( stderr, "ERROR!!\n" );
+                       fprintf( stderr, "In input file,\n" );
+                       fprintf( stderr, "name[%d] = %s\n", o, name[o] );
+                       fprintf( stderr, "but in alignment file,\n" );
+                       fprintf( stderr, "name[%d] = %s\n", i, aname[i] );
+                       exit( 1 );
+               }
+#if 0
+               else
+               {
+                       fprintf( stderr, "OK!!\n" );
+                       fprintf( stderr, "In input file,\n" );
+                       fprintf( stderr, "name[%d] = %s\n", o, name[o] );
+                       fprintf( stderr, "and in alignment file,\n" );
+                       fprintf( stderr, "name[%d] = %s\n", i, aname[i] );
+                       fprintf( stderr, "\n" );
+               }
+#endif
+       }
+//     fprintf( stderr, "seq[0] = %s\n", seq[0] );
+//     fprintf( stderr, "aseq[0] = %s\n", aseq[0] );
+
+       fillorichar( njob, oripos, aseq, seq );
+
+
+       writeData_pointer( stdout, njob, oname, nlen, aseq );
+
+       FreeCharMtx( seq );
+       FreeCharMtx( aseq );
+       FreeCharMtx( name );
+       FreeCharMtx( aname );
+       free( nlen );
+
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/rna.c b/binaries/src/mafft/core/rna.c
new file mode 100644 (file)
index 0000000..7a98058
--- /dev/null
@@ -0,0 +1,560 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define MEMSAVE 1
+
+#define DEBUG 1
+#define USE_PENALTY_EX  1
+#define STOREWM 1
+
+
+
+static float singleribosumscore( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2 )
+{
+       float val;
+       int i, j;
+       int code1, code2;
+
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               code1 = amino_n[(int)s1[i][p1]];
+               if( code1 > 3 ) code1 = 36;
+               code2 = amino_n[(int)s2[j][p2]];
+               if( code2 > 3 ) code2 = 36;
+
+//             fprintf( stderr, "'l'%c-%c: %f\n", s1[i][p1], s2[j][p2], (float)ribosumdis[code1][code2] );
+
+               val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j];
+       }
+       return( val );
+}
+static float pairedribosumscore53( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2, int c1, int c2 )
+{
+       float val;
+       int i, j;
+       int code1o, code1u, code2o, code2u, code1, code2;
+
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               code1o = amino_n[(int)s1[i][p1]];
+               code1u = amino_n[(int)s1[i][c1]];
+               if( code1o > 3 ) code1 = code1o = 36;
+               else if( code1u > 3 ) code1 = 36;
+               else code1 = 4 + code1o * 4 + code1u;
+
+               code2o = amino_n[(int)s2[j][p2]];
+               code2u = amino_n[(int)s2[j][c2]];
+               if( code2o > 3 ) code2 = code1o = 36;
+               else if( code2u > 3 ) code2 = 36;
+               else code2 = 4 + code2o * 4 + code2u;
+
+
+//             fprintf( stderr, "%c%c-%c%c: %f\n", s1[i][p1], s1[i][c1], s2[j][p2], s2[j][c2], (float)ribosumdis[code1][code2] );
+
+               if( code1 == 36 || code2 == 36 )
+                       val += (float)n_dis[code1o][code2o] * eff1[i] * eff2[j];
+               else
+                       val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j];
+       }
+       return( val );
+}
+
+static float pairedribosumscore35( int n1, int n2, char **s1, char **s2, double *eff1, double *eff2, int p1, int p2, int c1, int c2 )
+{
+       float val;
+       int i, j;
+       int code1o, code1u, code2o, code2u, code1, code2;
+
+       val = 0.0;
+       for( i=0; i<n1; i++ ) for( j=0; j<n2; j++ )
+       {
+               code1o = amino_n[(int)s1[i][p1]];
+               code1u = amino_n[(int)s1[i][c1]];
+               if( code1o > 3 ) code1 = code1o = 36;
+               else if( code1u > 3 ) code1 = 36;
+               else code1 = 4 + code1u * 4 + code1o;
+
+               code2o = amino_n[(int)s2[j][p2]];
+               code2u = amino_n[(int)s2[j][c2]];
+               if( code2o > 3 ) code2 = code1o = 36;
+               else if( code2u > 3 ) code2 = 36;
+               else code2 = 4 + code2u * 4 + code2o;
+
+
+//             fprintf( stderr, "%c%c-%c%c: %f\n", s1[i][p1], s1[i][c1], s2[j][p2], s2[j][c2], (float)ribosumdis[code1][code2] );
+
+               if( code1 == 36 || code2 == 36 )
+                       val += (float)n_dis[code1o][code2o] * eff1[i] * eff2[j];
+               else
+                       val += (float)ribosumdis[code1][code2] * eff1[i] * eff2[j];
+       }
+       return( val );
+}
+
+
+static void mccaskillextract( char **seq, char **nogap, int nseq, RNApair **pairprob, RNApair ***single, int **sgapmap, double *eff )
+{
+       int lgth;
+       int nogaplgth;
+       int i, j;
+       int left, right, adpos;
+       float prob;
+       static TLS int *pairnum;
+       RNApair *pt, *pt2;
+
+       lgth = strlen( seq[0] );
+       pairnum = calloc( lgth, sizeof( int ) );
+       for( i=0; i<lgth; i++ ) pairnum[i] = 0;
+
+       for( i=0; i<nseq; i++ )
+       {
+               nogaplgth = strlen( nogap[i] );
+               for( j=0; j<nogaplgth; j++ ) for( pt=single[i][j]; pt->bestpos!=-1; pt++ )
+               {
+                       left = sgapmap[i][j];
+                       right = sgapmap[i][pt->bestpos];
+                       prob = pt->bestscore;
+
+
+                       for( pt2=pairprob[left]; pt2->bestpos!=-1; pt2++ )
+                               if( pt2->bestpos == right ) break;
+
+//                     fprintf( stderr, "i,j=%d,%d, left=%d, right=%d, pt=%d, pt2->bestpos = %d\n", i, j, left, right, pt-single[i][j], pt2->bestpos );
+                       if( pt2->bestpos == -1 )
+                       {
+                               pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) );
+                               adpos = pairnum[left];
+                               pairnum[left]++;
+                               pairprob[left][adpos].bestscore = 0.0;
+                               pairprob[left][adpos].bestpos = right;
+                               pairprob[left][adpos+1].bestscore = -1.0;
+                               pairprob[left][adpos+1].bestpos = -1;
+                               pt2 = pairprob[left]+adpos;
+                       }
+                       else
+                               adpos = pt2-pairprob[left];
+
+                       pt2->bestscore += prob * eff[i];
+
+                       if( pt2->bestpos != right )
+                       {
+                               fprintf( stderr, "okashii!\n" );
+                               exit( 1 );
+                       }
+//                     fprintf( stderr, "adding %d-%d, %f\n", left, right, prob );
+//                     fprintf( stderr, "pairprob[0][0].bestpos=%d\n", pairprob[0][0].bestpos );
+//                     fprintf( stderr, "pairprob[0][0].bestscore=%f\n", pairprob[0][0].bestscore );
+               }
+       }
+
+//     fprintf( stderr, "before taikakuka\n" );
+       for( i=0; i<lgth; i++ ) for( j=0; j<pairnum[i]; j++ )
+       {
+               if( pairprob[i][j].bestpos > -1 )
+               {
+//                     pairprob[i][j].bestscore /= (float)nseq;
+//                     fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", i, pairprob[i][j].bestpos, pairprob[i][j].bestscore, seq[0][i], seq[0][pairprob[i][j].bestpos] );
+               }
+       }
+
+#if 0
+       for( i=0; i<lgth; i++ ) for( j=0; j<pairnum[i]; j++ )
+       {
+               right=pairprob[i][j].bestpos;
+               if( right < i ) continue;
+               fprintf( stderr, "no%d-%d, adding %d -> %d\n", i, j, right, i );
+               pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) );
+               pairprob[right][pairnum[right]].bestscore = pairprob[i][j].bestscore;
+               pairprob[right][pairnum[right]].bestpos = i;
+               pairnum[right]++;
+               pairprob[right][pairnum[right]].bestscore = -1.0;
+               pairprob[right][pairnum[right]].bestpos = -1;
+       }
+#endif
+
+       free( pairnum );
+
+}
+
+
+void rnaalifoldcall( char **seq, int nseq, RNApair **pairprob )
+{
+       int lgth;
+       int i;
+       static TLS int *order = NULL;
+       static TLS char **name = NULL;
+       char gett[1000];
+       FILE *fp;
+       int left, right, dumm;
+       float prob;
+       static TLS int pid;
+       static TLS char fnamein[100];
+       static TLS char cmd[1000];
+       static TLS int *pairnum;
+
+       lgth = strlen( seq[0] );
+       if( order == NULL )
+       {
+               pid = (int)getpid();
+               sprintf( fnamein, "/tmp/_rnaalifoldin.%d", pid );
+               order = AllocateIntVec( njob );
+               name = AllocateCharMtx( njob, 10 );
+               for( i=0; i<njob; i++ )
+               {
+                       order[i] = i;
+                       sprintf( name[i], "seq%d", i );
+               }
+       }
+       pairnum = calloc( lgth, sizeof( int ) );
+       for( i=0; i<lgth; i++ ) pairnum[i] = 0;
+
+       fp = fopen( fnamein, "w" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open /tmp/_rnaalifoldin\n" );
+               exit( 1 );
+       }
+       clustalout_pointer( fp, nseq, lgth, seq, name, NULL, NULL, order, 15 );
+       fclose( fp );
+
+       sprintf( cmd, "RNAalifold -p %s", fnamein );
+       system( cmd );
+
+       fp = fopen( "alifold.out", "r" );
+       if( !fp )
+       {
+               fprintf( stderr, "Cannot open /tmp/_rnaalifoldin\n" );
+               exit( 1 );
+       }
+
+#if 0
+       for( i=0; i<lgth; i++ ) // atode kesu
+       {
+               pairprob[i] = (RNApair *)realloc( pairprob[i], (2) * sizeof( RNApair ) ); // atode kesu
+               pairprob[i][1].bestscore = -1.0;
+               pairprob[i][1].bestpos = -1;
+       }
+#endif
+
+       while( 1 )
+       {
+               fgets( gett, 999, fp );
+               if( gett[0] == '(' ) break;
+               if( gett[0] == '{' ) break;
+               if( gett[0] == '.' ) break;
+               if( gett[0] == ',' ) break;
+               if( gett[0] != ' ' ) continue;
+
+               sscanf( gett, "%d %d %d %f", &left, &right, &dumm, &prob );
+               left--;
+               right--;
+
+
+#if 0
+               if( prob > 50.0 && prob > pairprob[left][0].bestscore )
+               {
+                       pairprob[left][0].bestscore = prob;
+                       pairprob[left][0].bestpos = right;
+#else
+               if( prob > 0.0 )
+               {
+                       pairprob[left] = (RNApair *)realloc( pairprob[left], (pairnum[left]+2) * sizeof( RNApair ) );
+                       pairprob[left][pairnum[left]].bestscore = prob / 100.0;
+                       pairprob[left][pairnum[left]].bestpos = right;
+                       pairnum[left]++;
+                       pairprob[left][pairnum[left]].bestscore = -1.0;
+                       pairprob[left][pairnum[left]].bestpos = -1;
+                       fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+
+                       pairprob[right] = (RNApair *)realloc( pairprob[right], (pairnum[right]+2) * sizeof( RNApair ) );
+                       pairprob[right][pairnum[right]].bestscore = prob / 100.0;
+                       pairprob[right][pairnum[right]].bestpos = left;
+                       pairnum[right]++;
+                       pairprob[right][pairnum[right]].bestscore = -1.0;
+                       pairprob[right][pairnum[right]].bestpos = -1;
+                       fprintf( stderr, "%d-%d, %f\n", left, right, prob );
+#endif
+               }
+       }
+       fclose( fp );
+       sprintf( cmd, "rm -f %s", fnamein );
+       system( cmd ); 
+
+       for( i=0; i<lgth; i++ )
+       {
+               if( (right=pairprob[i][0].bestpos) > -1 )
+               {
+                       pairprob[right][0].bestpos = i;
+                       pairprob[right][0].bestscore = pairprob[i][0].bestscore;
+               }
+       }
+
+#if 0
+       for( i=0; i<lgth; i++ ) // atode kesu
+               if( pairprob[i][0].bestscore > -1 ) pairprob[i][0].bestscore = 1.0; // atode kesu
+#endif
+
+//     fprintf( stderr, "after taikakuka in rnaalifoldcall\n" );
+//     for( i=0; i<lgth; i++ )
+//     {
+//             fprintf( stderr, "pair of %d = %d (%f) %c:%c\n", i, pairprob[i][0].bestpos, pairprob[i][0].bestscore, seq[0][i], seq[0][pairprob[i][0].bestpos] );
+//     }
+
+       free( pairnum );
+}
+
+
+static void utot( int n, int l, char **s )
+{
+       int i, j;
+       for( i=0; i<l; i++ )
+       {
+               for( j=0; j<n; j++ )
+               {
+                       if     ( s[j][i] == 'a' ) s[j][i] = 'a';
+                       else if( s[j][i] == 't' ) s[j][i] = 't';
+                       else if( s[j][i] == 'u' ) s[j][i] = 't';
+                       else if( s[j][i] == 'g' ) s[j][i] = 'g';
+                       else if( s[j][i] == 'c' ) s[j][i] = 'c';
+                       else if( s[j][i] == '-' ) s[j][i] = '-';
+                       else                                      s[j][i] = 'n';
+               }
+       }
+}
+
+
+void foldrna( int nseq1, int nseq2, char **seq1, char **seq2, double *eff1, double *eff2, RNApair ***grouprna1, RNApair ***grouprna2, float **impmtx, int *gapmap1, int *gapmap2, RNApair *additionalpair )
+{
+       int i, j;
+//     int ui, uj;
+//     int uiup, ujup;
+       int uido, ujdo;
+       static TLS char **useq1, **useq2;
+       static TLS char **oseq1, **oseq2, **oseq1r, **oseq2r, *odir1, *odir2;
+       static TLS RNApair **pairprob1, **pairprob2;
+       static TLS RNApair *pairpt1, *pairpt2;
+       int lgth1 = strlen( seq1[0] );
+       int lgth2 = strlen( seq2[0] );
+       static TLS float **impmtx2;
+       static TLS float **map;
+//     double lenfac;
+       float prob;
+       int **sgapmap1, **sgapmap2;
+       char *nogapdum;
+       float **tbppmtx;
+
+
+//     fprintf( stderr, "nseq1=%d, lgth1=%d\n", nseq1, lgth1 );
+       useq1 = AllocateCharMtx( nseq1, lgth1+10 );
+       useq2 = AllocateCharMtx( nseq2, lgth2+10 );
+       oseq1 = AllocateCharMtx( nseq1, lgth1+10 );
+       oseq2 = AllocateCharMtx( nseq2, lgth2+10 );
+       oseq1r = AllocateCharMtx( nseq1, lgth1+10 );
+       oseq2r = AllocateCharMtx( nseq2, lgth2+10 );
+       odir1 = AllocateCharVec( lgth1+10 );
+       odir2 = AllocateCharVec( lgth2+10 );
+       sgapmap1 = AllocateIntMtx( nseq1, lgth1+1 );
+       sgapmap2 = AllocateIntMtx( nseq2, lgth2+1 );
+       nogapdum = AllocateCharVec( MAX( lgth1, lgth2 ) );
+       pairprob1 = (RNApair **)calloc( lgth1, sizeof( RNApair *) );
+       pairprob2 = (RNApair **)calloc( lgth2, sizeof( RNApair *) );
+       map = AllocateFloatMtx( lgth1, lgth2 );
+       impmtx2 = AllocateFloatMtx( lgth1, lgth2 );
+       tbppmtx = AllocateFloatMtx( lgth1, lgth2 );
+
+       for( i=0; i<nseq1; i++ ) strcpy( useq1[i], seq1[i] );
+       for( i=0; i<nseq2; i++ ) strcpy( useq2[i], seq2[i] );
+       for( i=0; i<nseq1; i++ ) strcpy( oseq1[i], seq1[i] );
+       for( i=0; i<nseq2; i++ ) strcpy( oseq2[i], seq2[i] );
+
+       for( i=0; i<nseq1; i++ ) commongappick_record( 1, useq1+i, sgapmap1[i] );
+       for( i=0; i<nseq2; i++ ) commongappick_record( 1, useq2+i, sgapmap2[i] );
+
+       for( i=0; i<lgth1; i++ )
+       {
+               pairprob1[i] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+               pairprob1[i][0].bestpos = -1;
+               pairprob1[i][0].bestscore = -1;
+       }
+       for( i=0; i<lgth2; i++ )
+       {
+               pairprob2[i] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+               pairprob2[i][0].bestpos = -1;
+               pairprob2[i][0].bestscore = -1;
+       }
+
+       utot( nseq1, lgth1, oseq1 );
+       utot( nseq2, lgth2, oseq2 );
+
+//     fprintf( stderr, "folding group1\n" );
+//     rnalocal( oseq1, useq1, eff1, eff1, nseq1, nseq1, lgth1+10, pair1 );
+
+/* base-pairing probability of group 1 */
+       if( rnaprediction == 'r' )
+               rnaalifoldcall( oseq1, nseq1, pairprob1 );
+       else
+               mccaskillextract( oseq1, useq1, nseq1, pairprob1, grouprna1, sgapmap1, eff1 );
+
+
+//     fprintf( stderr, "folding group2\n" );
+//     rnalocal( oseq2, useq2, eff2, eff2, nseq2, nseq2, lgth2+10, pair2 );
+
+/* base-pairing probability of group 2 */
+       if( rnaprediction == 'r' )
+               rnaalifoldcall( oseq2, nseq2, pairprob2 );
+       else
+               mccaskillextract( oseq2, useq2, nseq2, pairprob2, grouprna2, sgapmap2, eff2 );
+
+
+
+#if 0
+       makerseq( oseq1, oseq1r, odir1, pairprob1, nseq1, lgth1 );
+       makerseq( oseq2, oseq2r, odir2, pairprob2, nseq2, lgth2 );
+
+       fprintf( stderr, "%s\n", odir2 );
+
+       for( i=0; i<nseq1; i++ )
+       {
+               fprintf( stdout, ">ori\n%s\n", oseq1[0] );
+               fprintf( stdout, ">rev\n%s\n", oseq1r[0] );
+       }
+#endif
+
+/* similarity score */
+       Lalignmm_hmout( oseq1, oseq2, eff1, eff2, nseq1, nseq2, 10000, NULL, NULL, NULL, NULL, map );
+
+       if( 1 )
+       {
+               if( RNAscoremtx == 'n' )
+               {
+                       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+                       {
+//                             impmtx2[i][j] = osoiaveragescore( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j ) * consweight_multi;
+                               impmtx2[i][j] = 0.0;
+                       }
+               }
+               else if( RNAscoremtx == 'r' )
+               {
+                       for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ ) 
+                       {
+                               tbppmtx[i][j] = 1.0;
+                               impmtx2[i][j] = 0.0;
+                       }
+                       for( i=0; i<lgth1; i++ ) for( pairpt1=pairprob1[i]; pairpt1->bestpos!=-1; pairpt1++ )
+                       {
+                               for( j=0; j<lgth2; j++ ) for( pairpt2=pairprob2[j]; pairpt2->bestpos!=-1; pairpt2++ )
+                               {
+                                       uido = pairpt1->bestpos;
+                                       ujdo = pairpt2->bestpos;
+                                       prob = pairpt1->bestscore * pairpt2->bestscore;
+                                       if( uido > -1  && ujdo > -1 )
+                                       {
+                                               if( uido > i && j > ujdo )
+                                               {
+                                                       impmtx2[i][j] += prob * pairedribosumscore53( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j, uido, ujdo ) * consweight_multi;
+                                                       tbppmtx[i][j] -= prob;
+                                               }
+                                               else if( i < uido && j < ujdo )
+                                               {
+                                                       impmtx2[i][j] += prob * pairedribosumscore35( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j, uido, ujdo ) * consweight_multi;
+                                                       tbppmtx[i][j] -= prob;
+                                               }
+                                       }
+                               }
+                       }
+       
+       
+                       for( i=0; i<lgth1; i++ )
+                       {
+                               for( j=0; j<lgth2; j++ )
+                               {
+                                       impmtx2[i][j] += tbppmtx[i][j] * singleribosumscore( nseq1, nseq2, oseq1, oseq2, eff1, eff2, i, j ) * consweight_multi;
+                               }
+                       }
+               }
+
+
+/* four-way consistency */
+
+               for( i=0; i<lgth1; i++ ) for( pairpt1=pairprob1[i]; pairpt1->bestpos!=-1; pairpt1++ )
+               {
+
+//                     if( pairprob1[i] == NULL ) continue;
+
+                       for( j=0; j<lgth2; j++ ) for( pairpt2=pairprob2[j]; pairpt2->bestpos!=-1; pairpt2++ )
+                       {
+//                             fprintf( stderr, "i=%d, j=%d, pn1=%d, pn2=%d\n", i, j, pairpt1-pairprob1[i], pairpt2-pairprob2[j] ); 
+//                             if( pairprob2[j] == NULL ) continue;
+
+                               uido = pairpt1->bestpos;
+                               ujdo = pairpt2->bestpos;
+                               prob = pairpt1->bestscore * pairpt2->bestscore;
+//                             prob = 1.0;
+//                             fprintf( stderr, "i=%d->uido=%d, j=%d->ujdo=%d\n", i, uido, j, ujdo );
+
+//                             fprintf( stderr, "impmtx2[%d][%d] = %f\n", i, j, impmtx2[i][j] );
+
+//                             if( i < uido && j > ujdo ) continue;
+//                             if( i > uido && j < ujdo ) continue;
+
+
+//                             posdistj = abs( ujdo-j );
+
+//                             if( uido > -1 && ujdo > -1 )  
+                               if( uido > -1 && ujdo > -1 && ( ( i > uido && j > ujdo ) || ( i < uido && j < ujdo ) ) )
+                               {
+                                       {
+                                               impmtx2[i][j] += MAX( 0, map[uido][ujdo] ) * consweight_rna * 600 * prob; // osoi
+                                       }
+                               }
+
+                       }
+               }
+               for( i=0; i<lgth1; i++ ) for( j=0; j<lgth2; j++ )
+               {
+                       impmtx[i][j] += impmtx2[i][j];
+//                     fprintf( stderr, "fastathreshold=%f, consweight_multi=%f, consweight_rna=%f\n", fastathreshold, consweight_multi, consweight_rna );
+//                     impmtx[i][j] *= 0.5;
+               }
+
+//             impmtx[0][0] += 10000.0;
+//             impmtx[lgth1-1][lgth2-1] += 10000.0;
+
+
+
+#if 0
+               fprintf( stdout, "#impmtx2 = \n" );
+               for( i=0; i<lgth1; i++ )
+               {
+                       for( j=0; j<lgth2; j++ )
+                       {
+                               fprintf( stdout, "%d %d %f\n", i, j, impmtx2[i][j] );
+                       }
+                       fprintf( stdout, "\n" );
+               }
+               exit( 1 );
+#endif
+       }
+
+       FreeCharMtx( useq1 );
+       FreeCharMtx( useq2 );
+       FreeCharMtx( oseq1 );
+       FreeCharMtx( oseq2 );
+       FreeCharMtx( oseq1r );
+       FreeCharMtx( oseq2r );
+       free( odir1 );
+       free( odir2 );
+       FreeFloatMtx( impmtx2 );
+       FreeFloatMtx( map );
+       FreeIntMtx( sgapmap1 );
+       FreeIntMtx( sgapmap2 );
+       FreeFloatMtx( tbppmtx );
+
+       for( i=0; i<lgth1; i++ ) free( pairprob1[i] );
+       for( i=0; i<lgth2; i++ ) free( pairprob2[i] );
+       free( pairprob1 );
+       free( pairprob2 );
+}
+
diff --git a/binaries/src/mafft/core/rnatest.c b/binaries/src/mafft/core/rnatest.c
new file mode 100644 (file)
index 0000000..c1f5ca2
--- /dev/null
@@ -0,0 +1,460 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       inputfile = NULL;
+       fftkeika = 0;
+       pslocal = -1000.0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       divpairscore = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_OP = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       ppenalty_EX = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'o':
+                                       RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'O':
+                                       ppenalty_OP = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'E':
+                                       ppenalty_EX = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+//                                     fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "TM %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       ppslocal = (int)( atof( *++argv ) * 1000 + 0.5 );
+                                       pslocal = (int)( 600.0 / 1000.0 * ppslocal + 0.5);
+//                                     fprintf( stderr, "ppslocal = %d\n", ppslocal );
+//                                     fprintf( stderr, "pslocal = %d\n", pslocal );
+                                       --argc;
+                                       goto nextoption;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+#if 0
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+#endif
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 's':
+                                       treemethod = 's';
+                                       break;
+                               case 'x':
+                                       disp = 1;
+                                       break;
+                               case 'p':
+                                       treemethod = 'p';
+                                       break;
+#if 0
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 'L':
+                                       alg = 'L';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'N':
+                                       alg = 'N';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'V':
+                                       alg = 'V';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       divpairscore = 1;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+int countamino( char *s, int end )
+{
+       int val = 0;
+       while( end-- )
+               if( *s++ != '-' ) val++;
+       return( val );
+}
+
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'x' )
+               fprintf( fp, "Tree = UPGMA (3).\n" );
+       else if( treemethod == 's' )
+               fprintf( fp, "Tree = UPGMA (2).\n" );
+       else if( treemethod == 'p' )
+               fprintf( fp, "Tree = UPGMA (1).\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  *nlen;      
+       static char **name, **seq, **useq;
+       static char **mseq1, **mseq2;
+       static char **aseq;
+       static char **bseq;
+       static double *eff;
+       int i;
+       FILE *infp;
+       char c;
+       int alloclen;
+       RNApair **pair1;
+       RNApair **pair2;
+       float **map;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob > M )
+       {
+               fprintf( stderr, "The number of sequences must be < %d\n", M );
+               fprintf( stderr, "Please try the splittbfast program for such large data.\n" );
+               exit( 1 );
+       }
+
+    name = AllocateCharMtx( njob, B+1 );
+    nlen = AllocateIntVec( njob ); 
+
+       seq = AllocateCharMtx( njob, nlenmax*5+1 );
+       useq = AllocateCharMtx( njob, nlenmax*5+1 );
+       aseq = AllocateCharMtx( njob, nlenmax*5+1 );
+       bseq = AllocateCharMtx( njob, nlenmax*5+1 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       alloclen = nlenmax*5;
+
+       pair1 = calloc( nlenmax*5+1, sizeof( RNApair *) );
+       pair2 = calloc( nlenmax*5+1, sizeof( RNApair *) );
+       map = AllocateFloatMtx( nlenmax+1, nlenmax );
+
+       eff = AllocateDoubleVec( njob );
+
+       readData_pointer( infp, name, nlen, seq );
+       fclose( infp );
+
+       for( i=0; i<njob; i++ ) strcpy( useq[i], seq[i] );
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       for( i=0; i<njob; i++ ) eff[i] = 1.0;
+
+//     for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+
+
+       fprintf( stderr, "folding group1\n" );
+//     rnalocal( seq, useq, eff, eff, njob, njob, alloclen, pair1 );
+       rnaalifoldcall( seq, njob, pair1 );
+       exit( 1 );
+
+#if 0
+       fprintf( stderr, "folding group1\n" );
+       rnalocal( seq+1, useq+1, eff+1, eff+1, 1, 1, alloclen, pair2 );
+       fprintf( stderr, "aligning 1 and 2, phase 1\n" );
+       Lalignmm_hmout( seq, seq+1, eff, eff+1, 1, 1, alloclen, NULL, NULL, NULL, NULL, map );
+
+
+#if 0
+       lgth1 = strlen( seq[0] );
+       for( i=0; i<lgth1; i++ )
+       {
+               fprintf( stderr, "\n" );
+               if( pair1[i].pos == -1 ) continue;
+               fprintf( stderr, "i=%d (%c):%d", i, seq[0][i], pair1[i].pos );
+               if( map12[pair1[i].pos].pos == -1 ) continue;
+               fprintf( stderr, "%c -> %c ", seq[0][pair1[i].pos], seq[1][map12[pair1[i].pos].pos] );
+               if( pair2[map12[pair1[i].pos].pos].pos == -1 ) continue;
+               fprintf( stderr, "%d:%d (%c)", map12[pair1[i].pos].pos, pair2[map12[pair1[i].pos].pos].pos, seq[1][pair2[map12[pair1[i].pos].pos].pos] );
+       }
+#endif
+
+
+       exit( 1 );
+
+
+       pairalign( name, nlen, bseq, aseq, mseq1, mseq2, eff, alloclen ); 
+       fprintf( trap_g, "done.\n" );
+#if DEBUG
+       fprintf( stderr, "closing trap_g\n" );
+#endif
+       fclose( trap_g );
+
+//     writePre( njob, name, nlen, aseq, !contin );
+#if 0
+       writeData( stdout, njob, name, nlen, aseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       SHOWVERSION;
+       return( 0 );
+#endif
+}
diff --git a/binaries/src/mafft/core/score.c b/binaries/src/mafft/core/score.c
new file mode 100644 (file)
index 0000000..1906cdb
--- /dev/null
@@ -0,0 +1,96 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       scoremtx = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'D':
+                                       scoremtx = -1;
+                                       break;
+                               case 'P':
+                                       scoremtx = 0;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+}
+
+
+int main( int ac, char **av )
+{
+       int nlen[M];
+       static char name[M][B], **seq;
+       double score;
+       extern double score_calc_for_score( int, char ** );
+
+       arguments( ac, av );
+
+       getnumlen( stdin );
+       rewind( stdin );
+
+       seq = AllocateCharMtx( njob, nlenmax );
+
+       readData( stdin, name, nlen, seq );
+
+       if( !isaligned( njob, seq ) ) ErrorExit( "Not aligned." );
+
+       constants( njob, seq );
+
+       score = score_calc_for_score( njob, seq );
+       if( scoremtx == 0 ) score += offset;
+
+       fprintf( stdout, "score = %f\n", score );
+       if     ( scoremtx ==  0 ) fprintf( stdout, "JTT %dPAM\n", pamN );
+       else if( scoremtx ==  1 ) fprintf( stdout, "Dayhoff( machigai ga aru )\n" );
+       else if( scoremtx ==  2 ) fprintf( stdout, "M-Y\n" );
+       else if( scoremtx == -1 ) fprintf( stdout, "DNA 1:%d\n", kimuraR );
+
+       fprintf( stdout, "gap penalty = %+6.2f, %+6.2f, %+6.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/seq2regtable.c b/binaries/src/mafft/core/seq2regtable.c
new file mode 100644 (file)
index 0000000..58b9cc8
--- /dev/null
@@ -0,0 +1,88 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+char *weboutfile = NULL;
+
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( (c = *++argv[0]) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'w':
+                                       weboutfile = *++argv;
+                                       fprintf( stderr, "weboutfile = %s\n", weboutfile );
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+}
+
+
+int main( int argc, char *argv[] )
+{
+       FILE *infp;
+       FILE *weboutfp;
+       int nlenmin;
+       int isaligned = 0;
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       if( weboutfile )
+       {
+               weboutfp = fopen( weboutfile, "w" );
+               if( !weboutfp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", weboutfile );
+                       exit( 1 );
+               }
+       }
+
+       dorp = NOTSPECIFIED;
+       if( weboutfile )
+       {
+               getnumlen_nogap_outallreg_web( infp, weboutfp, &nlenmin, &isaligned );
+               if( isaligned ) fprintf( stdout, "Aligned\n" );
+               else fprintf( stdout, "Not aligned\n" );
+       }
+       else
+               getnumlen_nogap_outallreg( infp, &nlenmin );
+
+       return( 0 );
+
+}
diff --git a/binaries/src/mafft/core/setcore.c b/binaries/src/mafft/core/setcore.c
new file mode 100644 (file)
index 0000000..baf1c7a
--- /dev/null
@@ -0,0 +1,503 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 1
+
+double corethr;
+int coreext;
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       fftkeika = 1;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'x';
+       contin = 0;
+       scoremtx = 0;
+       kobetsubunkatsu = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       corethr = .5;
+       coreext = 0;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       fastathreshold = atof( *++argv );
+                                       constraint = 2;
+                                       fprintf( stderr, "weighti = %f\n", fastathreshold );
+                                       --argc;
+                                       goto nextoption;
+                               case 'i':
+                                       corethr = atof( *++argv );
+                                       fprintf( stderr, "corethr = %f\n", corethr );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       fmodel = 1;
+                                       break;
+                               case 'c':
+                                       coreext = 1;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 's':
+                                       treemethod = 's';
+                                       break;
+                               case 'x':
+                                       treemethod = 'x';
+                                       break;
+                               case 'p':
+                                       treemethod = 'p';
+                                       break;
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'S':
+                                       alg = 'S';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+                               case 'o':
+                                       outgap = 0;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'x' )
+               fprintf( fp, "Tree = UPGMA (3).\n" );
+       else if( treemethod == 's' )
+               fprintf( fp, "Tree = UPGMA (2).\n" );
+       else if( treemethod == 'p' )
+               fprintf( fp, "Tree = UPGMA (1).\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  nlen[M];    
+       static char **name, **seq;
+       static char **oseq;
+       static double **pscore;
+       static double *eff;
+       static double **node0, **node1;
+       static double *gapc;
+       static double *avgap;
+       double tmpavgap;
+       int i, j, m, goffset;
+       static int ***topol;
+       static double **len;
+       FILE *prep;
+       char c;
+       int corestart, coreend;
+       int alloclen;
+       int winsize;
+       char *pt, *ot;
+       double gapmin;
+
+       arguments( argc, argv );
+
+       getnumlen( stdin );
+       rewind( stdin );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax*9+1 );
+       name = AllocateCharMtx( njob, B+1 );
+       oseq = AllocateCharMtx( njob, nlenmax*9+1 );
+       alloclen = nlenmax*9;
+
+       topol = AllocateIntCub( njob, 2, njob );
+       len = AllocateDoubleMtx( njob, 2 );
+       pscore = AllocateDoubleMtx( njob, njob );
+       eff = AllocateDoubleVec( njob );
+       node0 = AllocateDoubleMtx( njob, njob );
+       node1 = AllocateDoubleMtx( njob, njob );
+       gapc = AllocateDoubleVec( alloclen );
+       avgap = AllocateDoubleVec( alloclen );
+
+#if 0
+       Read( name, nlen, seq );
+#else
+       readData_pointer( stdin, name, nlen, seq );
+#endif
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+       writePre( njob, name, nlen, seq, 0 );
+
+       if( tbutree == 0 )
+       {
+               for( i=1; i<njob; i++ ) 
+               {
+                       if( nlen[i] != nlen[0] ) 
+                       {
+                               fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
+                               exit( 1 );
+                       }
+               }
+               for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+               {
+               /*
+                       pscore[i][j] = (double)score_calc1( seq[i], seq[j] );
+               */
+                       pscore[i][j] = (double)substitution_hosei( seq[i], seq[j] );
+               }
+       }
+       else
+       {
+               fprintf( stderr, "Loading 'hat2' ... " );
+               prep = fopen( "hat2", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat2." );
+               readhat2_pointer( prep, njob, name, pscore );
+               fclose( prep );
+               fprintf( stderr, "done.\n" );
+
+#if 0
+               prep = fopen( "hat2_check", "w" );
+               WriteHat2( prep, njob, name, pscore );
+               fclose( prep );
+#endif
+
+       }
+
+       fprintf( stderr, "Constructing dendrogram ... " );
+       if( treemethod == 'x' )
+               supg( njob, pscore, topol, len );
+       else if( treemethod == 's' )
+               spg( njob, pscore, topol, len );
+       else if( treemethod == 'p' )
+               upg2( njob, pscore, topol, len );
+       else 
+               ErrorExit( "Incorrect tree\n" );
+       fprintf( stderr, "done.\n" );
+
+       countnode( njob, topol, node0 );
+       if( tbrweight )
+       {
+               weight = 3; 
+#if 0
+               utree = 0; counteff( njob, topol, len, eff ); utree = 1;
+#else
+               counteff_simple( njob, topol, len, eff );
+#endif
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) eff[i] = 1.0;
+       }
+
+
+       for( i=0; i<nlenmax; i++ )
+       {
+               gapc[i] = 0.0;
+               for( j=0; j<njob; j++ )
+               {
+                       if( seq[j][i] == '-' ) gapc[i] += eff[j];
+               }
+       }
+
+       gapmin = 1.0;
+       winsize = fftWinSize;
+       goffset = winsize/2;
+       tmpavgap = 0.0;
+       corestart = coreend = -1;
+       for( i=0; i<winsize; i++ )
+       {
+               tmpavgap += gapc[i];
+       }
+       for( i=winsize; i<nlenmax; i++ )
+       {
+               m = i - goffset;
+               avgap[m] = tmpavgap / winsize;
+//             fprintf( stdout, "%d %f %f\n", m, avgap[m], gapc[i] );
+               if( avgap[m] < corethr )
+               {
+                       if( corestart == -1 )
+                               corestart = i - winsize;
+//                     fprintf( stdout, "ok, gapmin = %f, corestart = %d, coreend = %d\n", gapmin, corestart, coreend );
+                       if( avgap[m] < gapmin )
+                       { 
+                               gapmin = avgap[m];
+                       }
+                       coreend = i;
+               }
+               tmpavgap -= gapc[i-winsize];
+               tmpavgap += gapc[i];
+       }
+       if( corestart == -1 || coreend == -1 )
+       {
+               corestart = 0;
+               coreend = nlenmax-1;
+       }
+
+       for( i=0; i<njob; i++ )
+       {
+               pt = oseq[i];
+               m = winsize;
+               while( m-- ) *pt++ = '-';
+               for( j=corestart; j<=coreend; j++ )
+                       *pt++ = seq[i][j];
+               m = winsize;
+               while( m-- ) *pt++ = '-';
+               *pt = 0;
+
+               ot = oseq[i]+winsize-1;
+               pt = seq[i]+corestart-1;
+               if( coreext ) m = winsize;
+               else m = 0;
+               while( m && --pt > seq[i] )
+                       if( *pt != '-' )
+                       {
+                               *ot-- = *pt;
+                               m--;
+                       }
+
+               ot = oseq[i]+winsize+coreend-corestart+1;
+               pt = seq[i]+coreend;
+               if( coreext ) m = winsize;
+               else m = 0;
+               while( m && *(++pt) )
+               {
+                       if( *pt != '-' ) 
+                       {
+                               *ot++ = *pt;
+                               m--;
+                       }
+               }
+               fprintf( stdout, ">%s\n", name[i] );
+               fprintf( stdout, "%s\n", oseq[i] );
+       }
+
+       exit( 1 );
+
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/sextet5.c b/binaries/src/mafft/core/sextet5.c
new file mode 100644 (file)
index 0000000..1354b2c
--- /dev/null
@@ -0,0 +1,318 @@
+#include "mltaln.h"
+#include "mtxutl.h"
+
+#define DEBUG 0
+#define TEST  0
+
+#define END_OF_VEC -1
+
+static int maxl;
+static int tsize;
+
+void arguments( int argc, char *argv[] )
+{
+       int c;
+
+       inputfile = NULL;
+       disopt = 0;
+       scoremtx = 1;
+       nblosum = 62;
+       dorp = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'I':
+                                       disopt = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc != 0 )
+    {
+        fprintf( stderr, "options: -i\n" );
+        exit( 1 );
+    }
+}
+
+void seq_grp_nuc( int *grp, char *seq )
+{
+       int tmp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 4 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+}
+
+void seq_grp( int *grp, char *seq )
+{
+       int tmp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 6 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\n", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+}
+
+void makecompositiontable_p( short *table, int *pointt )
+{
+       int point;
+
+       while( ( point = *pointt++ ) != END_OF_VEC )
+               table[point]++;
+}
+
+int commonsextet_p( short *table, int *pointt )
+{
+       int value = 0;
+       short tmp;
+       int point;
+       static short *memo = NULL;
+       static int *ct = NULL;
+       static int *cp;
+
+       if( !memo )
+       {
+               memo = (short *)calloc( tsize, sizeof( short ) );
+               if( !memo ) ErrorExit( "Cannot allocate memo\n" );
+               ct = (int *)calloc( MIN( maxl, tsize)+1, sizeof( int ) );
+               if( !ct ) ErrorExit( "Cannot allocate memo\n" );
+       }
+
+       cp = ct;
+       while( ( point = *pointt++ ) != END_OF_VEC )
+       {
+               tmp = memo[point]++;
+               if( tmp < table[point] )
+                       value++;
+               if( tmp == 0 ) *cp++ = point;
+//             fprintf( stderr, "cp - ct = %d (tsize = %d)\n", cp - ct, tsize );
+       }
+       *cp = END_OF_VEC;
+       
+       cp =  ct;
+       while( *cp != END_OF_VEC )
+               memo[*cp++] = 0;
+
+       return( value );
+}
+
+void makepointtable_nuc( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       p = n;
+       point  = *n++ *  1024;
+       point += *n++ *   256;
+       point += *n++ *    64;
+       point += *n++ *    16;
+       point += *n++ *     4;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 1024;
+               point *= 4;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+void makepointtable( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       p = n;
+       point  = *n++ *  7776;
+       point += *n++ *  1296;
+       point += *n++ *   216;
+       point += *n++ *    36;
+       point += *n++ *     6;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 7776;
+               point *= 6;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+int main( int argc, char **argv )
+{
+       int i, j;
+       FILE *fp, *infp;
+       char **seq;
+       int *grpseq;
+       char *tmpseq;
+       int  **pointt;
+       static char name[M][B];
+       static int nlen[M];
+       double **mtx;
+       double **mtx2;
+       double score, score0;
+       static short *table1;
+       char b[B];
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+#if 0
+       PreRead( stdin, &njob, &nlenmax );
+#else
+       getnumlen( infp );
+#endif
+       rewind( infp );
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob );
+               exit( 1 );
+       }
+
+       tmpseq = AllocateCharVec( nlenmax+1 );
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       grpseq = AllocateIntVec( nlenmax+1 );
+       pointt = AllocateIntMtx( njob, nlenmax+1 );
+       mtx = AllocateDoubleMtx( njob, njob );
+       mtx2 = AllocateDoubleMtx( njob, njob );
+       pamN = NOTSPECIFIED;
+
+#if 0
+       FRead( infp, name, nlen, seq );
+#else
+       readData( infp, name, nlen, seq );
+#endif
+
+       fclose( infp );
+
+       constants( njob, seq );
+
+       if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
+       else              tsize = (int)pow( 6, 6 );
+
+       maxl = 0;
+       for( i=0; i<njob; i++ ) 
+       {
+               gappick0( tmpseq, seq[i] );
+               nlen[i] = strlen( tmpseq );
+               if( nlen[i] < 6 )
+               {
+                       fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
+                       exit( 1 );
+               }
+               if( nlen[i] > maxl ) maxl = nlen[i];
+               if( dorp == 'd' ) /* nuc */
+               {
+                       seq_grp_nuc( grpseq, tmpseq );
+                       makepointtable_nuc( pointt[i], grpseq );
+               }
+               else                 /* amino */
+               {
+                       seq_grp( grpseq, tmpseq );
+                       makepointtable( pointt[i], grpseq );
+               }
+       }
+       for( i=0; i<njob; i++ )
+       {
+               table1 = (short *)calloc( tsize, sizeof( short ) );
+               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+               if( i % 10 == 0 )
+               {
+                       fprintf( stderr, "%4d / %4d\r", i+1, njob );
+               }
+               makecompositiontable_p( table1, pointt[i] );
+
+               for( j=i; j<njob; j++ ) 
+               {
+                       score = (double)commonsextet_p( table1, pointt[j] );
+                       mtx[i][j] = score;
+               } 
+               free( table1 );
+       }
+       for( i=0; i<njob; i++ )
+       {
+               score0 = mtx[i][i];
+               for( j=0; j<njob; j++ ) 
+                       mtx2[i][j] = ( score0 - mtx[MIN(i,j)][MAX(i,j)] ) / score0 * 3.0;
+       }
+       for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
+       {
+#if TEST
+                double jscore;
+                jscore = mtx[i][j] / ( MIN( strlen( seq[i] ), strlen( seq[j] ) ) - 2 );
+                fprintf( stdout, "jscore = %f\n", jscore );
+
+               fprintf( stdout, "mtx2[%d][%d] = %f, mtx2[%d][%d] = %f\n", i, j, mtx2[i][j], j, i, mtx2[j][i] );
+#endif
+               mtx2[i][j] = MIN( mtx2[i][j], mtx2[j][i] );
+#if TEST
+               fprintf( stdout, "sonokekka mtx2[%d][%d] %f\n", i, j, mtx2[i][j] );
+#endif
+       }
+
+       if( disopt )
+       {
+               for( i=0; i<njob; i++ ) 
+               {
+                       sprintf( b, "=lgth = %04d", nlen[i] );
+                       strins( b, name[i] );
+               }
+       }
+               
+       fp = fopen( "hat2", "w" );
+       if( !fp ) ErrorExit( "Cannot open hat2." );
+       WriteHat2( fp, njob, name, mtx2 );
+       fclose( fp );
+
+       fprintf( stderr, "\n" );
+       SHOWVERSION;
+       exit( 0 );
+}
diff --git a/binaries/src/mafft/core/share.h b/binaries/src/mafft/core/share.h
new file mode 100644 (file)
index 0000000..ab9d277
--- /dev/null
@@ -0,0 +1,16 @@
+#if 0
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#endif
+#define IMA_YONDERU 'x'  /* iranai */
+#define IMA_KAITERU  0   /* iranai */
+#define KAKIOWATTA  'w'
+#define YOMIOWATTA  'r'
+#define OSHIMAI     'd'
+#define ISRUNNING    0
+#define SEMAPHORE    1
+#define STATUS       2
+
+#define IPC_ALLOC 0100000
diff --git a/binaries/src/mafft/core/splittbfast.c b/binaries/src/mafft/core/splittbfast.c
new file mode 100644 (file)
index 0000000..a810285
--- /dev/null
@@ -0,0 +1,3274 @@
+#include "mltaln.h"
+
+
+#define TREE 1
+#define PICKSIZE 50 // must be >= 3
+#define WEIGHT 0
+#define TOKYORIPARA 0.70 // 0.70
+#define TOKYORIPARA_A 0.70  // changed
+#define LENFAC 1
+#define HUKINTOTREE 1
+#define DIANA 0
+#define MAX6DIST 10.0
+
+// kouzoutai ni sasareru pointer ha static
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+#define END_OF_VEC -1
+
+static char *fastapath;
+static int doalign;
+static int fromaln;
+static int uselongest;
+static int treeout;
+static int classsize;
+static int picksize;
+static int maxl;
+static int tsize;
+static int reorder;
+static int pid;
+static int maxdepth = 0;
+static double tokyoripara;
+
+static double lenfaca, lenfacb, lenfacc, lenfacd;
+#define PLENFACA 0.01
+#define PLENFACB 10000
+#define PLENFACC 10000
+#define PLENFACD 0.1
+#define DLENFACA 0.01
+#define DLENFACB 2500
+#define DLENFACC 2500
+#define DLENFACD 0.1
+
+static char datafile[1000];
+static char queryfile[1000];
+static char resultfile[1000];
+
+typedef struct _scores
+{
+       double score;
+       int selfscore;
+       int orilen;
+       int *pointt;
+       int numinseq;
+       char *name;
+//     char *seq; // reallo
+//     char **seqpt;
+       int shimon;
+} Scores;
+
+int intcompare( const int *a, const int *b )
+{
+       return( *a - *b );
+}
+
+int lcompare( const Scores *a, const Scores *b )
+{
+       if( a->orilen < b->orilen ) return 1;
+       else if( a->orilen > b->orilen ) return -1;
+       else return 0;
+}
+
+int dcompare( const Scores *a, const Scores *b )
+{
+       if( a->score > b->score ) return 1;
+       else if( a->score < b->score ) return -1;
+       else
+       {
+               if( a->selfscore < b->selfscore ) return 1;
+               else if( a->selfscore > b->selfscore ) return -1;
+               else 
+               {
+                       if( a->orilen < b->orilen ) return 1;
+                       else if( a->orilen > b->orilen ) return -1;
+                       else return 0;
+               }
+       }
+}
+
+#if 0
+static void    gappickandx0( char *out, char *in )
+{
+       char c;
+       if( scoremtx == -1 )
+       {
+               while( *in )
+               {
+                       if( (c=*in++) == '-' )
+                               ;       
+                       else if( c == 'u' )
+                               *out++ = 't';
+                       else if( amino_n[c] < 4 && amino_n[c] > -1 )
+                               *out++ = c;
+                       else
+                               *out++ = 'n';
+               }
+       }
+       else
+       {
+               while( *in )
+               {
+                       if( (c=*in++) == '-' )
+                               ;       
+                       else if( amino_n[c] < 20 && amino_n[c] > -1 )
+                               *out++ = c;
+                       else
+                               *out++ = 'X';
+               }
+       }
+       *out = 0;
+}      
+
+static int getkouho( int *pickkouho, double prob, int nin, Scores *scores, char **seq ) // 0 < prob < 1
+{
+       int nkouho = 0;
+       int i, j;
+       int *iptr = pickkouho;
+       for( i=1; i<nin; i++ )
+       {
+               if( ( nkouho==0 || rnd() < prob ) && ( scores[i].shimon != scores->shimon || strcmp( seq[scores->numinseq], seq[scores[i].numinseq] ) ) )
+               {
+#if 0
+                       for( j=0; j<nkouho; j++ )
+                       {
+                               if( scores[i].shimon == scores[pickkouho[j]].shimon || !strcmp( seq[scores[pickkouho[j]].numinseq], seq[scores[i].numinseq] ) ) 
+                                       break;
+                       }
+                       if( j == nkouho )
+#endif
+                       {
+                               *iptr++ = i;
+                               nkouho++;
+//                             fprintf( stderr, "ok! nkouho=%d\n", nkouho );
+                       }
+               }
+               else
+               {
+                       ;
+//                     fprintf( stderr, "no! %d-%d\n", 0, scores[i].numinseq );
+               }
+       }
+       fprintf( stderr, "\ndone\n\n"  );
+       return nkouho;
+}
+
+#endif
+
+static void getfastascoremtx( int **tmpaminodis )
+{
+       FILE *qfp;
+       FILE *dfp;
+       FILE *rfp;
+       int i, j;
+       char aa;
+       int slen;
+       int res;
+       char com[10000];
+       static char *tmpseq;
+       static char *tmpname;
+       double *resvec;
+
+       if( scoremtx == -1 )
+       {
+               tmpaminodis['a']['a'] = 5;
+               tmpaminodis['g']['g'] = 5;
+               tmpaminodis['c']['c'] = 5;
+               tmpaminodis['t']['t'] = 5;
+               tmpaminodis['n']['n'] = -1;
+
+               return;
+       }
+
+
+       tmpseq = calloc( 2000, sizeof( char ) );
+       tmpname = calloc( B, sizeof( char ) );
+       resvec = calloc( 1, sizeof( double ) );
+
+//     fprintf( stderr, "xformatting .. " );
+       dfp = fopen( datafile, "w" );
+       if( !dfp ) ErrorExit( "Cannot open datafile." );
+       sprintf( tmpname, ">+===========+%d                      ", 0 );
+       strcpy( tmpseq, "AAAAAAXXXXXX" );
+       strcat( tmpseq, "CCCCCCXXXXXX" );
+       strcat( tmpseq, "DDDDDDXXXXXX" );
+       strcat( tmpseq, "EEEEEEXXXXXX" );
+       strcat( tmpseq, "FFFFFFXXXXXX" );
+       strcat( tmpseq, "GGGGGGXXXXXX" );
+       strcat( tmpseq, "HHHHHHXXXXXX" );
+       strcat( tmpseq, "IIIIIIXXXXXX" );
+       strcat( tmpseq, "KKKKKKXXXXXX" );
+       strcat( tmpseq, "LLLLLLXXXXXX" );
+       strcat( tmpseq, "MMMMMMXXXXXX" );
+       strcat( tmpseq, "NNNNNNXXXXXX" );
+       strcat( tmpseq, "PPPPPPXXXXXX" );
+       strcat( tmpseq, "QQQQQQXXXXXX" );
+       strcat( tmpseq, "RRRRRRXXXXXX" );
+       strcat( tmpseq, "SSSSSSXXXXXX" );
+       strcat( tmpseq, "TTTTTTXXXXXX" );
+       strcat( tmpseq, "VVVVVVXXXXXX" );
+       strcat( tmpseq, "WWWWWWXXXXXX" );
+       strcat( tmpseq, "YYYYYYXXXXXX" );
+       slen = strlen( tmpseq );
+       writeData_pointer( dfp, 1, &tmpname, &slen, &tmpseq );
+       fclose( dfp );
+       fprintf( stderr, "done.\n" );
+
+       for( i=0; i<20; i++ )
+       {
+               aa = amino[i];
+//             fprintf( stderr, "checking %c\n", aa );
+               *tmpseq = 0;
+               sprintf( tmpname, ">+===========+%d                      ", 0 );
+               for( j=0; j<6; j++ )
+                       sprintf( tmpseq+strlen( tmpseq ), "%c", aa );
+               qfp = fopen( queryfile, "w" );
+               if( !qfp ) ErrorExit( "Cannot open queryfile." );
+               writeData_pointer( qfp, 1, &tmpname, &slen, &tmpseq );
+               fclose( qfp );
+
+               if( scoremtx == -1 ) 
+                       sprintf( com, "%s -z3 -m10  -n -Q -H -b%d -E%d -d%d %s %s %d > %s", fastapath,  M, M, 0, queryfile, datafile, 6, resultfile );
+               else
+                       sprintf( com, "%s -z3 -m10  -p -Q -H -b%d -E%d -d%d %s %s %d > %s", fastapath,  M, M, 0, queryfile, datafile, 2, resultfile );
+               res = system( com );
+               if( res )
+               {
+                       fprintf( stderr, "error in %s", fastapath );
+                       exit( 1 );
+               }
+
+               rfp = fopen( resultfile, "r" );
+               if( rfp == NULL )  
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               res = ReadFasta34m10_scoreonly( rfp, resvec, 1 );
+               fprintf( stderr, "%c: %f\n", 'A'+i, *resvec/6 );
+               fclose( rfp );
+               if( ( (int)*resvec % 6 ) > 0.0 )
+               {
+                       fprintf( stderr, "Error in blast, *resvec=%f\n", *resvec );
+                       fprintf( stderr, "Error in blast, *resvec/6=%f\n", *resvec/6 );
+                       exit( 1 );
+               }
+               tmpaminodis[(int)aa][(int)aa] = (int)( *resvec / 6 );
+//             fprintf( stderr, "*resvec=%f, tmpaminodis[aa][aa] = %d\n", *resvec, tmpaminodis[aa][aa] );
+       }
+       tmpaminodis['X']['X'] = -1;
+       free( tmpname );
+       free( tmpseq );
+       free( resvec );
+}
+
+#if 0
+static void getblastscoremtx( int **tmpaminodis )
+{
+       FILE *qfp;
+       FILE *dfp;
+       FILE *rfp;
+       int i, j;
+       char aa;
+       int slen;
+       int res;
+       char com[10000];
+       static char *tmpseq;
+       static char *tmpname;
+       double *resvec;
+
+       if( scoremtx == -1 )
+       {
+               tmpaminodis['a']['a'] = 1;
+               tmpaminodis['g']['g'] = 1;
+               tmpaminodis['c']['c'] = 1;
+               tmpaminodis['t']['t'] = 1;
+
+               return;
+       }
+
+
+       tmpseq = calloc( 2000, sizeof( char ) );
+       tmpname = calloc( B, sizeof( char ) );
+       resvec = calloc( 1, sizeof( double ) );
+
+//     fprintf( stderr, "xformatting .. " );
+       dfp = fopen( datafile, "w" );
+       if( !dfp ) ErrorExit( "Cannot open datafile." );
+       sprintf( tmpname, "\0", i ); // BUG!!
+       strcpy( tmpseq, "AAAAAAXXXXXX" );
+       strcat( tmpseq, "CCCCCCXXXXXX" );
+       strcat( tmpseq, "DDDDDDXXXXXX" );
+       strcat( tmpseq, "EEEEEEXXXXXX" );
+       strcat( tmpseq, "FFFFFFXXXXXX" );
+       strcat( tmpseq, "GGGGGGXXXXXX" );
+       strcat( tmpseq, "HHHHHHXXXXXX" );
+       strcat( tmpseq, "IIIIIIXXXXXX" );
+       strcat( tmpseq, "KKKKKKXXXXXX" );
+       strcat( tmpseq, "LLLLLLXXXXXX" );
+       strcat( tmpseq, "MMMMMMXXXXXX" );
+       strcat( tmpseq, "NNNNNNXXXXXX" );
+       strcat( tmpseq, "PPPPPPXXXXXX" );
+       strcat( tmpseq, "QQQQQQXXXXXX" );
+       strcat( tmpseq, "RRRRRRXXXXXX" );
+       strcat( tmpseq, "SSSSSSXXXXXX" );
+       strcat( tmpseq, "TTTTTTXXXXXX" );
+       strcat( tmpseq, "VVVVVVXXXXXX" );
+       strcat( tmpseq, "WWWWWWXXXXXX" );
+       strcat( tmpseq, "YYYYYYXXXXXX" );
+       slen = strlen( tmpseq );
+       writeData_pointer( dfp, 1, &tmpname, &slen, &tmpseq );
+       fclose( dfp );
+       if( scoremtx == -1 )
+               sprintf( com, "formatdb  -p f -i %s -o F", datafile );
+       else
+               sprintf( com, "formatdb  -i %s -o F", datafile );
+       system( com );
+       fprintf( stderr, "done.\n" );
+
+       for( i=0; i<20; i++ )
+       {
+               aa = amino[i];
+               fprintf( stderr, "checking %c\n", aa );
+               *tmpseq = 0;
+               for( j=0; j<6; j++ )
+                       sprintf( tmpseq+strlen( tmpseq ), "%c", aa );
+               qfp = fopen( queryfile, "w" );
+               if( !qfp ) ErrorExit( "Cannot open queryfile." );
+               writeData_pointer( qfp, 1, &tmpname, &slen, &tmpseq );
+               fclose( qfp );
+
+               sprintf( com, "blastall -b %d -G 10 -E 1 -e 1e10 -p blastp -m 7  -i %s -d %s >  %s\0", 1, queryfile, datafile, resultfile );
+               res = system( com );
+               if( res )
+               {
+                       fprintf( stderr, "error in %s", "blastall" );
+                       exit( 1 );
+               }
+
+               rfp = fopen( resultfile, "r" );
+               if( rfp == NULL )  
+                       ErrorExit( "file 'fasta.$$' does not exist\n" );
+               res = ReadBlastm7_scoreonly( rfp, resvec, 1 );
+               fprintf( stdout, "%c: %f\n", 'A'+i, *resvec/6 );
+               fclose( rfp );
+               if( ( (int)*resvec % 6 ) > 0.0 )
+               {
+                       fprintf( stderr, "Error in blast, *resvec=%f\n", *resvec );
+                       fprintf( stderr, "Error in blast, *resvec/6=%f\n", *resvec/6 );
+                       exit( 1 );
+               }
+               tmpaminodis[aa][aa] = (int)( *resvec / 6 );
+       }
+       tmpaminodis['X']['X'] = 0;
+       free( tmpname );
+       free( tmpseq );
+       free( resvec );
+       
+}
+#endif
+
+static double *callfasta( char **seq, Scores *scores, int nin, int *picks, int query, int rewritedata )
+{
+       double *val;
+       FILE *qfp;
+       FILE *dfp;
+       FILE *rfp;
+       int i;
+       char com[10000];
+       static char datafile[1000];
+       static char queryfile[1000];
+       static char resultfile[1000];
+       static int pid;
+       static char *tmpseq;
+       static char *tmpname;
+       int slen;
+       int res;
+       static Scores *scoresbk = NULL;
+       static int ninbk = 0;
+
+       if( pid == 0 )
+       {
+               pid = (int)getpid();
+               sprintf( datafile, "/tmp/data-%d", pid );
+               sprintf( queryfile, "/tmp/query-%d", pid );
+               sprintf( resultfile, "/tmp/fasta-%d", pid );
+
+               tmpseq = calloc( nlenmax+1, sizeof( char ) );
+               tmpname = calloc( B+1, sizeof( char ) );
+       }
+
+       val = calloc( nin, sizeof( double ) );
+//     fprintf( stderr, "nin=%d, q=%d\n", nin, query );
+
+       if( rewritedata )
+       {
+               scoresbk = scores;
+               ninbk = nin;
+//             fprintf( stderr, "\nformatting .. " );
+               dfp = fopen( datafile, "w" );
+               if( !dfp ) ErrorExit( "Cannot open datafile." );
+               if( picks == NULL ) for( i=0; i<nin; i++ )
+               {
+//                     fprintf( stderr, "i=%d / %d / %d\n", i,  nin, njob );
+//                     fprintf( stderr, "nlenmax = %d\n", nlenmax );
+//                     fprintf( stderr, "scores[i].orilen = %d\n", scores[i].orilen );
+//                     fprintf( stderr, "strlen( seq[scores[i].numinseq] = %d\n", strlen( seq[scores[i].numinseq] ) );
+                       gappick0( tmpseq, seq[scores[i].numinseq] );
+                       sprintf( tmpname, ">+===========+%d                      ", i );
+                       slen = scores[i].orilen;
+                       writeData_pointer( dfp, 1, &tmpname, &slen, &tmpseq );
+               }
+               else for( i=0; i<nin; i++ )
+               {
+                       gappick0( tmpseq, seq[scores[picks[i]].numinseq] );
+                       sprintf( tmpname, ">+===========+%d                      ", i );
+                       slen = scores[picks[i]].orilen;
+                       writeData_pointer( dfp, 1, &tmpname, &slen, &tmpseq );
+               }
+               fclose( dfp );
+       }
+
+
+       gappick0( tmpseq, seq[scores[query].numinseq] );
+       sprintf( tmpname, ">+==========+%d                      ", 0 );
+       slen = scores[query].orilen;
+       qfp = fopen( queryfile, "w" );
+       if( !qfp ) ErrorExit( "Cannot open queryfile." );
+       writeData_pointer( qfp, 1, &tmpname, &slen, &tmpseq );
+       fclose( qfp );
+
+//     fprintf( stderr, "calling fasta, nin=%d\n", nin );
+
+       if( scoremtx == -1 ) 
+               sprintf( com, "%s  -z3 -m10  -n -Q -H -b%d -E%d -d%d %s %s %d > %s",  fastapath, nin, nin, 0, queryfile, datafile, 6, resultfile );
+       else
+               sprintf( com, "%s  -z3 -m10  -p -Q -H -b%d -E%d -d%d %s %s %d > %s",  fastapath, nin, nin, 0, queryfile, datafile, 2, resultfile );
+       res = system( com );
+       if( res )
+       {
+               fprintf( stderr, "error in %s", fastapath );
+               exit( 1 );
+       }
+//     fprintf( stderr, "fasta done\n" );
+
+//exit( 1 );
+
+       rfp = fopen( resultfile, "r" );
+       if( rfp == NULL )  
+               ErrorExit( "file 'fasta.$$' does not exist\n" );
+
+//     fprintf( stderr, "reading fasta\n" );
+       if( scoremtx == -1 ) 
+               res = ReadFasta34m10_scoreonly_nuc( rfp, val, nin );
+       else
+               res = ReadFasta34m10_scoreonly( rfp, val, nin );
+//     fprintf( stderr, "done. val[0] = %f\n", val[0] );
+
+
+       fclose( rfp );
+
+#if 0
+       for( i=0; i<nin; i++ )
+               fprintf( stderr, "r[%d-%d] = %f\n", 0, i, val[i] );
+       exit( 1 );
+#endif
+
+       return( val );
+}
+#if 0
+static double *callblast( char **seq, Scores *scores, int nin, int query, int rewritedata )
+{
+       double *val;
+       FILE *qfp;
+       FILE *dfp;
+       FILE *rfp;
+       int i, j;
+       char com[10000];
+       static char datafile[1000];
+       static char queryfile[1000];
+       static char resultfile[1000];
+       static int pid;
+       static char *tmpseq;
+       static char *tmpname;
+       char *seqptr;
+       int slen;
+       int res;
+       static Scores *scoresbk = NULL;
+       static int ninbk = 0;
+
+       if( pid == 0 )
+       {
+               pid = (int)getpid();
+               sprintf( datafile, "/tmp/data-%d\0", pid );
+               sprintf( queryfile, "/tmp/query-%d\0", pid );
+               sprintf( resultfile, "/tmp/fasta-%d\0", pid );
+
+               tmpseq = calloc( nlenmax+1, sizeof( char ) );
+               tmpname = calloc( B+1, sizeof( char ) );
+       }
+
+       val = calloc( nin, sizeof( double ) );
+//     fprintf( stderr, "nin=%d, q=%d\n", nin, query );
+
+       if( rewritedata )
+       {
+               scoresbk = scores;
+               ninbk = nin;
+               fprintf( stderr, "\nformatting .. " );
+               dfp = fopen( datafile, "w" );
+               if( !dfp ) ErrorExit( "Cannot open datafile." );
+               for( i=0; i<nin; i++ )
+               {
+//                     fprintf( stderr, "i=%d / %d / %d\n", i,  nin, njob );
+//                     fprintf( stderr, "nlenmax = %d\n", nlenmax );
+//                     fprintf( stderr, "scores[i].orilen = %d\n", scores[i].orilen );
+//                     fprintf( stderr, "strlen( seq[scores[i].numinseq] = %d\n", strlen( seq[scores[i].numinseq] ) );
+                       gappick0( tmpseq, seq[scores[i].numinseq] );
+                       sprintf( tmpname, "+===========+%d                      \0", i );
+                       slen = scores[i].orilen;
+                       writeData_pointer( dfp, 1, &tmpname, &slen, &tmpseq );
+               }
+               fclose( dfp );
+                       
+               if( scoremtx == -1 )
+                       sprintf( com, "formatdb  -p f -i %s -o F", datafile );
+               else
+                       sprintf( com, "formatdb  -i %s -o F", datafile );
+               system( com );
+//             fprintf( stderr, "done.\n" );
+       }
+
+
+       gappick0( tmpseq, seq[scores[query].numinseq] );
+       sprintf( tmpname, "+==========+%d                      \0", 0 );
+       slen = scores[query].orilen;
+       qfp = fopen( queryfile, "w" );
+       if( !qfp ) ErrorExit( "Cannot open queryfile." );
+       writeData_pointer( qfp, 1, &tmpname, &slen, &tmpseq );
+       fclose( qfp );
+//     fprintf( stderr, "q=%s\n", tmpseq );
+
+       fprintf( stderr, "\ncalling blast .. \n" );
+       if( scoremtx == -1 ) 
+               sprintf( com, "blastall -b %d -e 1e10 -p blastn -m 7  -i %s -d %s >  %s\0", nin, queryfile, datafile, resultfile );
+       else
+               sprintf( com, "blastall -b %d -G 10 -E 1 -e 1e10 -p blastp -m 7  -i %s -d %s >  %s\0", nin, queryfile, datafile, resultfile );
+       res = system( com );
+       if( res ) ErrorExit( "error in blast" );
+
+       rfp = fopen( resultfile, "r" );
+       if( rfp == NULL )  
+               ErrorExit( "file 'fasta.$$' does not exist\n" );
+       res = ReadBlastm7_scoreonly( rfp, val, nin );
+       fclose( rfp );
+
+#if 0
+       for( i=0; i<nin; i++ )
+               fprintf( stderr, "r[%d-%d] = %f\n", 0, i, val[i] );
+#endif
+
+       return( val );
+}
+#endif
+
+#if 0
+static void selhead( int *ar, int n )
+{
+       int min = *ar;
+       int *minptr = ar;
+       int *ptr = ar;
+       int tmp;
+       n--;
+       ar++;
+       while( n-- )
+       {
+               if( ( tmp = *ptr++ ) < min )
+               {
+                       min = tmp;
+                       minptr = ptr;
+               }
+       }
+       if( minptr != ar )
+       {
+               tmp = *ar;
+               *ar = min;
+               *minptr = tmp;
+       }
+       return;
+}
+#endif
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       doalign = 0;
+       fromaln = 0;
+       treeout = 0;
+       uselongest = 1;
+       reorder = 1;
+       nevermemsave = 0;
+       inputfile = NULL;
+       fftkeika = 0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0;
+       force_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'X';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = -1530;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = -123;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       TMorJTT = JTT;
+       classsize = NOTSPECIFIED;
+       picksize = NOTSPECIFIED;
+       tokyoripara = NOTSPECIFIED;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'p':
+                                       picksize = atoi( *++argv );
+                                       fprintf( stderr, "picksize = %d\n", picksize );
+                                       --argc;
+                                       goto nextoption;
+                               case 's':
+                                       classsize = atoi( *++argv );
+                                       fprintf( stderr, "groupsize = %d\n", classsize );
+                                       --argc;
+                                       goto nextoption;
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kimuraR = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+//                                     fprintf( stderr, "blosum %d\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "tm %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'T':
+                                       tokyoripara = (double)atof( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       uselongest = 0;
+                                       break;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'S':
+                                       doalign = 'f';
+                                       break;
+                               case 'Z':
+                                       fromaln = 1;
+                                       break;
+                               case 'L':
+                                       doalign = 1;
+                                       break;
+                               case 'x':
+                                       reorder = 0;
+                                       break;
+                               case 't':
+                                       treeout = 1;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#if 0
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+                               case 'Q':
+                                       calledByXced = 1;
+                                       break;
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'R':
+                                       alg = 'R';
+                                       break;
+                               case 'Q':
+                                       alg = 'Q';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'N':
+                                       nevermemsave = 1;
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'C':
+                                       alg = 'C';
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'G':
+                                       use_fft = 1;
+                                       force_fft = 1;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+                               case 'o':
+                                       outgap = 0;
+                                       break;
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+                               case 'X':
+                                       treemethod = 'X'; // mix
+                                       break;
+                               case 'E':
+                                       treemethod = 'E'; // upg (average)
+                                       break;
+                               case 'q':
+                                       treemethod = 'q'; // minimum
+                                       break;
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+static int maxl;
+static int tsize;
+
+int seq_grp_nuc( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 4 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       return( grp-grpbk );
+}
+
+int seq_grp( int *grp, char *seq )
+{
+       int tmp;
+       int *grpbk = grp;
+       while( *seq )
+       {
+               tmp = amino_grp[(int)*seq++];
+               if( tmp < 6 )
+                       *grp++ = tmp;
+               else
+                       fprintf( stderr, "WARNING : Unknown character %c\r", *(seq-1) );
+       }
+       *grp = END_OF_VEC;
+       return( grp-grpbk );
+}
+
+void makecompositiontable_p( short *table, int *pointt )
+{
+       int point;
+
+       while( ( point = *pointt++ ) != END_OF_VEC )
+               table[point]++;
+}
+
+int commonsextet_p( short *table, int *pointt )
+{
+       int value = 0;
+       short tmp;
+       int point;
+       static short *memo = NULL;
+       static int *ct = NULL;
+       static int *cp;
+
+       if( !memo )
+       {
+               memo = (short *)calloc( tsize, sizeof( short ) );
+               if( !memo ) ErrorExit( "Cannot allocate memo\n" );
+               ct = (int *)calloc( MIN( maxl, tsize )+1, sizeof( int ) );
+               if( !ct ) ErrorExit( "Cannot allocate memo\n" );
+       }
+
+       cp = ct;
+       while( ( point = *pointt++ ) != END_OF_VEC )
+       {
+               tmp = memo[point]++;
+               if( tmp < table[point] )
+                       value++;
+               if( tmp == 0 ) *cp++ = point;
+       }
+       *cp = END_OF_VEC;
+       
+       cp =  ct;
+       while( *cp != END_OF_VEC )
+               memo[*cp++] = 0;
+
+       return( value );
+}
+
+void makepointtable_nuc( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       p = n;
+       point  = *n++ *  1024;
+       point += *n++ *   256;
+       point += *n++ *    64;
+       point += *n++ *    16;
+       point += *n++ *     4;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 1024;
+               point *= 4;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+void makepointtable( int *pointt, int *n )
+{
+       int point;
+       register int *p;
+
+       p = n;
+       point  = *n++ *  7776;
+       point += *n++ *  1296;
+       point += *n++ *   216;
+       point += *n++ *    36;
+       point += *n++ *     6;
+       point += *n++;
+       *pointt++ = point;
+
+       while( *n != END_OF_VEC )
+       {
+               point -= *p++ * 7776;
+               point *= 6;
+               point += *n++;
+               *pointt++ = point;
+       }
+       *pointt = END_OF_VEC;
+}
+
+#if 1
+static void pairalign( int nseq, int *nlen, char **seq, int *mem1, int *mem2, double *weight, int *alloclen )
+{
+       int l, len1, len2;
+       int clus1, clus2;
+       float pscore, tscore;
+       static int *fftlog;
+       static char *indication1, *indication2;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       static char **mseq1, **mseq2;
+       float dumfl = 0.0;
+       int ffttry;
+       int m1, m2;
+#if 0
+       int i, j;
+#endif
+
+
+       if( effarr1 == NULL ) 
+       {
+               fftlog = AllocateIntVec( nseq );
+               effarr1 = AllocateDoubleVec( nseq );
+               effarr2 = AllocateDoubleVec( nseq );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+               mseq1 = AllocateCharMtx( nseq, 0 );
+               mseq2 = AllocateCharMtx( nseq, 0 );
+               for( l=0; l<nseq; l++ ) fftlog[l] = 1;
+       }
+
+       tscore = 0.0;
+       m1 = mem1[0];
+       m2 = mem2[0];
+       len1 = strlen( seq[m1] );
+       len2 = strlen( seq[m2] );
+       if( *alloclen < len1 + len2 )
+       {
+               fprintf( stderr, "\nReallocating.." );
+               *alloclen = ( len1 + len2 ) + 1000;
+               ReallocateCharMtx( seq, nseq, *alloclen + 10 ); 
+               fprintf( stderr, "done. *alloclen = %d\n", *alloclen );
+       }
+
+#if WEIGHT
+       clus1 = fastconjuction_noname( mem1, seq, mseq1, effarr1, weight, indication1 );
+       clus2 = fastconjuction_noname( mem2, seq, mseq2, effarr2, weight, indication2 );
+#else
+       clus1 = fastconjuction_noweight( mem1, seq, mseq1, effarr1, indication1 );
+       clus2 = fastconjuction_noweight( mem2, seq, mseq2, effarr2, indication2 );
+#endif
+
+#if 0
+       for( i=0; i<clus1; i++ )
+               fprintf( stderr, "in p seq[%d] = %s\n", mem1[i], seq[mem1[i]] );
+       for( i=0; i<clus2; i++ )
+               fprintf( stderr, "in p seq[%d] = %s\n", mem2[i], seq[mem2[i]] );
+#endif
+
+#if 0
+       fprintf( stderr, "group1 = %.66s", indication1 );
+       if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "group2 = %.66s", indication2 );
+       if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+       fprintf( stderr, "\n" );
+#endif
+
+//     fprintf( stdout, "mseq1 = %s\n", mseq1[0] );
+//     fprintf( stdout, "mseq2 = %s\n", mseq2[0] );
+
+       if( !nevermemsave && ( alg != 'M' && ( len1 > 10000 || len2 > 10000  ) ) )
+       {
+               fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode\n", len1, len2 );
+               alg = 'M';
+               if( commonIP ) FreeIntMtx( commonIP );
+               commonAlloc1 = 0;
+               commonAlloc2 = 0;
+       }
+
+       if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 );
+       else                                       ffttry = 0;
+
+       if( force_fft || ( use_fft && ffttry ) )
+       {
+               fprintf( stderr, "\bf" );
+               if( alg == 'M' )
+               {
+                       fprintf( stderr, "\bm" );
+//                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                       pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 );
+               }
+               else
+               {
+//                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                       pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL );
+               }
+       }
+       else
+       {
+               fprintf( stderr, "\bd" );
+               fftlog[m1] = 0;
+               switch( alg )
+               {
+                       case( 'a' ):
+                               pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen );
+                               break;
+                       case( 'M' ):
+                               fprintf( stderr, "\bm" );
+//                             fprintf( stderr, "%d-%d", clus1, clus2 );
+                               pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                               break;
+                       case( 'Q' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                               {
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                               }
+                               else
+                               {
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                               }
+                               break;
+                       case( 'A' ):
+                               if( clus1 == 1 && clus2 == 1 )
+                               {
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = G__align11( mseq1, mseq2, *alloclen, outgap, outgap );
+                               }
+                               else
+                               {
+//                                     fprintf( stderr, "%d-%d", clus1, clus2 );
+                                       pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                               }
+                               break;
+                       default:
+                               ErrorExit( "ERROR IN SOURCE FILE" );
+               }
+       }
+#if SCOREOUT
+       fprintf( stderr, "score = %10.2f\n", pscore );
+#endif
+       nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] );
+       return;
+}
+#endif
+
+#if 0
+static void treebase( int nseq, int *nlen, char **aseq, double *eff, int nalign, int ***topol, int *alloclen ) // topol
+{
+       int i, l;
+       int nlim;
+       int clus1, clus2;
+
+       nlim = nalign-1;
+       for( l=0; l<nlim; l++ )
+       {
+               fprintf( stderr, "in treebase, l = %d\n", l );
+               fprintf( stderr, "aseq[0] = %s\n", aseq[0] );
+               fprintf( stderr, "aseq[topol[l][0][0]] = %s\n", aseq[topol[l][0][0]] );
+               pairalign( nseq, nlen, aseq, topol[l][0], topol[l][1], eff, alloclen );
+               free( topol[l][0] );
+               free( topol[l][1] );
+       }
+}
+#endif
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'S' ) 
+               fprintf( fp, "Apgorithm S\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'X' )
+               fprintf( fp, "Tree = UPGMA (mix).\n" );
+       else if( treemethod == 'E' )
+               fprintf( fp, "Tree = .UPGMA (average)\n" );
+       else if( treemethod == 'q' )
+               fprintf( fp, "Tree = Minimum linkage.\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+#if 1
+static int splitseq_mq( Scores *scores, int nin, int *nlen, char **seq, char **orialn, char **name, char *inputfile, int uniform, char **tree, int *alloclen, int *order, int *whichgroup, double *weight, int *depthpt, int qinoya )
+{
+       int val;
+       int ii, jj;
+       int *mptr;
+       int treelen = 0; // by Mathog, a guess
+       static int groupid = 0;
+       static int branchid = 0;
+       int i, j;
+       int selfscore0;
+       double **dfromc;
+       double **dfromcp;
+       float **pickmtx;
+       float **yukomtx;
+       static short *table1;
+       Scores **outs, *ptr;
+       int *numin;
+       int *tsukau;
+       int belongto;
+       char **children = NULL; // by Mathog, a guess
+       char *tmptree;
+       static int *orderpos = NULL;
+       int rn;
+       int npick;
+       int nyuko;
+       int *picks;
+       int *yukos;
+       int *s_p_map;
+       int *p_o_map;
+       int *s_y_map;
+       int *y_o_map;
+       int *closeh;
+       int nkouho;
+       int *pickkouho;
+       int *iptr;
+       int *jptr;
+       int aligned;
+       int ***topol;
+       int *treeorder;
+       int picktmp;
+       float **len;
+       double minscore;
+//     double *minscoreinpick;
+       float *hanni;
+       double lenfac;
+       double longer;
+       double shorter;
+       static char **mseq1 = NULL;
+       static char **mseq2 = NULL;
+       double *blastresults = NULL; // by Mathog, a guess
+       static int palloclen = 0;
+       float maxdist;
+
+       if( orderpos == NULL )
+               orderpos = order;
+       if( palloclen == 0 )
+               palloclen = *alloclen * 2;
+       if( mseq1 == NULL && doalign == 1 )
+       {
+               mseq1 = AllocateCharMtx( 1, palloclen );
+               mseq2 = AllocateCharMtx( 1, palloclen );
+       }
+
+       if( nin == 0 ) 
+       {
+#if TREE
+               if( treeout )
+               {
+                       *tree = (char *)calloc( 1, sizeof( char ) );
+                       **tree = 0;
+               }
+#endif
+               return 1;
+       }
+
+       if( nin < 2 || uniform == -1 ) // kokodato muda deha nai ga
+       {
+               fprintf( stderr, "\nLeaf  %d / %d                ", ++branchid, njob );
+#if 0
+               outputfile = AllocateCharVec( strlen( inputfile ) + 100 );
+               sprintf( outputfile, "%s-%d", inputfile, branchid );
+               if( uniform > 0 )
+//                     sprintf( outputfile, "%su%d", outputfile, uniform );
+                       sprintf( outputfile + strlen(outputfile), "u%d", uniform );
+               fprintf( stderr, "GROUP %d: %d member(s) (%d) %s\n", branchid, nin, scores[0].numinseq, outputfile );
+               outfp = fopen( outputfile, "w" );
+               free( outputfile );
+               if( outfp == NULL )
+               {
+                       fprintf( stderr, "Cannot open %s\n", outputfile );
+                       exit( 1 );
+               }
+               for( j=0; j<nin; j++ )
+                       fprintf( outfp, ">G%d %s\n%s\n", branchid, scores[j].name+1, seq[scores[j].numinseq] );
+               fclose( outfp );
+#endif
+
+
+#if TREE
+               if( treeout )
+               {
+                       treelen = 0;
+                       tmptree = calloc( 100, sizeof( char ) );
+                       for( j=0; j<nin; j++ )
+                       {
+                               treelen += sprintf( tmptree, "%d", scores[j].numinseq+1 );
+                       }
+                       free( tmptree );
+       
+                       *tree = (char *)calloc( treelen + nin + 5, sizeof( char ) );
+                       if( nin > 1 ) **tree = '(';
+                       else              **tree = '\0';
+//                     **tree = '\0';
+                       for( j=0; j<nin-1; j++ )
+                       {
+                               sprintf( *tree+strlen( *tree ), "%d,", scores[j].numinseq+1 );
+                       }
+                       sprintf( *tree+strlen( *tree ), "%d", scores[j].numinseq+1 );
+                       if( nin > 1 ) strcat( *tree, ")" );
+//                     fprintf( stdout, "*tree = %s\n", *tree );
+               }
+
+#endif
+               for( j=0; j<nin; j++ )
+               {
+                       *orderpos++ = scores[j].numinseq;
+//                     fprintf( stderr, "*order = %d\n", scores[j].numinseq );
+               }
+
+               return 1;
+       }
+
+
+
+       if( uselongest )
+       {
+               i = nin;
+               ptr = scores;
+               selfscore0 = scores->selfscore;
+               belongto = 0;
+               while( i-- )
+               {
+//                     fprintf( stderr, "ptr-scores=%d, numinseq = %d, score = %f\n", ptr-scores, ptr->numinseq+1, ptr->score );
+                       if( ptr->selfscore > selfscore0 )
+                       {
+                               selfscore0 = ptr->selfscore;
+                               belongto = ptr-scores;
+                       }
+                       ptr++;
+               } 
+#if 1 
+               if( belongto != 0 )
+               {
+//                     fprintf( stderr, "swap %d %s\n<->\n%d %s\n", 0, scores->name, belongto, (scores+belongto)->name );
+                       ptr = calloc( 1, sizeof( Scores ) );
+                       *ptr = scores[belongto];
+                       scores[belongto] = *scores;
+                       *scores = *ptr;
+                       free( ptr );
+               }
+#endif
+       }
+       else
+       {
+               qsort( scores, nin, sizeof( Scores ), (int (*)())lcompare );
+               belongto = (int)( 0.5 * nin );
+//             fprintf( stderr, "lengths = %d, %d, %d\n", scores->orilen, scores[belongto].orilen, scores[nin-1].orilen );
+               if( belongto != 0 )
+               {
+//                     fprintf( stderr, "swap %d %s\n<->\n%d %s\n", 0, scores->name, belongto, (scores+belongto)->name );
+                       ptr = calloc( 1, sizeof( Scores ) );
+                       *ptr = scores[belongto];
+                       scores[belongto] = *scores;
+                       *scores = *ptr;
+                       free( ptr );
+               }
+       }
+
+       if( qinoya != scores->numinseq )
+//     if( 1 || qinoya != scores->numinseq )
+       {
+//             fprintf( stdout, "### scores->numinseq = %d, qinoya=%d, depth=%d\n", scores->numinseq, qinoya, *depthpt );
+
+
+               if( doalign )
+               {
+                       if( doalign == 'f' )
+                       {
+                               blastresults = callfasta( seq, scores, nin, NULL, 0, 1 );
+                               if( scores->selfscore != (int)blastresults[0] )
+                               {
+                                       fprintf( stderr, "\n\nWARNING1: selfscore\n" );
+                                       fprintf( stderr, "scores->numinseq = %d\n", scores->numinseq+1 );
+                                       fprintf( stderr, "scores->orilen = %d\n", scores->orilen );
+                                       fprintf( stderr, "scores->selfscore = %d, but blastresults[0] = %f\n", scores->selfscore, blastresults[0] );
+//                                     if( abs( scores->selfscore - (int)blastresults[0] ) > 2 )
+//                                             exit( 1 );
+//                                     scores->selfscore = (int)blastresults[0]; //iinoka?
+       
+//                                     exit( 1 );
+                               }
+                       }
+                       else
+                               gappick0( mseq1[0], seq[scores->numinseq] );
+               }
+               else
+               {
+                       table1 = (short *)calloc( tsize, sizeof( short ) );
+                       if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+                       makecompositiontable_p( table1, scores[0].pointt );
+               }
+       
+               selfscore0 = scores[0].selfscore;
+               for( i=0; i<nin; i++ ) 
+               {
+                       if( scores->orilen > scores[i].orilen )
+                       {
+                               longer = (double)scores->orilen;
+                               shorter = (double)scores[i].orilen;
+                       }
+                       else
+                       {
+                               longer = (double)scores[i].orilen; // nai
+                               shorter = (double)scores->orilen; //nai
+                       }
+
+#if LENFAC
+                       lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca );
+//                     lenfac = 1.0 / ( (double)LENFACA + (double)LENFACB / ( (double)longer + (double)LENFACC ) + (double)shorter / (double)longer * LENFACD );
+//                     fprintf( stderr, "lenfac = %f l=%d,%d\n", lenfac,scores->orilen, scores[i].orilen );
+#else
+                       lenfac = 1.0;
+#endif
+
+                       if( doalign )
+                       {
+                               if( doalign == 'f' )
+                               {
+                                       scores[i].score = ( 1.0 - blastresults[i] / MIN( scores->selfscore, scores[i].selfscore ) ) * 1;
+                                       if( scores[i].score < 0.0 ) scores[i].score = 0.0;
+                               }
+                               else
+                               {
+                                       if( fromaln )
+                                       {
+//                                             scores[i].score = ( 1.0 - (double)G__align11_noalign( amino_disLN, mseq1, mseq2, palloclen ) / MIN( selfscore0, scores[i].selfscore ) ) * 1;
+                                               scores[i].score = ( 1.0 - (double)naivepairscore11( orialn[scores[i].numinseq], orialn[scores->numinseq], penalty ) / MIN( selfscore0, scores[i].selfscore ) ) * 1;
+                                       }
+                                       else
+                                       {
+                                               if( *depthpt == 0 ) fprintf( stderr, "\r%d / %d   ", i, nin );
+                                               gappick0( mseq2[0], seq[scores[i].numinseq] );
+//                                             fprintf( stdout, "### before calc scores[%d] = %f (%c)\n", i, scores[i].score, qinoya == scores->numinseq?'o':'x' );
+                                               scores[i].score = ( 1.0 - (double)G__align11_noalign( amino_disLN, -1200, -60, mseq1, mseq2, palloclen ) / MIN( selfscore0, scores[i].selfscore ) ) * 1;
+//                                             fprintf( stderr, "scores[i] = %f\n", scores[i].score );
+//                                             fprintf( stderr, "m1=%s\n", seq[scores[0].numinseq] );
+//                                             fprintf( stderr, "m2=%s\n", seq[scores[i].numinseq] );
+//                                             fprintf( stdout, "### before calc scores[%d] = %f (%c)\n", i, scores[i].score, qinoya == scores->numinseq?'o':'x' );
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               scores[i].score = ( 1.0 - (double)commonsextet_p( table1, scores[i].pointt ) / MIN( selfscore0, scores[i].selfscore ) ) * lenfac;
+                               if( scores[i].score > MAX6DIST ) scores[i].score = MAX6DIST;
+                       }
+//                     if( i ) fprintf( stderr, "%d-%d d %4.2f len %d %d\n", 1, i+1, scores[i].score, scores->orilen, scores[i].orilen );
+               }
+               if( doalign == 'f' ) free( blastresults );
+               if( doalign == 0 ) free( table1 );
+//exit( 1 );
+       }
+
+//     fprintf( stderr, "sorting .. " );
+       qsort( scores, nin, sizeof( Scores ), (int (*)())dcompare );
+//     fprintf( stderr, "done.\n" );
+
+
+       maxdist = scores[nin-1].score;
+       if( fromaln ) // kanzen itch ga misalign sareteiru kamoshirenai.
+       {
+               if( scores[0].shimon == scores[nin-1].shimon && !strcmp( seq[scores[0].numinseq], seq[scores[nin-1].numinseq] ) ) 
+               {
+                       maxdist = 0.0;
+               }
+//             fprintf( stderr, "maxdist?? = %f, nin=%d, %d inori\n", scores[nin-1].score, nin, scores[nin-1].numinseq+1 );
+       }
+
+//     fprintf( stderr, "maxdist? = %f, nin=%d\n", scores[nin-1].score, nin );
+
+       if( nin == 1 ) fprintf( stderr, "nin=1, scores[0].score = %f\n", scores[0].score );
+
+// kokoni if( nin < 2 || ... )
+
+       picks = AllocateIntVec( nin+1 );
+       s_p_map = AllocateIntVec( nin+1 );
+       s_y_map = AllocateIntVec( nin+1 );
+       pickkouho = AllocateIntVec( nin+1 );
+       closeh = AllocateIntVec( nin+1 );
+
+//     nkouho = getkouho( pickkouho, (picksize+100)/nin, nin, scores, seq );
+//     nkouho = getkouho( pickkouho, 1.0, nin, scores, seq ); // zenbu
+//     fprintf( stderr, "selecting kouhos phase 2\n"  );
+//     if( nkouho == 0 )
+//     {
+//             fprintf( stderr, "selecting kouhos, phase 2\n"  );
+//             nkouho = getkouho( pickkouho, 1.0, nin, scores, seq );
+//     }
+//     fprintf( stderr, "\ndone\n\n"  );
+       for( i=0; i<nin; i++ ) pickkouho[i] = i+1; nkouho = nin-1; // zenbu
+
+
+
+       iptr = picks;
+       *iptr++ = 0;
+       npick = 1;
+       if( nkouho > 0 )
+       {
+//             fprintf( stderr, "pickkouho[0] = %d\n", pickkouho[0] );
+//             fprintf( stderr, "pickkouho[nin-1] = %d\n", pickkouho[nin-1] );
+               picktmp = pickkouho[nkouho-1];
+//             fprintf( stderr, "\nMOST DISTANT kouho=%d, nin=%d, nkouho=%d\n", picktmp, nin, nkouho );
+               nkouho--;
+               if( ( scores[picktmp].shimon == scores[0].shimon ) && ( !strcmp( seq[scores[0].numinseq], seq[scores[picktmp].numinseq] ) ) )
+               {
+//                     fprintf( stderr, "known, j=%d (%d inori)\n", 0, scores[picks[0]].numinseq );
+//                     fprintf( stderr, "%s\n%s\n", seq[scores[picktmp].numinseq], seq[scores[picks[0]].numinseq] );
+                       ;
+               }
+               else
+               {
+                       *iptr++ = picktmp;
+                       npick++;
+//                     fprintf( stderr, "ok, %dth pick = %d (%d inori)\n", npick, picktmp, scores[picktmp].numinseq );
+               }
+       }
+       i = 1;
+       while( npick<picksize && nkouho>0 )
+       {
+               if( i )
+               {
+                       i = 0;
+                       rn = nkouho * 0.5;
+//                     fprintf( stderr, "rn = %d\n", rn );
+               }
+               else
+               {
+                       rn = rnd() * (nkouho);
+               }
+               picktmp = pickkouho[rn];
+//             fprintf( stderr, "rn=%d/%d (%d inori), kouho=%d, nin=%d, nkouho=%d\n", rn, nkouho, scores[pickkouho[rn]].numinseq, pickkouho[rn], nin, nkouho );
+
+//             fprintf( stderr, "#kouho before swap\n" );
+//             for( i=0; i<nkouho; i++ ) fprintf( stderr, "%d ",  pickkouho[i] ); fprintf( stderr, "\n" );
+
+               nkouho--;
+               pickkouho[rn] = pickkouho[nkouho];
+#if 1
+//             fprintf( stderr, "#kouho after swap\n" ); 
+//             for( i=0; i<nkouho; i++ ) fprintf( stderr, "%d ",  pickkouho[i] ); fprintf( stderr, "\n" );
+               for( j=0; j<npick; j++ )
+               {
+                       if( scores[picktmp].shimon == scores[picks[j]].shimon && !strcmp( seq[scores[picks[j]].numinseq], seq[scores[picktmp].numinseq] ) ) 
+                               break;
+               }
+               if( j == npick )
+#endif
+               {
+//                     fprintf( stderr, "ok, %dth pick = %d (%d inori)\n", npick, picktmp, scores[picktmp].numinseq );
+                       npick++;
+                       *iptr++ = picktmp;
+               }
+               else
+               {
+//                     fprintf( stderr, "known, j=%d (%d inori)\n", j, scores[picks[j]].numinseq );
+               }
+       }
+#if 0
+       for( i=0; i<nin; i++ )
+       {
+               fprintf( stderr, "i=%d/%d, scores[%d].score = %f, inori=%d\n", i, nin, i, scores[i].score, scores[i].numinseq );
+       }
+       fprintf( stderr, "range:nin=%d scores[%d].score <= %f\n", nin, npick, scores[nin-1].score);
+       for( i=0; i<npick; i++ )
+       {
+               fprintf( stderr, "i=%d/%d, scores[%d].score = %f, inori=%d\n", i, npick, picks[i], scores[picks[i]].score, scores[picks[i]].numinseq );
+       }
+exit( 1 );
+#endif
+
+//     fprintf( stderr, "\nnkouho=%d, defaultq2 = %d (%d inori)\n", nkouho, picks[npick-1], scores[picks[npick-1]].numinseq );
+
+       qsort( picks, npick, sizeof( int ), (int (*)())intcompare );
+
+//     fprintf( stderr, "allocating..\n" );
+
+//     fprintf( stderr, "allocating outs, npick = %d\n", npick );
+       numin = calloc( npick, sizeof( int ) );
+       tsukau = calloc( npick, sizeof( int ) );
+       outs = calloc( npick, sizeof( Scores * ) );
+       for( i=0; i<npick; i++ ) outs[i] = NULL;
+       topol = AllocateIntCub( npick, 2, 0 );
+       treeorder = AllocateIntVec( npick + 1 );
+       len = AllocateFloatMtx( npick, 2 );
+       pickmtx = AllocateFloatHalfMtx( npick );
+//     yukomtx = AllocateFloatHalfMtx( npick );
+//     minscoreinpick = AllocateDoubleVec( npick );
+       yukos = AllocateIntVec( npick );
+       p_o_map = AllocateIntVec( npick+1 );
+       y_o_map = AllocateIntVec( npick+1 );
+       hanni = AllocateFloatVec( npick );
+
+       for( i=0; i<nin; i++ ) s_p_map[i] = -1;
+//     fprintf( stderr, "npick = %d\n", npick );
+//     fprintf( stderr, "picks =" );
+       for( i=0; i<npick; i++ )
+       {
+               s_p_map[picks[i]] = i;
+               p_o_map[i] = scores[picks[i]].numinseq;
+//             fprintf( stderr, " %d (%dinori)\n", picks[i], scores[picks[i]].numinseq+1 );
+       }
+//     fprintf( stderr, "\n" );
+
+#if 0
+       fprintf( stderr, "p_o_map =" );
+       for( i=0; i<npick; i++ )
+       {
+               fprintf( stderr, " %d", p_o_map[i]+1 );
+       }
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "picks =" );
+       for( i=0; i<npick; i++ )
+       {
+               fprintf( stderr, " %d", picks[i] );
+       }
+       fprintf( stderr, "\n" );
+#endif
+
+       for( j=0; j<nin; j++ )
+       {
+               if( s_p_map[j] != -1 )
+               {
+                       pickmtx[0][s_p_map[j]] = (float)scores[j].score;
+//                     fprintf( stderr, "pickmtx[0][%d] = %f\n", s_p_map[j], pickmtx[0][s_p_map[j]] );
+               }
+       }
+
+       for( j=1; j<npick; j++ )
+       {
+               if( doalign )
+               {
+                       if( doalign == 'f' )
+                       {
+//                             blastresults = callfasta( seq, scores, npick-j+1, picks+j-1, picks[j], 1 );
+                               blastresults = callfasta( seq, scores, npick, picks, picks[j], (j==1) );
+                               if( scores[picks[j]].selfscore != (int)blastresults[j] )
+                               {
+                                       fprintf( stderr, "\n\nWARNING2: selfscore j=%d/%d\n", j, npick );
+                                       fprintf( stderr, "scores[picks[j]].numinseq = %d\n", scores[picks[j]].numinseq+1 );
+                                       fprintf( stderr, "scores[picks[j]].orilen = %d\n", scores[picks[j]].orilen );
+                                       fprintf( stderr, "scores[picks[j]].selfscore = %d, but blastresults[j] = %f\n", scores[picks[j]].selfscore, blastresults[j] );
+//                                     if( abs( scores[picks[j]].selfscore - (int)blastresults[j] ) > 2 )
+//                                             exit( 1 );
+//                                     scores->selfscore = (int)blastresults[0]; //iinoka?
+                               }
+                       }
+                       else
+                               gappick0( mseq1[0], seq[scores[picks[j]].numinseq] );
+               }
+               else
+               {
+                       table1 = (short *)calloc( tsize, sizeof( short ) );
+                       if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+                       makecompositiontable_p( table1, scores[picks[j]].pointt );
+               }
+       
+               selfscore0 = scores[picks[j]].selfscore;
+               pickmtx[j][0] = 0.0;
+           for( i=j+1; i<npick; i++ ) 
+               {
+                       if( scores[picks[j]].orilen > scores[picks[i]].orilen )
+                       {
+                               longer = (double)scores[picks[j]].orilen;
+                               shorter = (double)scores[picks[i]].orilen;
+                       }
+                       else
+                       {
+                               longer = (double)scores[picks[i]].orilen;
+                               shorter = (double)scores[picks[j]].orilen;
+                       }
+       
+       #if LENFAC
+                       lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca );
+       //              lenfac = 1.0 / ( (double)LENFACA + (double)LENFACB / ( (double)longer + (double)LENFACC ) + (double)shorter / (double)longer * LENFACD );
+       //              fprintf( stderr, "lenfac = %f l=%d,%d\n", lenfac,scores->orilen, scores[i].orilen );
+       #else
+                       lenfac = 1.0;
+       #endif
+       
+                       if( doalign )
+                       {
+                               if( doalign == 'f' )
+                               {
+                                       pickmtx[j][i-j] = ( 1.0 - blastresults[i] / MIN( selfscore0, scores[picks[i]].selfscore ) ) * 1;
+                                       if( pickmtx[j][i-j] < 0.0 ) pickmtx[j][i-j] = 0.0;
+                               }
+                               else
+                               {
+                                       if( fromaln )
+                                       {
+                                               fprintf( stderr, "%d-%d/%d\r", j, i, npick );
+                                               pickmtx[j][i-j] = ( 1.0 - (double)naivepairscore11(  orialn[scores[picks[i]].numinseq], orialn[scores[picks[j]].numinseq], penalty ) / MIN( selfscore0, scores[picks[i]].selfscore ) ) * 1;
+                                       }
+                                       else
+                                       {
+//                                             fprintf( stderr, "\r%d / %d   ", i, nin );
+                                               gappick0( mseq2[0], seq[scores[picks[i]].numinseq] );
+                                               pickmtx[j][i-j] = ( 1.0 - (double)G__align11_noalign( amino_disLN, -1200, -60, mseq1, mseq2, palloclen ) / MIN( selfscore0, scores[picks[i]].selfscore ) ) * 1;
+       //                                      fprintf( stderr, "scores[picks[i]] = %f\n", scores[picks[i]].score );
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               pickmtx[j][i-j] = ( 1.0 - (double)commonsextet_p( table1, scores[picks[i]].pointt ) / MIN( selfscore0, scores[picks[i]].selfscore ) ) * lenfac;
+                               if( pickmtx[j][i-j] > MAX6DIST ) pickmtx[j][i-j] = MAX6DIST;
+                       }
+
+               }
+               if( doalign == 'f' ) free( blastresults );
+               if( doalign == 0 ) free( table1 );
+       }
+
+       dfromcp = AllocateDoubleMtx( npick, nin );
+       dfromc = AllocateDoubleMtx( npick, 0 );
+
+       for( i=0; i<npick; i++ ) for( j=0; j<nin; j++ )
+               dfromcp[i][j] = -0.5;
+       for( j=0; j<nin; j++ )
+       {
+               dfromcp[0][j] = ( scores[j].score );
+//             fprintf( stderr, "j=%d, s_p_map[j]=%d\n", j, s_p_map[j] );
+       }
+
+       for( i=0; i<npick; i++ ) for( j=i; j<npick; j++ )
+       {
+               dfromcp[i][picks[j]] = dfromcp[j][picks[i]] = pickmtx[i][j-i];
+       }
+
+#if 0
+       fprintf( stderr, "pickmtx = \n" );
+       for( i=0; i<npick; i++ )
+       {
+               for( j=i; j<npick; j++ )
+               {
+                       fprintf( stderr, "pickmtx[%d][%d] = %f\n", p_o_map[i]+1, p_o_map[j]+1, pickmtx[i][j-i] );
+               }
+       }
+       exit( 1 );
+#endif
+
+
+
+//     for( i=0; i<npick-1; i++ ) for( j=i; j<npick; j++ )
+//             fprintf( stderr, "dist[%d][%d] = %f\n", p_o_map[i]+1, p_o_map[j]+1, pickmtx[i][j-i] );
+
+       for( i=0; i<npick; i++ ) tsukau[i] = 1;
+       for( i=0; i<nin; i++ ) closeh[i] = -1;
+       for( i=0; i<npick; i++ ) 
+       {
+               closeh[picks[i]] = picks[i];
+//             fprintf( stderr, "i=%d/%d, picks[i]=%d, %d inori, closeh[%d] = %d \n", i, npick, picks[i], p_o_map[i]+1, picks[i], closeh[picks[i]] );
+       }
+#if 0
+       fprintf( stderr, "closeh = \n" );
+       for( i=0; i<nin; i++ )
+       {
+               fprintf( stderr, "%d ", closeh[i] );
+       }
+       fprintf( stderr, "\n" );
+#endif
+#if DIANA
+       for( i=0; i<npick-1; i++ ) for( j=i; j<npick; j++ )
+               fprintf( stderr, "dist[%d][%d] = %f\n", p_o_map[i]+1, p_o_map[j]+1, pickmtx[i][j-i] );
+       fprintf( stderr, "DIANA!!\n" );
+       if( npick > 2 )
+       {
+               float avdist;
+               float avdist1;
+               float avdist2;
+               float maxavdist;
+               int splinter;
+               int count;
+               int dochokoho;
+               splinter = 0;
+               int *docholist;
+               int *docholistbk;
+               maxavdist = 0.0;
+               for( i=0; i<npick; i++ )
+               {
+                       avdist = 0.0;
+                       for( j=i+1; j<npick; j++ )
+                       {
+                               avdist += pickmtx[i][j-i];
+                       }
+                       for( j=0; j<i; j++ )
+                       {
+                               avdist += pickmtx[j][i-j];
+                       }
+                       avdist /= (npick-1);
+                       fprintf( stderr, "avdist[%d] = %f\n", p_o_map[i] + 1, avdist );
+                       if( maxavdist < avdist ) 
+                       {
+                               maxavdist = avdist;
+                               splinter = i;
+                       }
+               }
+               fprintf( stderr, "splinter = %d (%d inori), maxavdist = %f\n", splinter, p_o_map[splinter]+1, maxavdist );
+
+               docholist = AllocateIntVec( npick );
+               docholistbk = AllocateIntVec( npick );
+               for( i=0; i<npick; i++ ) docholist[i] = 0;
+               docholist[splinter] = 1;
+               while( 1 )
+               {
+                       for( i=0; i<npick; i++ ) docholistbk[i] = docholist[i]; 
+                       for( dochokoho = 0; dochokoho<npick; dochokoho++ )
+                       {
+                               fprintf( stderr, "dochokoho=%d\n", dochokoho );
+                               if( docholist[dochokoho] ) continue;
+                               count = 0;
+                               avdist1 = 0.0;
+                               i=dochokoho;
+                               {
+                                       for( j=i+1; j<npick; j++ )
+                                       {
+                                               if( docholist[j] || j == dochokoho ) continue;
+                                               avdist1 += pickmtx[i][j-i];
+                                               count++;
+                                       }
+                                       for( j=0; j<i; j++ )
+                                       {
+                                               if( docholist[j] || j == dochokoho ) continue;
+                                               avdist1 += pickmtx[j][i-j];
+                                               count++;
+                                       }
+                               }
+                               if( count < 1 ) avdist1 = 0.0;
+                               else avdist1 /= (float)count;
+                               fprintf( stderr, "docho %d (%dinori), avdist1 = %f\n", dochokoho, p_o_map[dochokoho] + 1, avdist1 );
+
+                               count = 0;
+                               avdist2 = 0.0;
+                               i=dochokoho;
+                               {
+                                       for( j=i+1; j<npick; j++ )
+                                       {
+                                               if( !docholist[j] || j == dochokoho ) continue;
+                                               avdist2 += pickmtx[i][j-i];
+                                               count++;
+                                       }
+                                       for( j=0; j<i; j++ )
+                                       {
+                                               if( !docholist[j] || j == dochokoho ) continue;
+                                               avdist2 += pickmtx[j][i-j];
+                                               count++;
+                                       }
+                               }
+                               if( count < 1 ) avdist2 = 0.0;
+                               else avdist2 /= (float)count;
+                               fprintf( stderr, "docho %d (%dinori), avdist2 = %f\n", dochokoho, p_o_map[dochokoho] + 1, avdist2 );
+
+                               if( avdist2 < avdist1 ) 
+                               {
+                                       docholist[dochokoho] = 1;
+                                       hanni[dochokoho] = avdist2;
+                               }
+                               else
+                               {
+                                       docholist[dochokoho] = 0;
+                                       hanni[dochokoho] = avdist1;
+                               }
+                               fprintf( stderr, "avdist1=%f, avdist2=%f\n", avdist1, avdist2 );
+
+                       }
+                       for( i=0; i<npick; i++ ) if( docholist[i] != docholistbk[i] ) break;
+                       if( i == npick ) break;
+
+                       fprintf( stderr, "docholist = \n" );
+                       for( i=0; i<npick; i++ ) fprintf( stderr, "%d ", docholist[i] );
+                       fprintf( stderr, "\n" );
+               }
+               fprintf( stderr, "docholist = \n" );
+               for( i=0; i<npick; i++ ) fprintf( stderr, "%d ", docholist[i] );
+               fprintf( stderr, "\n" );
+
+               for( i=0; i<npick; i++ ) if( docholist[i] == 0 ) break;
+               yukos[0] = picks[i];
+               for( i=0; i<npick; i++ ) if( docholist[i] == 1 ) break;
+               yukos[1] = picks[splinter];
+
+               for( i=0; i<npick; i++ ) 
+               {
+                       if( docholist[i] == 0 ) closeh[picks[i]] = yukos[0];
+                       if( docholist[i] == 1 ) closeh[picks[i]] = yukos[1];
+               }
+//             for( i=0; i<npick; i++ ) closeh[picks[i]] = -1; // CHUUI !! iminai
+               nyuko = 2;
+               free( docholist );
+               free( docholistbk );
+       }
+       else if( npick > 1 )
+       {
+               nyuko = 2;
+               yukos[0] = picks[0]; yukos[1] = picks[1];
+               closeh[picks[0]] = yukos[0];
+               closeh[picks[1]] = yukos[1];
+       }
+       else
+       {
+               nyuko = 1;
+               yukos[0] = picks[0];
+               closeh[picks[0]] = yukos[0];
+       }
+#elif HUKINTOTREE
+       if( npick > 2 )
+       {
+#if 0
+               float avdist;
+               float maxavdist;
+               int count;
+               int splinter;
+               maxavdist = 0.0;
+               splinter=0;
+               for( i=0; i<npick; i++ )
+               {
+                       avdist = 0.0;
+                       for( j=i+1; j<npick; j++ )
+                       {
+                               avdist += pickmtx[i][j-i];
+                       }
+                       for( j=0; j<i; j++ )
+                       {
+                               avdist += pickmtx[j][i-j];
+                       }
+                       avdist /= (npick-1);
+                       fprintf( stderr, "avdist[%d] = %f\n", p_o_map[i] + 1, avdist );
+                       if( maxavdist < avdist ) 
+                       {
+                               maxavdist = avdist;
+                               splinter = i;
+                       }
+               }
+               fprintf( stderr, "splinter = %d (%d inori), maxavdist = %f\n", splinter, p_o_map[splinter]+1, maxavdist );
+#endif
+
+
+//             fprintf( stderr, "check kaishi =>, npick=%d members = \n", npick );
+//             for( i=0; i<npick; i++ ) fprintf( stderr, "%d (%d)", p_o_map[i]+1, picks[i] );
+//             fprintf( stderr, "\n" );
+               for( i=0; i<npick-1; i++ ) 
+               {
+                       if( tsukau[i] == 0 ) continue;
+                       for( j=i+1; j<npick; j++ )
+                       {
+//                             float kijun = maxdist *  1/(npick-2);
+//                             float kijun = maxavdist * tokyoripara;
+                               float kijun;
+                               kijun = maxdist * tokyoripara;  // atode kakunin
+//                             fprintf( stderr, "%d-%d\n", i, j );
+//                             fprintf( stderr, "maxdist = %f\n", maxdist );
+//                             if( i==0 && j == 1 ) continue; // machigai!! CHUUI!!
+//                             if( maxdist == pickmtx[i][j-i] ) continue;
+                               if( tsukau[j] == 0 ) continue;
+//                             fprintf( stderr, "checking %d-%d (%d-%d) %f, kijun=%f\n", p_o_map[i]+1, p_o_map[j]+1, i, j, pickmtx[i][j-i], kijun );
+                               if( pickmtx[i][j-i] < kijun )
+                               {
+//                                     fprintf( stderr, "dame!! %d => %d, because %f < %f\n", p_o_map[j]+1, p_o_map[i]+1, pickmtx[i][j-i], kijun );
+#if 0
+                                       if( scores[picks[i]].orilen > scores[picks[j]].orilen )
+                                       {
+                                               fprintf( stderr, "%d => %d\n", p_o_map[j]+1, p_o_map[i]+1 );
+                                               tsukau[j] = 0;
+                                       }
+                                       else
+                                       {
+                                               fprintf( stderr, "%d => %d\n", p_o_map[i]+1, p_o_map[j]+1 );
+                                               tsukau[i] = 0;
+                                       }
+                                       if( 0 && j == npick-1 ) tsukau[i] = 0;
+                                       else                       tsukau[j] = 0;
+                                       fprintf( stderr, "tsukau[%d] = %d (%d inori)\n", j, tsukau[j], p_o_map[j]+1 );
+#else
+                                       tsukau[j] = 0;
+                                       closeh[picks[j]] = closeh[picks[i]];
+//                                     fprintf( stderr, "%d => tsukawanai\n", j );
+#endif
+                               }
+                       }
+               }
+       }
+       for( ii=0,i=0; i<npick; i++ )
+       {
+               if( tsukau[i] )
+               {
+                       dfromc[ii] = dfromcp[i];
+                       ii++;
+               }
+               else
+               {
+                       free( dfromcp[i] );
+                       dfromcp[i] = NULL;
+               }
+       }
+       dfromc[ii] = NULL;
+
+       for( ii=0,i=0; i<npick; i++ )
+       {
+               if( tsukau[i] )
+               {
+                       for( jj=ii,j=i; j<npick; j++ )
+                       {
+                               if( tsukau[j] )
+                               {
+                                       pickmtx[ii][jj-ii] = pickmtx[i][j-i];
+                                       jj++;
+                               }
+                       }
+                       ii++;
+               }
+       }
+       for( ; ii<npick; ii++ )
+       {
+               free( pickmtx[ii] ); 
+               pickmtx[ii] = NULL;
+       }
+
+       for( ii=0,i=0; i<npick; i++ )
+       {
+               if( tsukau[i] )
+               {
+                       yukos[ii++] = picks[i];
+               }
+       }
+
+
+       nyuko = ii;
+       yukomtx = pickmtx;
+       pickmtx = NULL;
+
+#endif
+#if 0
+       for( i=0; i<npick; i++ ) for( j=i; j<npick; j++ )
+       {
+               if( tsukau[i] == 1 && tsukau[j] == 1 )
+                       fprintf( stderr, "dist[%d][%d] = %f (ok)\n", p_o_map[i]+1, p_o_map[j]+1, pickmtx[i][j-i]  );
+               else if( tsukau[i] == 0 && tsukau[j] == 0 )
+                       fprintf( stderr, "dist[%d][%d] = %f (xx)\n", p_o_map[i]+1, p_o_map[j]+1, pickmtx[i][j-i]  );
+               else    
+                       fprintf( stderr, "%d-%d, okashii\n", p_o_map[i]+1, p_o_map[j]+1 );
+       }
+#endif
+//     FreeFloatHalfMtx( pickmtx, npick );
+
+
+       for( i=0; i<nin; i++ ) s_y_map[i] = -1;
+//     fprintf( stderr, "npick = %d\n", npick );
+//     fprintf( stderr, "yukos =" );
+       for( i=0; i<nyuko; i++ )
+       {
+               s_y_map[yukos[i]] = i;
+               y_o_map[i] = scores[yukos[i]].numinseq;
+//             fprintf( stderr, " %d\n", yukos[i] );
+       }
+//     fprintf( stderr, "\n" );
+#if 0
+       for( i=0; i<nyuko; i++ )
+       {
+               fprintf( stderr, "y_o_map[%d] = %d\n", i, y_o_map[i]+1 );
+       }
+       for( i=0; i<nyuko; i++ ) for( j=i; j<nyuko; j++ )
+       {
+               fprintf( stderr, "yukodist[%d][%d] = %f (ok)\n", y_o_map[i]+1, y_o_map[j]+1, yukomtx[i][j-i]  );
+       }
+#endif
+
+       for( i=0; i<nin; i++ )
+       {
+               if( closeh[i] != -1 )
+               {
+//                     fprintf( stderr, "closeh[%d,%dinori] = %d,%dinori\n", i, scores[i].numinseq+1, closeh[i], scores[closeh[i]].numinseq+1 );
+               }
+       }
+
+#if 0
+               for( i=0; i<nyuko; i++ )
+               {
+                       minscoreinpick[i] = 99.9;
+                       for( j=i+1; j<nyuko; j++ )
+                       {
+                               if( minscoreinpick[i] > yukomtx[i][j-i] )
+                                       minscoreinpick[i] = yukomtx[i][j-i];
+                       }
+                       for( j=0; j<i; j++ )
+                       {
+                               if( minscoreinpick[i] > yukomtx[j][i-j] )
+                                       minscoreinpick[i] = yukomtx[j][i-j];
+                       }
+                       fprintf( stderr, "minscoreinpick[%d(%dinori)] = %f\n", i, y_o_map[i]+1, minscoreinpick[i] );
+               }
+#endif
+
+
+#if TREE
+       if( treeout )
+       {
+               children = calloc( nyuko+1, sizeof( char * ) );
+               for( i=0; i<nyuko+1; i++ ) children[i] = NULL;
+       }
+#endif
+//     fprintf( stderr, "done..\n" );
+       
+//     fprintf( stderr, "classifying, nyuko=%d \n", nyuko );
+       if( nyuko == 1 )
+       {
+               if( npick != 1 )
+               {
+                       fprintf( stderr, "okashii, nyuko = 1, shikashi npick = %d\n", npick );
+                       exit( 1 );
+               }
+//             fprintf( stderr, "### itchi suru hazu, nazenara scores[nin-1].score=%f, selfscores=%d,%d\n", scores[nin-1].score, scores[nin-1].selfscore, scores->selfscore );
+//             fprintf( stderr, "seq[%d] = scores->seq = \n%s\n", scores->numinseq, seq[scores->numinseq] );
+
+               uniform = -1;
+               for( j=0; j<nin; j++ ) 
+               {
+                       belongto = 0;
+                       outs[belongto] = realloc( outs[belongto], sizeof( Scores ) * ( numin[belongto] + 1 ) );
+                       outs[belongto][numin[belongto]] = scores[j];
+                       numin[belongto]++;
+               }
+       }
+       else
+       {
+
+#if 0
+               fprintf( stderr, "yukos = \n" );
+               for( i=0; i<nyuko; i++ ) fprintf( stderr, "%d ", y_o_map[i] + 1 );
+               fprintf( stderr, "\n" );
+#endif
+               fprintf( stderr, "\n\n%dx%d distance matrix\n", nyuko, nin );
+
+               for( i=1; i<nyuko; i++ )
+               {
+                       fprintf( stderr, "%d / %d \r", i, nyuko );
+
+                       if( doalign )
+                       {
+                               if( doalign == 'f' )
+                               {
+                                       blastresults = callfasta( seq, scores, nin, NULL, yukos[i], (i==1) );
+                               }
+                               else
+                                       gappick0( mseq1[0], seq[scores[yukos[i]].numinseq] );
+                       }
+                       else
+                       {
+                               table1 = (short *)calloc( tsize, sizeof( short ) );
+                               if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+                               makecompositiontable_p( table1, scores[yukos[i]].pointt );
+                       }
+               
+                       selfscore0 = scores[yukos[i]].selfscore;
+                       for( j=0; j<nin; j++ ) 
+                       {
+                               if( scores[yukos[i]].orilen > scores[j].orilen )
+                               {
+                                       longer = scores[yukos[i]].orilen;
+                                       shorter = scores[j].orilen;
+                               }
+                               else
+                               {
+                                       shorter = scores[yukos[i]].orilen;
+                                       longer = scores[j].orilen;
+                               }
+
+#if LENFAC
+//                             lenfac = 1.0 / ( (double)LENFACA + (double)LENFACB / ( (double)longer + (double)LENFACC ) + (double)shorter / (double)longer * LENFACD );
+                               lenfac = 1.0 / ( shorter / longer * lenfacd + lenfacb / ( longer + lenfacc ) + lenfaca );
+//                             lenfac = 1.0 / ( shorter / longer * LENFACD + LENFACB / ( longer + LENFACC ) + LENFACA );
+//                             fprintf( stderr, "lenfac = %f, l=%d, %d\n", lenfac, scores[yukos[i]].orilen, scores[j].orilen );
+#else
+                               lenfac = 1.0;
+#endif
+#if 0 // iihazu -> dame
+                               ii = s_y_map[j]; jj=s_y_map[yukos[i]];
+                               if( ii != -1 && jj != -1 )
+                               {
+                                       if( dfromc[ii][yukos[jj]] != -0.5 )
+                                       {
+                                               dfromc[i][j] = dfromc[ii][yukos[jj]];
+                                       }
+                                       else
+                                       {
+                                               if( ii > jj )
+                                               {
+                                                       kk = jj;
+                                                       jj = ii;
+                                                       ii = kk;
+                                               }
+                                               dfromc[ii][yukos[jj]] = 
+                                               dfromc[i][j] = yukomtx[ii][jj-ii];
+                                       }
+                               }
+                               else
+#else
+                               if( dfromc[i][j] == -0.5 )
+#endif
+                               {
+                                       if( doalign )
+                                       {
+                                               if( doalign == 'f' )
+                                               {
+                                                       dfromc[i][j] = 
+                                                       ( 1.0 - blastresults[j] / MIN( selfscore0, scores[j].selfscore ) ) * 1;
+                                                       if( dfromc[i][j] < 0.0 ) dfromc[i][j] = 0.0;
+                                               }
+                                               else
+                                               {
+                                                       if( fromaln )
+                                                       {
+                                                               dfromc[i][j] = ( 1.0 - (double)naivepairscore11( orialn[scores[j].numinseq], orialn[scores[yukos[i]].numinseq], penalty ) / MIN( selfscore0, scores[j].selfscore ) ) * 1;
+                                                       }
+                                                       else
+                                                       {
+                                                               gappick0( mseq2[0], seq[scores[j].numinseq] );
+                                                               dfromc[i][j] = ( 1.0 - (double)G__align11_noalign( amino_disLN, -1200, -60, mseq1, mseq2, palloclen ) / MIN( selfscore0, scores[j].selfscore ) ) * 1;
+                                                       }
+                                               }
+                                       }
+                                       else
+                                       {
+                                               dfromc[i][j] = ( 1.0 - (double)commonsextet_p( table1, scores[j].pointt ) / MIN( selfscore0, scores[j].selfscore ) ) * lenfac;
+                                               if( dfromc[i][j] > MAX6DIST ) dfromc[i][j] = MAX6DIST;
+                                       }
+                               }
+//                             fprintf( stderr, "i,j=%d,%d (%d,%d)/ %d,%d, dfromc[][]=%f \n", i, j, scores[yukos[i]].numinseq+1, scores[j].numinseq+1, nyuko, nin, dfromc[i][j] );
+
+//                             if( i == 1 )
+//                                     fprintf( stdout, "&&& dfromc[%d][%d] (%d,%d) = %f\n", i, j, p_o_map[i], scores[j].numinseq, dfromc[i][j] );
+                       }
+//                     fprintf( stderr, "i=%d, freeing\n", i );
+                       if( !doalign ) free( table1 );
+                       if( doalign && doalign == 'f' ) free( blastresults );
+               }
+               fprintf( stderr, "                \r" );
+
+
+
+
+               for( i=0; i<nyuko; i++ ) numin[i] = 0;
+//             fprintf( stderr, "### itchi shinai hazu, nazenara scores[nin-1].score=%f, selfscores=%d,%d, len=%d,%d, nin=%d\n", scores[nin-1].score, scores[nin-1].selfscore, scores->selfscore, scores->orilen, scores[nin-1].orilen, nin );
+               for( j=0; j<nin; j++ ) 
+               {
+#if 0
+                       belongto = s_y_map[j];
+                       {
+                               fprintf( stderr, "belongto = %d (%dinori)\n", belongto, y_o_map[belongto]+1 ); 
+                       }
+                       if( belongto == -1 && closeh[j] != -1 )
+#endif
+#if 0
+                       if( closeh[j] != -1 )
+                       {
+                               belongto = s_y_map[closeh[j]];
+//                             if( belongto != -1 )
+//                                     fprintf( stderr, "known, %d(%dinori)->%d(%dinori)\n", j, scores[j].numinseq+1, belongto, y_o_map[belongto]+1 );
+                       }
+                       else
+//                     if( belongto == -1 )
+#else
+                       belongto = s_y_map[j];
+                       if( belongto == -1 )
+#endif
+                       {
+                               belongto = 0;  // default ha horyu
+                               minscore = dfromc[0][j];
+                               for( i=0; i<nyuko; i++ )
+                               {
+//                                     fprintf( stderr, "checking %d/%d,%d/%d (%d-%d inori) minscore=%f, dfromc[0][j]=%f, dfromc[i][j]=%f\n", i, nyuko, j, nin, y_o_map[i], scores[j].numinseq, minscore, dfromc[0][j], dfromc[i][j] );
+                                       if( scores[j].shimon == scores[yukos[i]].shimon && !strcmp( seq[scores[j].numinseq], seq[y_o_map[i]] ) ) 
+                                       {
+//                                             fprintf( stderr, "yuko-%d (%d in ori) to score-%d (%d inori) ha kanzen itch\n", i, y_o_map[i], j, scores[j].numinseq );
+                                               belongto = i;
+                                               break;
+                                       }
+                                       if( dfromc[i][j] < minscore )
+//                                     if( dfromc[i][j] < minscore && minscore-dfromc[i][j] > ( minscoreinpick[yukos[i]] + minscoreinpick[j] ) * 1.0 )
+//                                     if( rnd() < 0.5 ) // CHUUI !!!!!
+                                       {
+//                                             fprintf( stderr, "yuko-%d (%d in ori) to score-%d (%d inori) ha tikai, %f>%f\n", i, y_o_map[i]+1, j, scores[j].numinseq+1, minscore, dfromc[i][j] );
+                                               minscore = dfromc[i][j];
+                                               belongto = i;
+                                       }
+                               }
+                       }
+#if 0
+                       if( dfromc[belongto][j] > minscoreinpick[belongto] )
+                       {
+                               fprintf( stderr, "dame, %f > %f\n", dfromc[belongto][j], minscoreinpick[belongto] );
+                               belongto = npick;
+                       }
+                       else
+                               fprintf( stderr, "ok, %f < %f\n", dfromc[belongto][j], minscoreinpick[belongto] );
+#endif
+//                     fprintf( stderr, "j=%d (%d inori) -> %d (%d inori) d=%f\n", j, scores[j].numinseq+1, belongto, y_o_map[belongto]+1, dfromc[belongto][j] );
+//                     fprintf( stderr, "numin = %d\n", numin[belongto] );
+                       outs[belongto] = realloc( outs[belongto], sizeof( Scores ) * ( numin[belongto] + 1 ) );
+                       outs[belongto][numin[belongto]] = scores[j];
+                       numin[belongto]++;
+
+               }
+               free( dfromcp );
+               FreeDoubleMtx( dfromc );
+
+//             fprintf( stderr, "##### npick = %d\n", npick );
+//             fprintf( stderr, "##### nyuko = %d\n", nyuko );
+
+
+               if( nyuko > 2 )
+               {
+                       fprintf( stderr, "upgma       " );
+//                     veryfastsupg_float_realloc_nobk_halfmtx( nyuko, yukomtx, topol, len );
+                       fixed_musclesupg_float_realloc_nobk_halfmtx( nyuko, yukomtx, topol, len, NULL );
+                       fprintf( stderr, "\r                      \r" );
+               }
+               else
+               {
+                       topol[0][0] = (int *)realloc( topol[0][0], 2 * sizeof( int ) );
+                       topol[0][1] = (int *)realloc( topol[0][1], 2 * sizeof( int ) );
+                       topol[0][0][0] = 0;
+                       topol[0][0][1] = -1;
+                       topol[0][1][0] = 1;
+                       topol[0][1][1] = -1;
+               }
+               FreeFloatHalfMtx( yukomtx, npick );
+
+#if 0
+               ii = nyuko-1;
+               fprintf( stderr, "nyuko = %d, topol[][] = \n", nyuko );
+               for( j=0; j<nyuko-1; j++ )
+               {
+                       fprintf( stderr, "STEP%d \n", j );
+                       for( i=0; ; i++ )
+                       {
+                               fprintf( stderr, "%d ", ( topol[j][0][i] )+0 );
+                               if( topol[j][0][i] == -1 ) break;
+                       }
+                       fprintf( stderr, "\n" );
+                       for( i=0; ; i++ )
+                       {
+                               fprintf( stderr, "%d ", ( topol[j][1][i] )+0 );
+                               if( topol[j][1][i] == -1 ) break;
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "\n" );
+               }
+               exit( 1 );
+#endif
+               jptr = treeorder; 
+               iptr = topol[nyuko-2][0]; while( *iptr != -1 ) *jptr++ = *iptr++;
+               iptr = topol[nyuko-2][1]; while( *iptr != -1 ) *jptr++ = *iptr++;
+               *jptr++ = -1;
+               for( j=0; j<nyuko; j++ )
+               {
+//                     fprintf( stderr, "treeorder[%d] = %d\n", j, treeorder[j] );
+                       if( treeorder[j] == -1 ) break;
+               }
+       }
+
+       aligned = 1;
+       for( i=0; i<nyuko; i++ )
+       {
+               ii = treeorder[i];
+#if 0
+               if( numin[ii] > 1 )
+               {
+                       fprintf( stderr, "\ncalling a child, pick%d (%d inori): # of mem=%d\n", i, p_o_map[ii]+1, numin[ii] );
+                       for( j=0; j<numin[ii]; j++ )
+                       {
+                               fprintf( stderr, "%d ", outs[ii][j].numinseq+1 );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+#endif
+               aligned *= splitseq_mq( outs[ii], numin[ii], nlen, seq, orialn, name, inputfile, uniform, children+ii, alloclen, order, whichgroup, weight, depthpt, scores->numinseq );
+       }
+
+
+       for( i=0; i<nyuko; i++ )
+       {
+               if( !numin[i] )
+               {
+                       fprintf( stderr, "i=%d/%d, ERROR!\n", i, nyuko );
+                       for( j=0; j<nyuko; j++ )
+                               fprintf( stderr, "numin[%d] = %d (rep=%d inori)\n", j, numin[j], y_o_map[j] );
+                       exit( 1 );
+               }
+       }
+
+#if TREE
+       if( treeout )
+       {
+               treelen = 0;
+               for( i=0; i<nyuko; i++ )
+                       treelen += strlen( children[i] );
+               *tree = calloc( treelen + nin * 3, sizeof ( char ) );
+       }
+#endif
+
+
+       if( nin >= classsize || !aligned )
+               val = 0;
+       else
+               val = 1;
+
+       if( nyuko > 1 )
+       {
+               int *mem1p, *mem2p;
+               int mem1size, mem2size;
+               int v1 = 0, v2 = 0, v3 = 0;
+               int nlim;
+               int l;
+               static int *mem1 = NULL;
+               static int *mem2 = NULL;
+               char **parttree = NULL; // by Mathog
+
+#if TREE
+               if( treeout )
+               {
+                       parttree = (char **)calloc( nyuko, sizeof( char * ) );
+                       for( i=0; i<nyuko; i++ )
+                       {
+//                             fprintf( stderr, "allocating parttree, size = %d\n", treelen + nin * 5 );
+                               parttree[i] = calloc( treelen + nin * 5, sizeof ( char ) );
+                               strcpy( parttree[i], children[i] );
+                               free( children[i] );
+                       }
+                       free( children );
+               }
+#endif
+               if( mem1 == NULL )
+               {
+                       mem1 = AllocateIntVec( njob+1 );
+                       mem2 = AllocateIntVec( njob+1 );
+               }
+
+//             veryfastsupg_float_realloc_nobk_halfmtx( nyuko, yukomtx, topol, len );
+       
+//             counteff_simple_float( nyuko, topol, len, eff );
+
+
+               nlim = nyuko-1;
+               for( l=0; l<nlim; l++ )
+               {
+                       mem1p = topol[l][0];
+                       mptr = mem1;
+                       mem1size = 0;
+                       while( *mem1p != -1 )
+                       {
+//                             fprintf( stderr, "*mem1p = %d (%d inori), numin[]=%d\n", *mem1p, p_o_map[*mem1p], numin[*mem1p] );
+                               i = numin[*mem1p]; ptr = outs[*(mem1p++)];
+                               mem1size += i;
+                               while( i-- )
+                               {
+                                       *mptr++ = (ptr++)->numinseq;
+                               }
+                       }
+                       *mptr = -1;
+
+                       mem2p = topol[l][1];
+                       mptr = mem2;
+                       mem2size = 0;
+                       while( *mem2p != -1 )
+                       {
+//                             fprintf( stderr, "*mem2p = %d (%d inori), numin[]=%d\n", *mem2p, p_o_map[*mem2p], numin[*mem2p] );
+                               i = numin[*mem2p]; ptr = outs[*(mem2p++)];
+                               mem2size += i;
+                               while( i-- )
+                               {
+                                       *mptr++ = (ptr++)->numinseq;
+                               }
+                       }
+                       *mptr = -1;
+
+                       qsort( mem1, mem1size, sizeof( int ), (int (*)())intcompare );
+                       qsort( mem2, mem2size, sizeof( int ), (int (*)())intcompare );
+//                     selhead( mem1, numin[0] );
+//                     selhead( mem2, numin[1] );
+
+
+#if 0
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "mem1 (nin=%d) = \n", nin );
+                       for( i=0; ; i++ )
+                       {
+                               fprintf( stderr, "%d ", mem1[i]+1 );
+                               if( mem1[i] == -1 ) break;
+                       }
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "mem2 (nin=%d) = \n", nin );
+                       for( i=0; ; i++ )
+                       {
+                               fprintf( stderr, "%d ", mem2[i]+1 );
+                               if( mem2[i] == -1 ) break;
+                       }
+                       fprintf( stderr, "\n" );
+#endif
+
+#if 0
+                       fprintf( stderr, "before pairalign, l = %d, nyuko=%d, mem1size=%d, mem2size=%d\n", l, nyuko, mem1size, mem2size );
+                       fprintf( stderr, "before alignment\n" );
+                       for( j=0; j<mem1size; j++ )
+                               fprintf( stderr, "%s\n", seq[mem1[j]] );
+                       fprintf( stderr, "----\n" );
+                       for( j=0; j<mem2size; j++ )
+                               fprintf( stderr, "%s\n", seq[mem2[j]] );
+                       fprintf( stderr, "----\n\n" );
+#endif
+
+                       if( val )
+                       {
+                               fprintf( stderr, "\r  Alignment %d-%d                                 \r", mem1size, mem2size );
+                               if( *mem1 < *mem2 )
+                                       pairalign( njob, nlen, seq, mem1, mem2, weight, alloclen );
+                               else
+                                       pairalign( njob, nlen, seq, mem2, mem1, weight, alloclen );
+                       }
+
+#if TREE
+                       if( treeout )
+                       {
+                               v1 = topol[l][0][0];
+                               v2 = topol[l][1][0];
+       
+//                             fprintf( stderr, "nyuko=%d, v1=%d, v2=%d\n", nyuko, v1, v2 );
+                               if( v1 > v2 )
+                               {
+                                       v3 = v1;
+                                       v1 = v2;
+                                       v2 = v3;
+                               }
+//                             fprintf( stderr, "nyuko=%d, v1=%d, v2=%d after sort\n", nyuko, v1, v2 );
+//                             fprintf( stderr, "nyuko=%d, v1=%d, v2=%d\n", nyuko, v1, v2 );
+//                             fprintf( stderr, "v1=%d, v2=%d, parttree[v1]=%s, parttree[v2]=%s\n", v1, v2, parttree[v1], parttree[v2] );
+                               sprintf( *tree, "(%s,%s)", parttree[v1], parttree[v2] );
+                               strcpy( parttree[v1], *tree );
+//                             fprintf( stderr, "parttree[%d] = %s\n", v1, parttree[v1] );
+//                             fprintf( stderr, "*tree = %s\n", *tree );
+                               free( parttree[v2] ); parttree[v2] = NULL;
+                       }
+#endif
+
+#if 0
+                       fprintf( stderr, "after alignment\n" );
+                       for( j=0; j<mem1size; j++ )
+                               fprintf( stderr, "%s\n", seq[mem1[j]] );
+                       fprintf( stderr, "----\n" );
+                       for( j=0; j<mem2size; j++ )
+                               fprintf( stderr, "%s\n", seq[mem2[j]] );
+                       fprintf( stderr, "----\n\n" );
+#endif
+               }
+#if TREE
+               if( treeout )
+               {
+                       free( parttree[v1] ); parttree[v1] = NULL;
+//                     fprintf( stderr, "*tree = %s\n", *tree );
+//                     FreeCharMtx( parttree );
+                       free( parttree ); parttree = NULL;
+               }
+#endif
+
+#if 0
+               fprintf( stderr, "after alignment\n" );
+               for( i=0; i<nyuko; i++ )
+               {
+                       for( j=0; j<numin[i]; j++ )
+                               fprintf( stderr, "%s\n", seq[outs[i][j].numinseq] );
+               }
+#endif
+
+               if( val )
+               {
+                       groupid++;
+                       mptr = mem1; while( *mptr != -1 ) 
+                       {
+#if 0
+                               fprintf( stdout, "==g1-%d \n", *mptr+1 );
+                               fprintf( stdout, "%s \n", seq[*mptr] );
+#endif
+                               whichgroup[*mptr] = groupid;
+                               weight[*mptr++] *= 0.5;
+                       }
+       
+                       mptr = mem2; while( *mptr != -1 ) 
+                       {
+#if 0
+                               fprintf( stdout, "=g2-%d ", *mptr+1 );
+                               fprintf( stdout, "%s \n", seq[*mptr] );
+#endif
+                               whichgroup[*mptr] = groupid;
+                               weight[*mptr++] *= 0.5;
+                       }
+       
+                       if( numin[1] == 0 )
+                       {
+                               mptr = mem1; while( *mptr != -1 ) 
+                               {
+                                       whichgroup[*mptr] = groupid;
+                                       weight[*mptr++] *= (double)2.0/numin[0];
+                               }
+                       }
+               }
+               {
+                       if( *depthpt > maxdepth ) maxdepth = *depthpt;
+                       (*depthpt)++;
+               }
+       }
+       else
+       {
+#if TREE
+               if( treeout )
+               {
+                       sprintf( *tree, "%s", children[0] );
+                       free( children[0] );
+                       free( children );
+               }
+#endif
+       }
+       for( i=0; i<npick; i++ ) free( (void *)outs[i] );
+//     FreeFloatHalfMtx( pickmtx, npick );
+//     FreeFloatHalfMtx( yukomtx, npick );
+       FreeFloatMtx( len );
+       FreeIntCub( topol );
+       FreeIntVec( treeorder );
+       free( outs );
+       free( numin );
+       free( picks );
+       free( yukos );
+       free( s_p_map );
+       free( s_y_map );
+       free( p_o_map );
+       free( y_o_map );
+       free( hanni );
+       free( closeh );
+       free( pickkouho );
+       free( tsukau );
+//     free( minscoreinpick );
+       return val;
+}
+#endif
+
+static void alignparaphiles( int nseq, int *nlen, double *weight, char **seq, int nmem, int *members, int *alloclen )
+{
+       int i, ilim;
+       int *mem1 = AllocateIntVec( nmem );
+       int *mem2 = AllocateIntVec( 2 );
+
+       mem2[1] = -1;
+       ilim = nmem-1;
+       for( i=0; i<ilim; i++ )
+       {
+               mem1[i] = members[i];
+               mem1[i+1] = -1;
+               mem2[0] = members[i+1];
+               pairalign( nseq, nlen, seq, mem1, mem2, weight, alloclen );
+       }
+       free( mem1 );
+       free( mem2 );
+}
+
+
+
+
+
+
+
+
+
+
+
+int main( int argc, char *argv[] )
+{
+       static char **name, **seq, **orialn;
+       static int *grpseq;
+       static char *tmpseq;
+       static int  **pointt;
+       static int *nlen;
+       int i, st, en;
+       FILE *infp;
+       FILE *treefp;
+       char *treefile = NULL; //by Mathog
+       char c;
+       int alloclen;
+       static int *order;
+       static int *whichgroup;
+       static double *weight;
+       static char tmpname[B+100];
+       int groupnum;
+       int groupid;
+       int pos;
+       int *paramem;
+       int npara;
+       int completed;
+       int orilen;
+       int pscore;
+       char *pt;
+       int **tmpaminodis;
+       static char com[1000];
+       int depth;
+       int aan;
+
+       static Scores *scores;
+       static short *table1;
+       static char **tree;
+
+
+
+       arguments( argc, argv );
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp )
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+
+       if( picksize == NOTSPECIFIED || picksize < 2 )
+               picksize = PICKSIZE;
+
+       if( classsize == NOTSPECIFIED || classsize < 0 )
+       {
+               classsize = njob + 1;
+       }
+       else
+       {
+//             picksize = MIN( picksize, (int)sqrt( classsize ) + 1);
+       }
+
+       if( tokyoripara == NOTSPECIFIED )
+       {
+               if( doalign ) tokyoripara = TOKYORIPARA_A;
+               else tokyoripara = TOKYORIPARA;
+       }
+       if( picksize > njob )
+               tokyoripara = 0.0;
+
+
+       alloclen = nlenmax * 2;
+       name = AllocateCharMtx( njob, B+1 );
+
+       if( classsize == 1 )
+               seq = AllocateCharMtx( njob, 0 );
+       else
+               seq = AllocateCharMtx( njob, alloclen+1 );
+
+
+       nlen = AllocateIntVec( njob ); 
+       tmpseq = calloc( nlenmax+1, sizeof( char )  );
+       pointt = AllocateIntMtx( njob, 0 );
+       grpseq = AllocateIntVec( nlenmax + 1 );
+       order = (int *)calloc( njob + 1, sizeof( int ) );
+       whichgroup = (int *)calloc( njob, sizeof( int ) );
+       weight = (double *)calloc( njob, sizeof( double ) );
+
+       fprintf( stderr, "alloclen = %d in main\n", alloclen );
+
+       for( i=0; i<njob; i++ ) whichgroup[i] = 0;
+       for( i=0; i<njob; i++ ) weight[i] = 1.0;
+       for( i=0; i<njob; i++ ) order[i] = -1;
+
+       if( classsize == 1 )
+               readData_varlen( infp, name, nlen, seq );
+       else
+               readData_pointer( infp, name, nlen, seq );
+
+       fclose( infp );
+
+       if( fromaln ) doalign = 1;
+
+       if( fromaln )
+       {
+               orialn = AllocateCharMtx( njob, alloclen+1 );
+               for( i=0; i<njob; i++ )
+               {
+                       if( strlen( seq[i] ) != nlenmax )
+                       {
+                               fprintf( stderr, "Input sequences must be aligned\n" );
+                               exit( 1 );
+                       }
+                       strcpy( orialn[i], seq[i] );
+               }
+       }
+
+       constants( njob, seq );
+
+       if( dorp == 'd' ) tsize = (int)pow( 4, 6 );
+       else              tsize = (int)pow( 6, 6 );
+
+       if( dorp == 'd' )
+       {
+               lenfaca = DLENFACA;
+               lenfacb = DLENFACB;
+               lenfacc = DLENFACC;
+               lenfacd = DLENFACD;
+       }
+       else
+       {
+               lenfaca = PLENFACA;
+               lenfacb = PLENFACB;
+               lenfacc = PLENFACC;
+               lenfacd = PLENFACD;
+       }
+
+       maxl = 0;
+       for( i=0; i<njob; i++ ) 
+       {
+               gappick0( tmpseq, seq[i] );
+               nlen[i] = strlen( tmpseq );
+               strcpy( seq[i], tmpseq );
+               pointt[i] = AllocateIntVec( nlen[i]+1 ); // ??
+
+               if( nlen[i] < 6 )
+               {
+                       fprintf( stderr, "Seq %d, too short, %d characters\n", i+1, nlen[i] );
+                       fprintf( stderr, "name = %s\n", name[i] );
+                       fprintf( stderr, "seq = %s\n", seq[i] );
+                       exit( 1 );
+//                     continue;
+               }
+               if( nlen[i] > maxl ) maxl = nlen[i];
+               if( dorp == 'd' ) /* nuc */
+               {
+                       if( seq_grp_nuc( grpseq, tmpseq ) < 6 )
+                       {
+                               fprintf( stderr, "Seq %d, too short.\n", i+1 );
+                               fprintf( stderr, "name = %s\n", name[i] );
+                               fprintf( stderr, "seq = %s\n", seq[i] );
+                               exit( 1 );
+//                             continue;
+                       }
+                       makepointtable_nuc( pointt[i], grpseq );
+               }
+               else                 /* amino */
+               {
+                       if( seq_grp( grpseq, tmpseq ) < 6 )
+                       {
+                               fprintf( stderr, "Seq %d, too short.\n", i+1 );
+                               fprintf( stderr, "name = %s\n", name[i] );
+                               fprintf( stderr, "seq = %s\n", seq[i] );
+                               exit( 1 );
+//                             continue;
+                       }
+                       makepointtable( pointt[i], grpseq );
+               }
+//             fprintf( stdout, ">%s\n", name[i] );
+//             fprintf( stdout, "%s\n", seq[i] );
+       }
+//     exit( 1 );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illeagal character %c\n", c );
+               exit( 1 );
+       }
+
+       pid = (int)getpid();
+       sprintf( datafile, "/tmp/data-%d", pid );
+       sprintf( queryfile, "/tmp/query-%d", pid );
+       sprintf( resultfile, "/tmp/fasta-%d", pid );
+
+       scores = (Scores *)calloc( njob, sizeof( Scores ) );
+
+//     fprintf( stderr, "\nCalculating i-i scores ... \n" );
+       for( i=0; i<njob; i++ ) 
+       {
+               orilen = strlen( seq[i] );
+               scores[i].numinseq = i; // irimasu
+               scores[i].orilen = orilen;
+       }
+
+       if( doalign == 'f' )
+       {
+               fastapath = getenv( "FASTA_4_MAFFT" );
+               if( !fastapath ) fastapath = "fasta34";
+               fprintf( stderr, "fastapath=%s\n", fastapath );
+               tmpaminodis = AllocateIntMtx( 0x80, 0x80 );
+               getfastascoremtx( tmpaminodis );
+       }
+       else
+               tmpaminodis = NULL;
+       
+       for( i=0; i<njob; i++ )
+       {
+               scores[i].pointt = pointt[i];
+               scores[i].shimon = (int)pointt[i][0] + (int)pointt[i][1] + (int)pointt[i][scores[i].orilen-6];
+               scores[i].name = name[i];
+               if( doalign )
+               {
+                       fprintf( stderr, "\r %05d/%05d   ", i, njob );
+                       free( scores[i].pointt );
+                       if( doalign == 'f' )
+                       {
+#if 0
+#define KIZAMI 100
+                               int ipos = (int)( i / KIZAMI ) * KIZAMI;
+                               int iposamari = i % KIZAMI;
+
+                               fprintf( stderr, "%d / %d\r", i, njob );
+//                             fprintf( stderr, "ipos = %d\n", ipos );
+//                             fprintf( stderr, "iposamari = %d\n", iposamari );
+
+//                             fprintf( stderr, " calling blast, i=%d\n", i );
+//                             blastresults = callfasta( seq, scores+i, 1, 0, 1 );
+                               blastresults = callfasta( seq, scores+ipos, MIN(KIZAMI,njob-ipos), NULL, iposamari, (iposamari==0)  );
+//                             fprintf( stderr, "done., i=%d\n\n", i );
+                               scores[i].selfscore = (int)blastresults[iposamari]; 
+#if 0
+                               for( j=0; j<100; j++ )
+                               {
+                                       fprintf( stderr, "res[%d] = %f\n", j, blastresults[j] );
+                               }
+#endif
+//                             fprintf( stderr, "%d->selfscore = %d\n", i, scores[i].selfscore );
+                               free( blastresults );
+#else
+                               pscore = 0;
+                               if( scoremtx == -1 )
+                               {
+                                       st = 1;
+                                       en = 0;
+                                       for( pt=seq[i]; *pt; pt++ )
+                                       {
+                                               if( *pt == 'u' ) *pt = 't';
+                                               aan = amino_n[(int)*pt];
+                                               if( aan<0 || aan >= 4 ) *pt = 'n';
+
+                                               if( *pt == 'n' ) 
+                                               {
+                                                       en++;
+                                                       if( st ) continue;
+                                                       else pscore += tmpaminodis[(int)*pt][(int)*pt];
+                                               }
+                                               else
+                                               {
+                                                       st = 0;
+                                                       en = 0;
+                                                       pscore += tmpaminodis[(int)*pt][(int)*pt];
+                                               }
+                                       }
+                                       scores[i].selfscore = pscore - en * tmpaminodis['n']['n']; 
+                               }
+                               else
+                               {
+                                       st = 1;
+                                       en = 0;
+                                       for( pt=seq[i]; *pt; pt++ )
+                                       {
+                                               aan = amino_n[(int)*pt];
+                                               if( aan<0 || aan >= 20 ) *pt = 'X';
+                                               if( *pt == 'X' ) 
+                                               {
+                                                       en++;
+                                                       if( st ) continue;
+                                                       else pscore += tmpaminodis[(int)*pt][(int)*pt];
+                                               }
+                                               else
+                                               {
+                                                       st = 0;
+                                                       en = 0;
+                                                       pscore += tmpaminodis[(int)*pt][(int)*pt];
+                                               }
+                                       }
+                                       scores[i].selfscore = pscore - en * tmpaminodis['X']['X']; 
+                               }
+#endif
+                       }
+                       else
+                       {
+                               pscore = 0;
+                               for( pt=seq[i]; *pt; pt++ )
+                               {
+                                       pscore += amino_dis[(int)*pt][(int)*pt];
+                               }
+                               scores[i].selfscore = pscore; 
+                       }
+//                     fprintf( stderr, "selfscore[%d] = %d\n", i+1, scores[i].selfscore );
+               }
+               else
+               {
+                       table1 = (short *)calloc( tsize, sizeof( short ) );
+                       if( !table1 ) ErrorExit( "Cannot allocate table1\n" );
+                       makecompositiontable_p( table1, pointt[i] );
+                       scores[i].selfscore = commonsextet_p( table1, pointt[i] );
+                       free( table1 );
+               }
+       }
+       if( tmpaminodis ) FreeIntMtx( tmpaminodis );
+
+       depth = 0;
+#if TREE
+       if( treeout )
+       {
+               tree = (char **)calloc( 1, sizeof( char *) );
+               *tree = NULL;
+//             splitseq_bin( scores, njob, nlen, seq, name, inputfile, 0, tree, &alloclen, order, whichgroup, weight );
+               completed = splitseq_mq( scores, njob, nlen, seq, orialn, name, inputfile, 0, tree, &alloclen, order, whichgroup, weight, &depth, -1 );
+               treefile = (char *)calloc( strlen( inputfile ) + 10, sizeof( char ) );
+               if( inputfile )
+                       sprintf( treefile, "%s.tree", inputfile );
+               else
+                       sprintf( treefile, "splittbfast.tree" );
+               treefp = fopen( treefile, "w" );
+               fprintf( treefp, "%s\n", *tree );
+               fclose( treefp );
+       }
+       else
+               completed = splitseq_mq( scores, njob, nlen, seq, orialn, name, inputfile, 0, tree, &alloclen, order, whichgroup, weight, &depth, -1 );
+#else
+       completed = splitseq_mq( scores, njob, nlen, seq, orialn, name, inputfile, 0, tree, &alloclen, order, whichgroup, weight, &depth, -1 );
+#endif
+
+       fprintf( stderr, "\nDone.\n\n" );
+
+#if 1
+       groupnum = 0;
+       groupid = -1;
+       paramem = NULL;
+       npara = 0;
+       for( i=0; i<njob; i++ )
+       {
+               pos = order[i];
+               if( whichgroup[pos] != groupid )
+               {
+                       groupnum++;
+                       groupid = whichgroup[pos];
+               }
+               if( whichgroup[pos] )
+               {
+                       if( paramem )
+                       {
+                               paramem[npara] = -1;
+                               if( npara > 1 && classsize > 2 ) 
+                               {
+                                       qsort( paramem, npara, sizeof( int ), (int (*)(const void *, const void*))intcompare );
+//                                     selhead( paramem, npara );
+                                       alignparaphiles( njob, nlen, weight, seq, npara, paramem, &alloclen );
+                               }
+                               free( paramem ); paramem = NULL; npara = 0;
+                       }
+                       sprintf( tmpname, "Group-%d %s", groupnum, name[pos]+1 );
+               }
+               else
+               {
+                       paramem = realloc( paramem, sizeof( int) * ( npara + 2 ) );
+                       paramem[npara++] = pos;
+                       sprintf( tmpname, "Group-para %s", name[pos]+1 );
+               }
+               tmpname[B-1] = 0;
+               if( classsize > 1 && classsize <= njob )
+                       strcpy( name[pos]+1, tmpname );
+       }
+       if( paramem )
+       {
+               paramem[npara] = -1;
+               if( npara > 1 && classsize > 2 ) 
+               {
+                       qsort( paramem, npara, sizeof( int ), (int (*)(const void *, const void*))intcompare );
+//                     selhead( paramem, npara );
+                       alignparaphiles( njob, nlen, weight, seq, npara, paramem, &alloclen );
+               }
+               free( paramem ); paramem = NULL; npara = 0;
+       }
+#else
+       for( i=0; i<njob; i++ )
+       {
+               sprintf( tmpname, "Group-%d %s", whichgroup[i], name[i]+1 );
+               strcpy( name[i]+1, tmpname );
+       }
+#endif
+
+
+//     maketanni( name, seq,  njob, nlenmax, nlen );
+
+       fclose( trap_g );
+
+#if DEBUG
+       fprintf( stderr, "writing alignment to stdout\n" );
+#endif
+       if( reorder )
+               writeData_reorder_pointer( stdout, njob, name, nlen, seq, order );
+       else
+               writeData_pointer( stdout, njob, name, nlen, seq );
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+       if( classsize == 1 )
+       {
+               fprintf( stderr, "\n\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "nseq = %d\n", njob );
+               fprintf( stderr, "groupsize = %d, picksize=%d\n", classsize, picksize );
+               fprintf( stderr, "The input sequences have been sorted so that similar sequences are close.\n" );
+               if( reorder )
+                       fprintf( stderr, "The order of sequences has been changed according to estimated similarity.\n" );
+#if TREE
+               if( treeout )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "A guide tree is in the '%s' file.\n", treefile );
+               }
+//             else
+//             {
+//                     fprintf( stderr, "To output guide tree,\n" );
+//                     fprintf( stderr, "%% %s -t  -i %s\n", progName( argv[0] ), "inputfile" );
+//             }
+#endif
+               if( !doalign )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "mafft --dpparttree might give a better result, although slow.\n" );
+                       fprintf( stderr, "mafft --fastaparttree is also available if you have fasta34.\n" );
+               }
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+       }
+       else if( groupnum > 1 )
+       {
+               fprintf( stderr, "\n\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "groupsize = %d, picksize=%d\n", classsize, picksize );
+               fprintf( stderr, "The input sequences have been classified into %d groups + some paraphyletic groups\n", groupnum );
+               fprintf( stderr, "Note that the alignment is not completed.\n" );
+               if( reorder )
+                       fprintf( stderr, "The order of sequences has been changed according to estimated similarity.\n" );
+#if TREE
+               if( treeout )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "A guide tree is in the '%s' file.\n", treefile );
+               }
+//             else
+//             {
+//                     fprintf( stderr, "To output guide tree,\n" );
+//                     fprintf( stderr, "%% %s -t  -i %s\n", progName( argv[0] ), "inputfile" );
+//             }
+#endif
+               if( !doalign )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "mafft --dpparttree might give a better result, although slow.\n" );
+                       fprintf( stderr, "mafft --fastaparttree is also available if you have fasta34.\n" );
+               }
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+       }                       
+       else
+       {
+               fprintf( stderr, "\n\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "nseq = %d\n", njob );
+               fprintf( stderr, "groupsize = %d, partsize=%d\n", classsize, picksize );
+//             fprintf( stderr, "A single alignment containing all the input sequences has been computed.\n" );
+//             fprintf( stderr, "If the sequences are highly diverged and you feel there are too many gaps,\n" );
+//             fprintf( stderr, "please try \n" );
+//             fprintf( stderr, "%% mafft --parttree --groupsize 100 inputfile\n" );
+//             fprintf( stderr, "which classifies the sequences into several groups with <~ 100 sequences\n" );
+//             fprintf( stderr, "and performs only intra-group alignments.\n" );
+               if( reorder )
+                       fprintf( stderr, "The order of sequences has been changed according to estimated similarity.\n" );
+#if TREE
+               if( treeout )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "A guide tree is in the '%s' file.\n", treefile );
+               }
+//             else
+//             {
+//                     fprintf( stderr, "To output guide tree,\n" );
+//                     fprintf( stderr, "%% %s -t  -i %s\n", progName( argv[0] ), "inputfile" );
+//             }
+#endif
+               if( !doalign || fromaln )
+               {
+                       fprintf( stderr, "\n" );
+                       fprintf( stderr, "mafft --dpparttree might give a better result, although slow.\n" );
+                       fprintf( stderr, "mafft --fastaparttree is also available if you have fasta34.\n" );
+               }
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "----------------------------------------------------------------------------\n" );
+       }
+#if TREE
+       if( treeout ) free( treefile );
+#endif
+
+#if 0
+       fprintf( stdout, "weight =\n" );
+       for( i=0; i<njob; i++ )
+               fprintf( stdout, "%d: %f\n", i+1, weight[i] );
+#endif
+
+       if( doalign == 'f' )
+       {
+               strcpy( com, "rm -f" );
+               strcat( com, " " );
+               strcat( com, datafile );
+               strcat( com, "*  " );
+               strcat( com, queryfile );
+               strcat( com, " " );
+               strcat( com, resultfile );
+               fprintf( stderr, "%s\n", com );
+               system( com );
+       }
+
+       SHOWVERSION;
+
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/suboptalign11.c b/binaries/src/mafft/core/suboptalign11.c
new file mode 100644 (file)
index 0000000..5c1a9fe
--- /dev/null
@@ -0,0 +1,678 @@
+#include "mltaln.h"
+#include "dp.h"
+
+#define DEBUG 0
+#define DEBUG2 0
+#define XXXXXXX    0
+#define USE_PENALTY_EX  1
+
+typedef struct _shuryoten
+{
+       int i;
+       int j;
+       float wm;
+       struct _shuryoten *next;
+       struct _shuryoten *prev;
+} Shuryoten;
+
+
+static int localstop;
+
+static int compshuryo( Shuryoten *s1_arg, Shuryoten *s2_arg )
+{
+       Shuryoten *s1 = (Shuryoten *)s1_arg;
+       Shuryoten *s2 = (Shuryoten *)s2_arg;
+       if      ( s1->wm > s2->wm ) return( -1 );
+       else if ( s1->wm < s2->wm ) return( 1 );
+       else                        return( 0 );
+}
+
+static void match_calc( float *match, char **s1, char **s2, int i1, int lgth2 )
+{
+       int j;
+
+       for( j=0; j<lgth2; j++ )
+               match[j] = amino_dis[(int)(*s1)[i1]][(int)(*s2)[j]];
+}
+
+static float gentracking( int **used,
+                                               char **seq1, char **seq2, 
+                        char **mseq1, char **mseq2, 
+                        float **cpmx1, float **cpmx2, 
+                        int **ijpi, int **ijpj, int *off1pt, int *off2pt, int endi, int endj )
+{
+       int l, iin, jin, lgth1, lgth2, k, limk;
+       int ifi=0, jfi=0;
+//     char gap[] = "-";
+       char *gap;
+       gap = newgapstr;
+       static char *res1 = NULL, *res2 = NULL;
+       char *mspt1, *mspt2;
+       if( res1 == NULL )
+       {
+               res1 = (char *)calloc( N, sizeof( char ) );
+               res2 = (char *)calloc( N, sizeof( char ) );
+       }
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       mspt1 = res1 + lgth1+lgth2;
+       *mspt1 = 0;
+       mspt2 = res2 + lgth1+lgth2;
+       *mspt2 = 0;
+       iin = endi; jin = endj;
+
+       limk = lgth1+lgth2;
+       if( used[iin][jin] ) return( -1.0 );
+       for( k=0; k<=limk; k++ ) 
+       {
+               ifi = ( ijpi[iin][jin] );
+               jfi = ( ijpj[iin][jin] );
+
+               if( used[ifi][jfi] ) return( -1.0 );
+
+               l = iin - ifi;
+               while( --l ) 
+               {
+                       *--mspt1 = seq1[0][ifi+l];
+                       *--mspt2 = *gap;
+                       k++;
+               }
+               l= jin - jfi;
+               while( --l )
+               {
+                       *--mspt1 = *gap;
+                       *--mspt2 = seq2[0][jfi+l];
+                       k++;
+               }
+
+               if( iin <= 0 || jin <= 0 ) break;
+               *--mspt1 = seq1[0][ifi];
+               *--mspt2 = seq2[0][jfi];
+               if( ijpi[ifi][jfi] == localstop ) break;
+               if( ijpj[ifi][jfi] == localstop ) break;
+               k++;
+               iin = ifi; jin = jfi;
+       }
+       if( ifi == -1 ) *off1pt = 0; else *off1pt = ifi;
+       if( jfi == -1 ) *off2pt = 0; else *off2pt = jfi;
+
+//     fprintf( stderr, "ifn = %d, jfn = %d\n", ifi, jfi );
+
+       iin = endi; jin = endj;
+       limk = lgth1+lgth2;
+       for( k=0; k<=limk; k++ ) 
+       {
+               ifi = ( ijpi[iin][jin] );
+               jfi = ( ijpj[iin][jin] );
+
+               used[ifi][jfi] = 1;
+               if( iin <= 0 || jin <= 0 ) break;
+               if( ijpi[ifi][jfi] == localstop ) break;
+               if( ijpj[ifi][jfi] == localstop ) break;
+
+               k++;
+               iin = ifi; jin = jfi;
+       }
+
+
+       strcpy( mseq1[0], mspt1 );
+       strcpy( mseq2[0], mspt2 );
+
+       fprintf( stderr, "mseq1=%s\nmseq2=%s\n", mspt1, mspt2 );
+
+       return( 0.0 );
+}
+
+
+float suboptalign11( char **seq1, char **seq2, int alloclen, int *off1pt, int *off2pt, LocalHom *lhmpt )
+/* score no keisan no sai motokaraaru gap no atukai ni mondai ga aru */
+{
+       int k;
+       static int **used;
+       register int i, j;
+       int lasti, lastj;                      /* outgap == 0 -> lgth1, outgap == 1 -> lgth1+1 */
+       int lgth1, lgth2;
+       int resultlen;
+       float wm = 0.0;   // by D.Mathog, 
+       float g;
+       float *currentw, *previousw;
+#if 1
+       float *wtmp;
+       int *ijpipt;
+       int *ijpjpt;
+       float *mjpt, *Mjpt, *prept, *curpt;
+       int *mpjpt, *Mpjpt;
+#endif
+       static float mi, *m;
+       static float Mi, *largeM;
+       static int **ijpi;
+       static int **ijpj;
+       static int mpi, *mp;
+       static int Mpi, *Mp;
+       static float *w1, *w2;
+//     static float *match;
+       static float *initverticalw;    /* kufuu sureba iranai */
+       static float *lastverticalw;    /* kufuu sureba iranai */
+       static char **mseq1;
+       static char **mseq2;
+       static float **cpmx1;
+       static float **cpmx2;
+       static int **intwork;
+       static float **floatwork;
+       static int orlgth1 = 0, orlgth2 = 0;
+       float maxwm;
+       float tbk;
+       int tbki, tbkj;
+       int endali, endalj;
+//     float localthr = 0.0;
+//     float localthr2 = 0.0;
+       float fpenalty = (float)penalty;
+       float fpenalty_OP = (float)penalty_OP;
+       float fpenalty_ex = (float)penalty_ex;
+//     float fpenalty_EX = (float)penalty_EX;
+       float foffset = (float)offset;
+       float localthr = -foffset;
+       float localthr2 = -foffset;
+       static Shuryoten *shuryo = NULL;
+       int numshuryo;
+       float minshuryowm = 0.0; // by D.Mathog
+       int minshuryopos = 0; // by D.Mathog
+       float resf;
+
+
+//     fprintf( stderr, "@@@@@@@@@@@@@ penalty_OP = %f, penalty_EX = %f, pelanty = %f\n", fpenalty_OP, fpenalty_EX, fpenalty );
+
+       fprintf( stderr, "in suboptalign11\n" );
+       if( !shuryo )
+       {
+               shuryo = (Shuryoten *)calloc( 100, sizeof( Shuryoten ) );
+       }
+       for( i=0; i<100; i++ )
+       {
+               shuryo[i].i = -1;
+               shuryo[i].j = -1;
+               shuryo[i].wm = 0.0;
+       }
+       numshuryo = 0;
+
+       if( orlgth1 == 0 )
+       {
+       }
+
+
+       lgth1 = strlen( seq1[0] );
+       lgth2 = strlen( seq2[0] );
+
+       fprintf( stderr, "in suboptalign11 step 1\n" );
+
+       if( lgth1 > orlgth1 || lgth2 > orlgth2 )
+       {
+               int ll1, ll2;
+
+       fprintf( stderr, "in suboptalign11 step 1.3\n" );
+               if( orlgth1 > 0 && orlgth2 > 0 )
+               {
+       fprintf( stderr, "in suboptalign11 step 1.4\n" );
+                       FreeFloatVec( w1 );
+                       FreeFloatVec( w2 );
+//                     FreeFloatVec( match );
+                       FreeFloatVec( initverticalw );
+                       FreeFloatVec( lastverticalw );
+       fprintf( stderr, "in suboptalign11 step 1.5\n" );
+
+                       FreeFloatVec( m );
+                       FreeIntVec( mp );
+                       FreeFloatVec( largeM );
+                       FreeIntVec( Mp );
+       fprintf( stderr, "in suboptalign11 step 1.6\n" );
+
+
+                       FreeFloatMtx( cpmx1 );
+                       FreeFloatMtx( cpmx2 );
+
+       fprintf( stderr, "in suboptalign11 step 1.7\n" );
+                       FreeFloatMtx( floatwork );
+                       FreeIntMtx( intwork );
+               }
+
+               ll1 = MAX( (int)(1.3*lgth1), orlgth1 ) + 100;
+               ll2 = MAX( (int)(1.3*lgth2), orlgth2 ) + 100;
+
+#if DEBUG
+               fprintf( stderr, "\ntrying to allocate (%d+%d)xn matrices ... ", ll1, ll2 );
+#endif
+
+               w1 = AllocateFloatVec( ll2+2 );
+               w2 = AllocateFloatVec( ll2+2 );
+//             match = AllocateFloatVec( ll2+2 );
+
+               initverticalw = AllocateFloatVec( ll1+2 );
+               lastverticalw = AllocateFloatVec( ll1+2 );
+
+               m = AllocateFloatVec( ll2+2 );
+               mp = AllocateIntVec( ll2+2 );
+               largeM = AllocateFloatVec( ll2+2 );
+               Mp = AllocateIntVec( ll2+2 );
+
+               cpmx1 = AllocateFloatMtx( 26, ll1+2 );
+               cpmx2 = AllocateFloatMtx( 26, ll2+2 );
+
+               floatwork = AllocateFloatMtx( 26, MAX( ll1, ll2 )+2 ); 
+               intwork = AllocateIntMtx( 26, MAX( ll1, ll2 )+2 ); 
+
+               mseq1 = AllocateCharMtx( njob, ll1+ll2 );
+               mseq2 = AllocateCharMtx( njob, ll1+ll2 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n" );
+#endif
+
+               orlgth1 = ll1 - 100;
+               orlgth2 = ll2 - 100;
+       }
+       fprintf( stderr, "in suboptalign11 step 1.6\n" );
+
+
+
+       fprintf( stderr, "in suboptalign11 step 2\n" );
+
+       if( orlgth1 > commonAlloc1 || orlgth2 > commonAlloc2 )
+       {
+               int ll1, ll2;
+
+               if( commonAlloc1 && commonAlloc2 )
+               {
+                       FreeIntMtx( commonIP );
+                       FreeIntMtx( commonJP );
+                       FreeIntMtx( used );
+               }
+
+               ll1 = MAX( orlgth1, commonAlloc1 );
+               ll2 = MAX( orlgth2, commonAlloc2 );
+
+#if DEBUG
+               fprintf( stderr, "\n\ntrying to allocate %dx%d matrices ... ", ll1+1, ll2+1 );
+#endif
+
+               used = AllocateIntMtx( ll1+10, ll2+10 );
+               commonIP = AllocateIntMtx( ll1+10, ll2+10 );
+               commonJP = AllocateIntMtx( ll1+10, ll2+10 );
+
+#if DEBUG
+               fprintf( stderr, "succeeded\n\n" );
+#endif
+
+               commonAlloc1 = ll1;
+               commonAlloc2 = ll2;
+       }
+       ijpi = commonIP;
+       ijpj = commonJP;
+
+
+#if 0
+       for( i=0; i<lgth1; i++ ) 
+               fprintf( stderr, "ogcp1[%d]=%f\n", i, ogcp1[i] );
+#endif
+
+       fprintf( stderr, "in suboptalign11 step 3\n" );
+       currentw = w1;
+       previousw = w2;
+
+       match_calc( initverticalw, seq2, seq1, 0, lgth1 );
+
+       match_calc( currentw, seq1, seq2, 0, lgth2 );
+
+
+       lasti = lgth2+1;
+       for( j=1; j<lasti; ++j ) 
+       {
+               m[j] = currentw[j-1]; mp[j] = 0;
+               largeM[j] = currentw[j-1]; Mp[j] = 0;
+       }
+
+       lastverticalw[0] = currentw[lgth2-1];
+
+
+#if 0
+fprintf( stderr, "currentw = \n" );
+for( i=0; i<lgth1+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[i] );
+}
+fprintf( stderr, "\n" );
+fprintf( stderr, "initverticalw = \n" );
+for( i=0; i<lgth2+1; i++ )
+{
+       fprintf( stderr, "%5.2f ", initverticalw[i] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "       " );
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%c     ", seq2[0][j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       localstop = lgth1+lgth2+1;
+       maxwm = -999.9;
+       endali = endalj = 0;
+#if DEBUG2
+       fprintf( stderr, "\n" );
+       fprintf( stderr, "%c   ", seq1[0][0] );
+
+       for( j=0; j<lgth2+1; j++ )
+               fprintf( stderr, "%5.0f ", currentw[j] );
+       fprintf( stderr, "\n" );
+#endif
+
+       lasti = lgth1+1;
+       for( i=1; i<lasti; i++ )
+       {
+               wtmp = previousw; 
+               previousw = currentw;
+               currentw = wtmp;
+
+               previousw[0] = initverticalw[i-1];
+
+               match_calc( currentw, seq1, seq2, i, lgth2 );
+#if DEBUG2
+               fprintf( stderr, "%c   ", seq1[0][i] );
+               fprintf( stderr, "%5.0f ", currentw[0] );
+#endif
+
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+#if XXXXXXX
+fprintf( stderr, "\n" );
+fprintf( stderr, "i=%d\n", i );
+fprintf( stderr, "currentw = \n" );
+for( j=0; j<lgth2; j++ )
+{
+       fprintf( stderr, "%5.2f ", currentw[j] );
+}
+fprintf( stderr, "\n" );
+#endif
+               currentw[0] = initverticalw[i];
+
+               mi = previousw[0]; mpi = 0;
+               Mi = previousw[0]; Mpi = 0;
+
+#if 0
+               if( mi < localthr ) mi = localthr2;
+#endif
+
+               ijpipt = ijpi[i] + 1;
+               ijpjpt = ijpj[i] + 1;
+               mjpt = m + 1;
+               Mjpt = largeM + 1;
+               prept = previousw;
+               curpt = currentw + 1;
+               mpjpt = mp + 1;
+               Mpjpt = Mp + 1;
+               tbk = -999999.9;
+               tbki = 0;
+               tbkj = 0;
+               lastj = lgth2+1;
+               for( j=1; j<lastj; j++ )
+               {
+                       wm = *prept;
+                       *ijpipt = i-1;
+                       *ijpjpt = j-1;
+
+
+//                     fprintf( stderr, "i,j=%d,%d %c-%c\n", i, j, seq1[0][i], seq2[0][j] );
+//                     fprintf( stderr, "wm=%f\n", wm );
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = mi + fpenalty;
+#if 0
+                       fprintf( stderr, "%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+//                             *ijpipt = i - 1;
+                               *ijpjpt = mpi;
+                       }
+                       g = *prept;
+                       if( g > mi )
+                       {
+                               mi = g;
+                               mpi = j-1;
+                       }
+
+#if USE_PENALTY_EX
+                       mi += fpenalty_ex;
+#endif
+
+#if 0
+                       fprintf( stderr, "%5.0f->", wm );
+#endif
+                       g = *mjpt + fpenalty;
+#if 0
+                       fprintf( stderr, "m%5.0f?", g );
+#endif
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijpipt = *mpjpt;
+//                             *ijpjpt = j - 1;
+                       }
+                       g = *prept;
+                       if( g > *mjpt )
+                       {
+                               *mjpt = g;
+                               *mpjpt = i-1;
+                       }
+#if USE_PENALTY_EX
+                       *mjpt += fpenalty_ex;
+#endif
+
+
+                       g =  tbk + fpenalty_OP;
+//                     g =  tbk;
+                       if( g > wm )
+                       {
+                               wm = g;
+                               *ijpipt = tbki;
+                               *ijpjpt = tbkj;
+//                             fprintf( stderr, "hit! i%d, j%d, ijpi = %d, ijpj = %d\n", i, j, *ijpipt, *ijpjpt );
+                       }
+                       g = Mi;
+                       if( g > tbk )
+                       {
+                               tbk = g;
+                               tbki = i-1;
+                               tbkj = Mpi;
+                       }
+                       g = *Mjpt;
+                       if( g > tbk )
+                       {
+                               tbk = g;
+                               tbki = *Mpjpt;
+                               tbkj = j-1;
+                       }
+//                     tbk += fpenalty_EX;// + foffset;
+
+                       g = *prept;
+                       if( g > *Mjpt )
+                       {
+                               *Mjpt = g;
+                               *Mpjpt = i-1;
+                       }
+//                     *Mjpt += fpenalty_EX;// + foffset;
+
+                       g = *prept;
+                       if( g > Mi )
+                       {
+                               Mi = g;
+                               Mpi = j-1;
+                       }
+//                     Mi += fpenalty_EX;// + foffset;
+
+
+//                     fprintf( stderr, "wm=%f, tbk=%f(%c-%c), mi=%f, *mjpt=%f\n", wm, tbk, seq1[0][tbki], seq2[0][tbkj], mi, *mjpt );
+//                     fprintf( stderr, "ijp = %c,%c\n", seq1[0][abs(*ijpipt)], seq2[0][abs(*ijpjpt)] );
+
+
+                       if( maxwm < wm )
+                       {
+                               maxwm = wm;
+                               endali = i;
+                               endalj = j;
+                       }
+
+#if 1
+                       if( numshuryo < 100 )
+                       {
+                               shuryo[numshuryo].i = i;
+                               shuryo[numshuryo].j = j;
+                               shuryo[numshuryo].wm = wm;
+
+                               if( minshuryowm > wm )
+                               {
+                                        minshuryowm = wm;
+                                        minshuryopos = numshuryo;
+                               }
+                               numshuryo++;
+                       }
+                       else
+                       {
+                               if( wm > minshuryowm )
+                               {
+                                       shuryo[minshuryopos].i = i;
+                                       shuryo[minshuryopos].j = j;
+                                       shuryo[minshuryopos].wm = wm;
+                                       minshuryowm = wm;
+                                       for( k=0; k<100; k++ )    // muda
+                                       {
+                                               if( shuryo[k].wm < minshuryowm )
+                                               {
+                                                       minshuryowm = shuryo[k].wm;
+                                                       minshuryopos = k;
+                                                       break;
+                                               }
+                                       }
+                               }
+                       }
+#endif
+#if 1
+                       if( wm < localthr )
+                       {
+//                             fprintf( stderr, "stop i=%d, j=%d, curpt=%f\n", i, j, *curpt );
+                               *ijpipt = localstop;
+//                             *ijpjpt = localstop;
+                               wm = localthr2;
+                       }
+#endif
+#if 0
+                       fprintf( stderr, "%5.0f ", *curpt );
+#endif
+#if DEBUG2
+                       fprintf( stderr, "%5.0f ", wm );
+//                     fprintf( stderr, "%c-%c *ijppt = %d, localstop = %d\n", seq1[0][i], seq2[0][j], *ijppt, localstop );
+#endif
+
+                       *curpt += wm;
+                       ijpipt++;
+                       ijpjpt++;
+                       mjpt++;
+                       Mjpt++;
+                       prept++;
+                       mpjpt++;
+                       Mpjpt++;
+                       curpt++;
+               }
+#if DEBUG2
+               fprintf( stderr, "\n" );
+#endif
+
+               lastverticalw[i] = currentw[lgth2-1];
+       }
+
+       for( k=0; k<100; k++ )
+       {
+               fprintf( stderr, "shuryo[%d].i,j,wm = %d,%d,%f\n", k, shuryo[k].i, shuryo[k].j, shuryo[k].wm );
+       }
+
+
+#if 1
+       fprintf( stderr, "maxwm = %f\n", maxwm );
+       fprintf( stderr, "endali = %d\n", endali );
+       fprintf( stderr, "endalj = %d\n", endalj );
+#endif
+
+       qsort( shuryo, 100, sizeof( Shuryoten ), (int (*)())compshuryo );
+       for( k=0; k<100; k++ )
+       {
+               fprintf( stderr, "shuryo[%d].i,j,wm = %d,%d,%f\n", k, shuryo[k].i, shuryo[k].j, shuryo[k].wm );
+       }
+
+               
+       lasti = lgth1+1;
+    for( i=0; i<lasti; i++ ) 
+    {
+        ijpi[i][0] = localstop;
+        ijpj[i][0] = localstop;
+    }
+       lastj = lgth2+1;
+    for( j=0; j<lastj; j++ ) 
+    {
+        ijpi[0][j] = localstop;
+        ijpj[0][j] = localstop;
+    }
+
+       for( i=0; i<lasti; i++ ) for( j=0; j<lastj; j++ ) used[i][j] = 0;
+
+       for( k=0; k<numshuryo; k++ )
+       {
+               if( shuryo[k].wm < shuryo[0].wm * 0.3 ) break;
+               fprintf( stderr, "k=%d, shuryo[k].i,j,wm=%d,%d,%f go\n", k, shuryo[k].i, shuryo[k].j, shuryo[k].wm );
+               resf = gentracking( used, seq1, seq2, mseq1, mseq2, cpmx1, cpmx2, ijpi, ijpj, off1pt, off2pt, shuryo[k].i, shuryo[k].j );
+               if( resf == -1.0 ) continue;
+               putlocalhom3( mseq1[0], mseq2[0], lhmpt, *off1pt, *off2pt, (int)shuryo[k].wm, strlen( mseq1[0] ) );
+#if 0
+               fprintf( stderr, "\n" );
+               fprintf( stderr, ">\n%s\n", mseq1[0] );
+               fprintf( stderr, ">\n%s\n", mseq2[0] );
+#endif
+       }
+       for( i=0; i<20; i++ )
+       {
+               for( j=0; j<20; j++ )
+               {
+                       fprintf( stderr, "%2d ", used[i][j] );
+               }
+               fprintf( stderr, "\n" );
+       }
+
+
+//     fprintf( stderr, "### impmatch = %f\n", *impmatch );
+
+       resultlen = strlen( mseq1[0] );
+       if( alloclen < resultlen || resultlen > N )
+       {
+               fprintf( stderr, "alloclen=%d, resultlen=%d, N=%d\n", alloclen, resultlen, N );
+               ErrorExit( "LENGTH OVER!\n" );
+       }
+
+
+
+
+
+       return( wm );
+}
+
diff --git a/binaries/src/mafft/core/tbfast.c b/binaries/src/mafft/core/tbfast.c
new file mode 100644 (file)
index 0000000..6acce28
--- /dev/null
@@ -0,0 +1,1880 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+#define IODEBUG 0
+#define SCOREOUT 0
+
+static int nadd;
+static int treein;
+static int topin;
+static int treeout;
+static int distout;
+static int noalign;
+
+typedef struct _jobtable
+{
+    int i;  
+    int j;  
+} Jobtable;
+
+#ifdef enablemultithread
+typedef struct _distancematrixthread_arg
+{
+       int njob;
+       int thread_no;
+       float *selfscore;
+       float **iscore;
+       char **seq;
+       Jobtable *jobpospt;
+       pthread_mutex_t *mutex;
+} distancematrixthread_arg_t;
+
+typedef struct _treebasethread_arg
+{
+       int thread_no;
+       int *nrunpt;
+       int njob;
+       int *nlen;
+       int *jobpospt;
+       int ***topol;
+       Treedep *dep;
+       char **aseq;
+       double *effarr;
+       int *alloclenpt;
+       LocalHom **localhomtable;
+       RNApair ***singlerna;
+       double *effarr_kozo;
+       int *fftlog;
+       pthread_mutex_t *mutex;
+       pthread_cond_t *treecond;
+} treebasethread_arg_t;
+#endif
+
+void arguments( int argc, char *argv[] )
+{
+    int c;
+
+       nthread = 1;
+       outnumber = 0;
+       scoreout = 0;
+       treein = 0;
+       topin = 0;
+       rnaprediction = 'm';
+       rnakozo = 0;
+       nevermemsave = 0;
+       inputfile = NULL;
+       addfile = NULL;
+       addprofile = 1;
+       fftkeika = 0;
+       constraint = 0;
+       nblosum = 62;
+       fmodel = 0;
+       calledByXced = 0;
+       devide = 0;
+       use_fft = 0; // chuui
+       force_fft = 0;
+       fftscore = 1;
+       fftRepeatStop = 0;
+       fftNoAnchStop = 0;
+    weight = 3;
+    utree = 1;
+       tbutree = 1;
+    refine = 0;
+    check = 1;
+    cut = 0.0;
+    disp = 0;
+    outgap = 1;
+    alg = 'A';
+    mix = 0;
+       tbitr = 0;
+       scmtd = 5;
+       tbweight = 0;
+       tbrweight = 3;
+       checkC = 0;
+       treemethod = 'X';
+       contin = 0;
+       scoremtx = 1;
+       kobetsubunkatsu = 0;
+       dorp = NOTSPECIFIED;
+       ppenalty = NOTSPECIFIED;
+       ppenalty_ex = NOTSPECIFIED;
+       poffset = NOTSPECIFIED;
+       kimuraR = NOTSPECIFIED;
+       pamN = NOTSPECIFIED;
+       geta2 = GETA2;
+       fftWinSize = NOTSPECIFIED;
+       fftThreshold = NOTSPECIFIED;
+       RNAppenalty = NOTSPECIFIED;
+       RNAppenalty_ex = NOTSPECIFIED;
+       RNApthr = NOTSPECIFIED;
+       TMorJTT = JTT;
+       consweight_multi = 1.0;
+       consweight_rna = 0.0;
+
+    while( --argc > 0 && (*++argv)[0] == '-' )
+       {
+        while ( ( c = *++argv[0] ) )
+               {
+            switch( c )
+            {
+                               case 'i':
+                                       inputfile = *++argv;
+                                       fprintf( stderr, "inputfile = %s\n", inputfile );
+                                       --argc;
+                    goto nextoption;
+                               case 'I':
+                                       nadd = atoi( *++argv );
+                                       fprintf( stderr, "nadd = %d\n", nadd );
+                                       --argc;
+                                       goto nextoption;
+                               case 'e':
+                                       RNApthr = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'o':
+                                       RNAppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       --argc;
+                                       goto nextoption;
+                               case 'f':
+                                       ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "ppenalty = %d\n", ppenalty );
+                                       --argc;
+                                       goto nextoption;
+                               case 'g':
+                                       ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
+                                       fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
+                                       --argc;
+                                       goto nextoption;
+                               case 'h':
+                                       poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
+//                                     fprintf( stderr, "poffset = %d\n", poffset );
+                                       --argc;
+                                       goto nextoption;
+                               case 'k':
+                                       kimuraR = atoi( *++argv );
+                                       fprintf( stderr, "kappa = %d\n", kimuraR );
+                                       --argc;
+                                       goto nextoption;
+                               case 'b':
+                                       nblosum = atoi( *++argv );
+                                       scoremtx = 1;
+                                       fprintf( stderr, "blosum %d / kimura 200\n", nblosum );
+                                       --argc;
+                                       goto nextoption;
+                               case 'j':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = JTT;
+                                       fprintf( stderr, "jtt/kimura %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'm':
+                                       pamN = atoi( *++argv );
+                                       scoremtx = 0;
+                                       TMorJTT = TM;
+                                       fprintf( stderr, "tm %d\n", pamN );
+                                       --argc;
+                                       goto nextoption;
+                               case 'l':
+                                       fastathreshold = atof( *++argv );
+                                       constraint = 2;
+                                       --argc;
+                                       goto nextoption;
+                               case 'r':
+                                       consweight_rna = atof( *++argv );
+                                       rnakozo = 1;
+                                       --argc;
+                                       goto nextoption;
+                               case 'c':
+                                       consweight_multi = atof( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'C':
+                                       nthread = atoi( *++argv );
+                                       fprintf( stderr, "nthread = %d\n", nthread );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'R':
+                                       rnaprediction = 'r';
+                                       break;
+                               case 's':
+                                       RNAscoremtx = 'r';
+                                       break;
+#if 1
+                               case 'a':
+                                       fmodel = 1;
+                                       break;
+#endif
+                               case 'K':
+                                       addprofile = 0;
+                                       break;
+                               case 'y':
+                                       distout = 1;
+                                       break;
+                               case 't':
+                                       treeout = 1;
+                                       break;
+                               case 'T':
+                                       noalign = 1;
+                                       break;
+                               case 'D':
+                                       dorp = 'd';
+                                       break;
+                               case 'P':
+                                       dorp = 'p';
+                                       break;
+#if 1
+                               case 'O':
+                                       outgap = 0;
+                                       break;
+#else
+                               case 'O':
+                                       fftNoAnchStop = 1;
+                                       break;
+#endif
+                               case 'S':
+                                       scoreout = 1;
+                                       break;
+#if 0
+                               case 'e':
+                                       fftscore = 0;
+                                       break;
+                               case 'r':
+                                       fmodel = -1;
+                                       break;
+                               case 'R':
+                                       fftRepeatStop = 1;
+                                       break;
+                               case 's':
+                                       treemethod = 's';
+                                       break;
+#endif
+                               case 'X':
+                                       treemethod = 'X';
+                                       break;
+                               case 'E':
+                                       treemethod = 'E';
+                                       break;
+                               case 'q':
+                                       treemethod = 'q';
+                                       break;
+                               case 'n' :
+                                       outnumber = 1;
+                                       break;
+#if 0
+                               case 'a':
+                                       alg = 'a';
+                                       break;
+#endif
+                               case 'Q':
+                                       alg = 'Q';
+                                       break;
+                               case 'H':
+                                       alg = 'H';
+                                       break;
+                               case 'A':
+                                       alg = 'A';
+                                       break;
+                               case 'M':
+                                       alg = 'M';
+                                       break;
+                               case 'N':
+                                       nevermemsave = 1;
+                                       break;
+                               case 'B':
+                                       break;
+                               case 'F':
+                                       use_fft = 1;
+                                       break;
+                               case 'G':
+                                       force_fft = 1;
+                                       use_fft = 1;
+                                       break;
+                               case 'U':
+                                       treein = 1;
+                                       break;
+                               case 'V':
+                                       topin = 1;
+                                       break;
+                               case 'u':
+                                       tbrweight = 0;
+                                       weight = 0;
+                                       break;
+                               case 'v':
+                                       tbrweight = 3;
+                                       break;
+                               case 'd':
+                                       disp = 1;
+                                       break;
+/* Modified 01/08/27, default: user tree */
+                               case 'J':
+                                       tbutree = 0;
+                                       break;
+/* modification end. */
+                               case 'z':
+                                       fftThreshold = atoi( *++argv );
+                                       --argc; 
+                                       goto nextoption;
+                               case 'w':
+                                       fftWinSize = atoi( *++argv );
+                                       --argc;
+                                       goto nextoption;
+                               case 'Z':
+                                       checkC = 1;
+                                       break;
+                default:
+                    fprintf( stderr, "illegal option %c\n", c );
+                    argc = 0;
+                    break;
+            }
+               }
+               nextoption:
+                       ;
+       }
+    if( argc == 1 )
+    {
+        cut = atof( (*argv) );
+        argc--;
+    }
+    if( argc != 0 ) 
+    {
+        fprintf( stderr, "options: Check source file !\n" );
+        exit( 1 );
+    }
+       if( tbitr == 1 && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : o, m or u\n" );
+               exit( 1 );
+       }
+       if( alg == 'C' && outgap == 0 )
+       {
+               fprintf( stderr, "conflicting options : C, o\n" );
+               exit( 1 );
+       }
+}
+
+#if 0
+static void *distancematrixthread2( void *arg )
+{
+       distancematrixthread_arg_t *targ = (distancematrixthread_arg_t *)arg;
+       int njob = targ->njob;
+       int thread_no = targ->thread_no;
+       float *selfscore = targ->selfscore;
+       float **iscore = targ->iscore;
+       char **seq = targ->seq;
+       Jobtable *jobpospt = targ->jobpospt;
+
+       float ssi, ssj, bunbo;
+       int i, j;
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               i = jobpospt->i;
+               i++;
+               if( i == njob-1 )
+               {
+                       pthread_mutex_unlock( targ->mutex );
+                       return( NULL );
+               }
+               jobpospt->i = i;
+               pthread_mutex_unlock( targ->mutex );
+
+               ssi = selfscore[i];
+               if( i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no );
+               for( j=i+1; j<njob; j++)
+               {
+                       ssj = selfscore[j];
+                       bunbo = MIN( ssi, ssj );
+                       if( bunbo == 0.0 )
+                               iscore[i][j-i] = 1.0;
+                       else
+                               iscore[i][j-i] = 1.0 - naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
+               }
+       }
+}
+#endif
+
+#ifdef enablemultithread
+static void *distancematrixthread( void *arg )
+{
+       distancematrixthread_arg_t *targ = (distancematrixthread_arg_t *)arg;
+       int njob = targ->njob;
+       int thread_no = targ->thread_no;
+       float *selfscore = targ->selfscore;
+       float **iscore = targ->iscore;
+       char **seq = targ->seq;
+       Jobtable *jobpospt = targ->jobpospt;
+
+       float ssi, ssj, bunbo;
+       int i, j;
+
+       while( 1 )
+       {
+               pthread_mutex_lock( targ->mutex );
+               j = jobpospt->j;
+               i = jobpospt->i;
+               j++;
+               if( j == njob )
+               {
+                       i++;
+                       j = i + 1;
+                       if( i == njob-1 )
+                       {
+                               pthread_mutex_unlock( targ->mutex );
+                               return( NULL );
+                       }
+               }
+               jobpospt->j = j;
+               jobpospt->i = i;
+               pthread_mutex_unlock( targ->mutex );
+
+
+               if( j==i+1 && i % 10 == 0 ) fprintf( stderr, "\r% 5d / %d (thread %4d)", i, njob, thread_no );
+               ssi = selfscore[i];
+               ssj = selfscore[j];
+               bunbo = MIN( ssi, ssj );
+               if( bunbo == 0.0 )
+                       iscore[i][j-i] = 1.0;
+               else
+                       iscore[i][j-i] = 1.0 - naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
+       }
+}
+
+static void *treebasethread( void *arg )
+{
+       treebasethread_arg_t *targ = (treebasethread_arg_t *)arg;
+       int *nrunpt = targ->nrunpt;
+       int thread_no = targ->thread_no;
+       int njob = targ->njob;
+       int *nlen = targ->nlen;
+       int *jobpospt = targ->jobpospt;
+       int ***topol = targ->topol;
+       Treedep *dep = targ->dep;
+       char **aseq = targ->aseq;
+       double *effarr = targ->effarr;
+       int *alloclen = targ->alloclenpt;
+       LocalHom **localhomtable = targ->localhomtable;
+       RNApair ***singlerna = targ->singlerna;
+       double *effarr_kozo = targ->effarr_kozo;
+       int *fftlog = targ->fftlog;
+
+       char **mseq1, **mseq2;
+       char **localcopy;
+       int i, j, l;
+       int len1, len2;
+       int clus1, clus2;
+       float pscore;
+       char *indication1, *indication2;
+       double *effarr1 = NULL;
+       double *effarr2 = NULL;
+       double *effarr1_kozo = NULL;
+       double *effarr2_kozo = NULL;
+       LocalHom ***localhomshrink = NULL;
+       int m1, m2;
+       float dumfl = 0.0;
+       int ffttry;
+       RNApair ***grouprna1, ***grouprna2;
+
+
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+       localcopy = calloc( njob, sizeof( char * ) );
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       }
+       else
+       {
+               grouprna1 = grouprna2 = NULL;
+       }
+
+       effarr1 = AllocateDoubleVec( njob );
+       effarr2 = AllocateDoubleVec( njob );
+       indication1 = AllocateCharVec( 150 );
+       indication2 = AllocateCharVec( 150 );
+#if 0
+#else
+       if( constraint )
+       {
+               localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) );
+               for( i=0; i<njob; i++)
+                       localhomshrink[i] = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+       }
+#endif
+       effarr1_kozo = AllocateDoubleVec( njob ); //tsuneni allocate sareru.
+       effarr2_kozo = AllocateDoubleVec( njob ); //tsuneni allocate sareru.
+       for( i=0; i<njob; i++ ) effarr1_kozo[i] = 0.0;
+       for( i=0; i<njob; i++ ) effarr2_kozo[i] = 0.0;
+
+
+#if 0
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+#if 0 //-> main thread
+       if( constraint )
+               calcimportance( njob, effarr, aseq, localhomtable );
+#endif
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+
+//     for( l=0; l<njob-1; l++ )
+       while( 1 )
+       {
+
+               pthread_mutex_lock( targ->mutex );
+               l = *jobpospt;
+               if( l == njob-1 )
+               {
+                       pthread_mutex_unlock( targ->mutex );
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonIP = NULL;
+                       Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL );
+                       A__align( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, 0 );
+                       free( mseq1 );
+                       free( mseq2 );
+                       free( localcopy );
+                       free( effarr1 );
+                       free( effarr2 );
+                       free( effarr1_kozo );
+                       free( effarr2_kozo );
+                       free( indication1 );
+                       free( indication2 );
+                       if( constraint )
+                       {
+                               for( i=0; i<njob; i++)
+                                       free( localhomshrink[i] );
+                               free( localhomshrink );
+                       }
+                       return( NULL );
+               }
+               *jobpospt = l+1;
+
+               if( dep[l].child0 != -1 )
+               {
+                       while( dep[dep[l].child0].done == 0 )
+                               pthread_cond_wait( targ->treecond, targ->mutex );
+               }
+               if( dep[l].child1 != -1 )
+               {
+                       while( dep[dep[l].child1].done == 0 )
+                               pthread_cond_wait( targ->treecond, targ->mutex );
+               }
+//             while( *nrunpt >= nthread )
+//                     pthread_cond_wait( targ->treecond, targ->mutex );
+               (*nrunpt)++;
+
+//             pthread_mutex_unlock( targ->mutex );
+
+
+               m1 = topol[l][0][0];
+               m2 = topol[l][1][0];
+
+//             pthread_mutex_lock( targ->mutex );
+
+        len1 = strlen( aseq[m1] );
+        len2 = strlen( aseq[m2] );
+        if( *alloclen <= len1 + len2 )
+        {
+                       fprintf( stderr, "\nReallocating (by thread %d) ..", thread_no );
+                       *alloclen = ( len1 + len2 ) + 1000;
+                       ReallocateCharMtx( aseq, njob, *alloclen + 10  );
+                       fprintf( stderr, "done. *alloclen = %d\n", *alloclen );
+               }
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+               {
+                       localcopy[j] = calloc( *alloclen, sizeof( char ) );
+                       strcpy( localcopy[j], aseq[j] );
+               }
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+               {
+                       localcopy[j] = calloc( *alloclen, sizeof( char ) );
+                       strcpy( localcopy[j], aseq[j] );
+               }
+
+               pthread_mutex_unlock( targ->mutex );
+
+               if( effarr_kozo )
+               {
+                       clus1 = fastconjuction_noname_kozo( topol[l][0], localcopy, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 );
+                       clus2 = fastconjuction_noname_kozo( topol[l][1], localcopy, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 );
+               }
+               else
+               {
+                       clus1 = fastconjuction_noname( topol[l][0], localcopy, mseq1, effarr1, effarr, indication1 );
+                       clus2 = fastconjuction_noname( topol[l][1], localcopy, mseq2, effarr2, effarr, indication2 );
+               }
+
+
+
+#if 1
+               fprintf( stderr, "\rSTEP % 5d /%d (thread %4d) ", l+1, njob-1, thread_no );
+#else
+               fprintf( stderr, "STEP %d /%d (thread %d) \n", l+1, njob-1, thread_no );
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, ", child1 = %d\n", dep[l].child0 );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, ", child2 = %d\n", dep[l].child1 );
+
+               fprintf( stderr, "Group1's lengths = " );
+               for( i=0; i<clus1; i++ ) fprintf( stderr, "%d ", strlen( mseq1[i] ) );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "Group2's lengths = " );
+               for( i=0; i<clus2; i++ ) fprintf( stderr, "%d ", strlen( mseq2[i] ) );
+               fprintf( stderr, "\n" );
+               
+#endif
+
+
+
+//             for( i=0; i<clus1; i++ ) fprintf( stderr, "## STEP%d-eff for mseq1-%d %f\n", l+1, i, effarr1[i] );
+
+               if( constraint )
+               {
+                       fastshrinklocalhom( topol[l][0], topol[l][1], localhomtable, localhomshrink );
+//                     msfastshrinklocalhom( topol[l][0], topol[l][1], localhomtable, localhomshrink );
+//                     fprintf( stderr, "localhomshrink =\n" );
+//                     outlocalhompt( localhomshrink, clus1, clus2 );
+//                     weightimportance4( clus1, clus2, effarr1, effarr2, localhomshrink );
+//                     fprintf( stderr, "after weight =\n" );
+//                     outlocalhompt( localhomshrink, clus1, clus2 );
+               }
+               if( rnakozo && rnaprediction == 'm' )
+               {
+                       makegrouprna( grouprna1, singlerna, topol[l][0] );
+                       makegrouprna( grouprna2, singlerna, topol[l][1] );
+               }
+
+
+/*
+               fprintf( stderr, "before align all\n" );
+               display( localcopy, njob );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+               if( !nevermemsave && ( constraint != 2  && alg != 'M'  && ( len1 > 30000 || len2 > 30000 ) ) )
+               {
+                       fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 );
+                       alg = 'M';
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonAlloc1 = 0;
+                       commonAlloc2 = 0;
+               }
+               
+
+//             if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 );
+               if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000 );
+               else                                               ffttry = 0;
+//             ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000 ); // v6.708
+//             fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 );
+//             fprintf( stderr, "f=%d, clus1=%d, fftlog[m1]=%d, clus2=%d, fftlog[m2]=%d\n", ffttry, clus1, fftlog[m1], clus2, fftlog[m2] );
+               if( constraint == 2 )
+               {
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "\n\nMemory saving mode is not supported.\n\n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "c" );
+                       if( alg == 'A' )
+                       {
+                               imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                               if( rnakozo ) imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL );
+                               pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                       }
+                       else if( alg == 'H' )
+                       {
+                               imp_match_init_strictH( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+                       else if( alg == 'Q' )
+                       {
+                               imp_match_init_strictQ( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL );
+                               pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+                       else if( alg == 'R' )
+                       {
+                               imp_match_init_strictR( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+               }
+               else if( force_fft || ( use_fft && ffttry ) )
+               {
+                       fprintf( stderr, "f" );
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "m" );
+                               pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 );
+                       }
+                       else
+                               pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL );
+               }
+               else
+               {
+                       fprintf( stderr, "d" );
+                       fftlog[m1] = 0;
+                       switch( alg )
+                       {
+                               case( 'a' ):
+                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen );
+                                       break;
+                               case( 'M' ):
+                                       fprintf( stderr, "m" );
+                                       pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'A' ):
+                                       pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'Q' ):
+                                       pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'R' ):
+                                       pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'H' ):
+                                       pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               default:
+                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                       }
+               }
+
+               nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] );
+
+#if SCOREOUT
+               fprintf( stderr, "score = %10.2f\n", pscore );
+#endif
+
+/*
+               fprintf( stderr, "after align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "after align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+//             writePre( njob, name, nlen, localcopy, 0 );
+
+               if( disp ) display( localcopy, njob );
+
+               pthread_mutex_lock( targ->mutex );
+               dep[l].done = 1;
+               (*nrunpt)--;
+               pthread_cond_broadcast( targ->treecond );
+
+//             pthread_mutex_unlock( targ->mutex );
+//             pthread_mutex_lock( targ->mutex );
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+                       strcpy( aseq[j], localcopy[j] );
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+                       strcpy( aseq[j], localcopy[j] );
+               pthread_mutex_unlock( targ->mutex );
+
+               for( i=0; (j=topol[l][0][i])!=-1; i++ )
+                       free( localcopy[j] );
+               for( i=0; (j=topol[l][1][i])!=-1; i++ )
+                       free( localcopy[j] );
+               free( topol[l][0] );
+               free( topol[l][1] );
+               free( topol[l] );
+
+       }
+}
+#endif
+
+void treebase( int *nlen, char **aseq, int nadd, char *mergeoralign, char **mseq1, char **mseq2, int ***topol, double *effarr, int *alloclen, LocalHom **localhomtable, RNApair ***singlerna, double *effarr_kozo )
+{
+       int i, l, m;
+       int len1nocommongap, len2nocommongap;
+       int len1, len2;
+       int clus1, clus2;
+       float pscore, tscore;
+       static char *indication1, *indication2;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       static double *effarr1_kozo = NULL;
+       static double *effarr2_kozo = NULL;
+       static LocalHom ***localhomshrink = NULL;
+       static int *fftlog;
+       int m1, m2;
+       static int *gaplen;
+       static int *gapmap;
+       static int *alreadyaligned;
+       float dumfl = 0.0;
+       int ffttry;
+       RNApair ***grouprna1, ***grouprna2;
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       }
+       else
+       {
+               grouprna1 = grouprna2 = NULL;
+       }
+
+       if( effarr1 == NULL ) 
+       {
+               fftlog = AllocateIntVec( njob );
+               effarr1 = AllocateDoubleVec( njob );
+               effarr2 = AllocateDoubleVec( njob );
+               indication1 = AllocateCharVec( 150 );
+               indication2 = AllocateCharVec( 150 );
+               gaplen = AllocateIntVec( *alloclen+10 );
+               gapmap = AllocateIntVec( *alloclen+10 );
+               alreadyaligned = AllocateIntVec( njob );
+#if 0
+#else
+               if( constraint )
+               {
+                       localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) );
+                       for( i=0; i<njob; i++)
+                               localhomshrink[i] = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+               }
+#endif
+               effarr1_kozo = AllocateDoubleVec( njob ); //tsuneni allocate sareru.
+               effarr2_kozo = AllocateDoubleVec( njob ); //tsuneni allocate sareru.
+               for( i=0; i<njob; i++ ) effarr1_kozo[i] = 0.0;
+               for( i=0; i<njob; i++ ) effarr2_kozo[i] = 0.0;
+       }
+
+       for( i=0; i<njob-nadd; i++ ) alreadyaligned[i] = 1;
+       for( i=njob-nadd; i<njob; i++ ) alreadyaligned[i] = 0;
+
+       for( l=0; l<njob; l++ ) fftlog[l] = 1;
+
+#if 0
+       fprintf( stderr, "##### fftwinsize = %d, fftthreshold = %d\n", fftWinSize, fftThreshold );
+#endif
+
+#if 0
+       for( i=0; i<njob; i++ )
+               fprintf( stderr, "TBFAST effarr[%d] = %f\n", i, effarr[i] );
+#endif
+
+
+       if( constraint )
+               calcimportance( njob, effarr, aseq, localhomtable );
+
+
+//     writePre( njob, name, nlen, aseq, 0 );
+
+       tscore = 0.0;
+       for( l=0; l<njob-1; l++ )
+       {
+               if( mergeoralign[l] == 'n' )
+               {
+//                     fprintf( stderr, "SKIP!\n" );
+                       free( topol[l][0] );
+                       free( topol[l][1] );
+                       free( topol[l] );
+                       continue;
+               }
+
+               m1 = topol[l][0][0];
+               m2 = topol[l][1][0];
+        len1 = strlen( aseq[m1] );
+        len2 = strlen( aseq[m2] );
+        if( *alloclen < len1 + len2 )
+        {
+                       fprintf( stderr, "\nReallocating.." );
+                       *alloclen = ( len1 + len2 ) + 1000;
+                       ReallocateCharMtx( aseq, njob, *alloclen + 10  );
+                       gaplen = realloc( gaplen, ( *alloclen + 10 ) * sizeof( int ) );
+                       if( gaplen == NULL )
+                       {
+                               fprintf( stderr, "Cannot realloc gaplen\n" );
+                               exit( 1 );
+                       }
+                       gapmap = realloc( gapmap, ( *alloclen + 10 ) * sizeof( int ) );
+                       if( gapmap == NULL )
+                       {
+                               fprintf( stderr, "Cannot realloc gapmap\n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "done. *alloclen = %d\n", *alloclen );
+               }
+
+               if( effarr_kozo )
+               {
+                       clus1 = fastconjuction_noname_kozo( topol[l][0], aseq, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 );
+                       clus2 = fastconjuction_noname_kozo( topol[l][1], aseq, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 );
+               }
+               else
+               {
+                       clus1 = fastconjuction_noname( topol[l][0], aseq, mseq1, effarr1, effarr, indication1 );
+                       clus2 = fastconjuction_noname( topol[l][1], aseq, mseq2, effarr2, effarr, indication2 );
+               }
+
+               if( mergeoralign[l] == '1' || mergeoralign[l] == '2' )
+               {
+                       newgapstr = "=";
+               }
+               else
+                       newgapstr = "-";
+
+
+               len1nocommongap = len1;
+               len2nocommongap = len2;
+               if( mergeoralign[l] == '1' ) // nai
+               {
+                       findcommongaps( clus2, mseq2, gapmap );
+                       commongappick( clus2, mseq2 );
+                       len2nocommongap = strlen( mseq2[0] );
+               }
+               else if( mergeoralign[l] == '2' )
+               {
+                       findcommongaps( clus1, mseq1, gapmap );
+                       commongappick( clus1, mseq1 );
+                       len1nocommongap = strlen( mseq1[0] );
+               }
+               
+
+               fprintf( trap_g, "\nSTEP-%d\n", l );
+               fprintf( trap_g, "group1 = %s\n", indication1 );
+               fprintf( trap_g, "group2 = %s\n", indication2 );
+
+#if 1
+               fprintf( stderr, "\rSTEP % 5d /%d ", l+1, njob-1 );
+               fflush( stderr );
+#else
+               fprintf( stdout, "STEP %d /%d\n", l+1, njob-1 );
+               fprintf( stderr, "STEP %d /%d\n", l+1, njob-1 );
+               fprintf( stderr, "group1 = %.66s", indication1 );
+               if( strlen( indication1 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "group2 = %.66s", indication2 );
+               if( strlen( indication2 ) > 66 ) fprintf( stderr, "..." );
+               fprintf( stderr, "\n" );
+#endif
+
+
+
+//             for( i=0; i<clus1; i++ ) fprintf( stderr, "## STEP%d-eff for mseq1-%d %f\n", l+1, i, effarr1[i] );
+
+               if( constraint )
+               {
+                       fastshrinklocalhom( topol[l][0], topol[l][1], localhomtable, localhomshrink );
+//                     msfastshrinklocalhom( topol[l][0], topol[l][1], localhomtable, localhomshrink );
+//                     fprintf( stderr, "localhomshrink =\n" );
+//                     outlocalhompt( localhomshrink, clus1, clus2 );
+//                     weightimportance4( clus1, clus2, effarr1, effarr2, localhomshrink );
+//                     fprintf( stderr, "after weight =\n" );
+//                     outlocalhompt( localhomshrink, clus1, clus2 );
+               }
+               if( rnakozo && rnaprediction == 'm' )
+               {
+                       makegrouprna( grouprna1, singlerna, topol[l][0] );
+                       makegrouprna( grouprna2, singlerna, topol[l][1] );
+               }
+
+
+/*
+               fprintf( stderr, "before align all\n" );
+               display( aseq, njob );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "before align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+               if( !nevermemsave && ( constraint != 2  && alg != 'M'  && ( len1 > 30000 || len2 > 30000 ) ) )
+               {
+                       fprintf( stderr, "\nlen1=%d, len2=%d, Switching to the memsave mode.\n", len1, len2 );
+                       alg = 'M';
+                       if( commonIP ) FreeIntMtx( commonIP );
+                       commonAlloc1 = 0;
+                       commonAlloc2 = 0;
+               }
+               
+
+//             if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 );
+               if( fftlog[m1] && fftlog[m2] ) ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 1000 && clus2 < 1000 );
+               else                                               ffttry = 0;
+//             ffttry = ( nlen[m1] > clus1 && nlen[m2] > clus2 && clus1 < 5000 && clus2 < 5000 ); // v6.708
+//             fprintf( stderr, "f=%d, len1/fftlog[m1]=%f, clus1=%d, len2/fftlog[m2]=%f, clus2=%d\n", ffttry, (float)len1/fftlog[m1], clus1, (float)len2/fftlog[m2], clus2 );
+//             fprintf( stderr, "f=%d, clus1=%d, fftlog[m1]=%d, clus2=%d, fftlog[m2]=%d\n", ffttry, clus1, fftlog[m1], clus2, fftlog[m2] );
+               if( constraint == 2 )
+               {
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "\n\nMemory saving mode is not supported.\n\n" );
+                               exit( 1 );
+                       }
+                       fprintf( stderr, "c" );
+                       if( alg == 'A' )
+                       {
+                               imp_match_init_strict( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                               if( rnakozo ) imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL );
+                               pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                       }
+                       else if( alg == 'H' )
+                       {
+                               imp_match_init_strictH( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+                       else if( alg == 'Q' )
+                       {
+                               imp_match_init_strictQ( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, NULL, NULL, NULL );
+                               pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+                       else if( alg == 'R' )
+                       {
+                               imp_match_init_strictR( NULL, clus1, clus2, strlen( mseq1[0] ), strlen( mseq2[0] ), mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                               pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, localhomshrink, &dumfl, NULL, NULL, NULL, NULL );
+                       }
+               }
+               else if( force_fft || ( use_fft && ffttry ) )
+               {
+                       fprintf( stderr, "f" );
+                       if( alg == 'M' )
+                       {
+                               fprintf( stderr, "m" );
+                               pscore = Falign_udpari_long( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1 );
+                       }
+                       else
+                               pscore = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, fftlog+m1, NULL, 0, NULL );
+               }
+               else
+               {
+                       fprintf( stderr, "d" );
+                       fftlog[m1] = 0;
+                       switch( alg )
+                       {
+                               case( 'a' ):
+                                       pscore = Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen );
+                                       break;
+                               case( 'M' ):
+                                       fprintf( stderr, "m" );
+                                       pscore = MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'A' ):
+                                       pscore = A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                       break;
+                               case( 'Q' ):
+                                       pscore = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'R' ):
+                                       pscore = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               case( 'H' ):
+                                       pscore = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, *alloclen, NULL, &dumfl, NULL, NULL, NULL, NULL );
+                                       break;
+                               default:
+                                       ErrorExit( "ERROR IN SOURCE FILE" );
+                       }
+               }
+
+               nlen[m1] = 0.5 * ( nlen[m1] + nlen[m2] );
+
+#if SCOREOUT
+               fprintf( stderr, "score = %10.2f\n", pscore );
+#endif
+               tscore += pscore;
+/*
+               fprintf( stderr, "after align 1 %s \n", indication1 );
+               display( mseq1, clus1 );
+               fprintf( stderr, "\n" );
+               fprintf( stderr, "after align 2 %s \n", indication2 );
+               display( mseq2, clus2 );
+               fprintf( stderr, "\n" );
+*/
+
+//             writePre( njob, name, nlen, aseq, 0 );
+
+               if( disp ) display( aseq, njob );
+
+               if( mergeoralign[l] == '1' ) // jissainiha nai. atarashii hairetsu ha saigo dakara.
+               {
+                       adjustgapmap( strlen( mseq2[0] )-len2nocommongap+len2, gapmap, mseq2[0] );
+                       restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen );
+                       findnewgaps( clus2, mseq2, gaplen );
+                       insertnewgaps( njob, alreadyaligned, aseq, topol[l][1], topol[l][0], gaplen, gapmap, *alloclen, alg );
+                       for( i=0; i<njob; i++ ) eq2dash( aseq[i] );
+                       for( i=0; (m=topol[l][0][i])>-1; i++ ) alreadyaligned[m] = 1;
+               }
+               if( mergeoralign[l] == '2' )
+               {
+//                     fprintf( stderr, ">mseq1[0] = \n%s\n", mseq1[0] );
+//                     fprintf( stderr, ">mseq2[0] = \n%s\n", mseq2[0] );
+                       adjustgapmap( strlen( mseq1[0] )-len1nocommongap+len1, gapmap, mseq1[0] );
+                       restorecommongaps( njob, aseq, topol[l][0], topol[l][1], gapmap, *alloclen );
+                       findnewgaps( clus1, mseq1, gaplen );
+                       insertnewgaps( njob, alreadyaligned, aseq, topol[l][0], topol[l][1], gaplen, gapmap, *alloclen, alg );
+                       for( i=0; i<njob; i++ ) eq2dash( aseq[i] );
+                       for( i=0; (m=topol[l][1][i])>-1; i++ ) alreadyaligned[m] = 1;
+               }
+
+               free( topol[l][0] );
+               free( topol[l][1] );
+               free( topol[l] );
+       }
+#if SCOREOUT
+       fprintf( stderr, "totalscore = %10.2f\n\n", tscore );
+#endif
+}
+
+static void WriteOptions( FILE *fp )
+{
+
+       if( dorp == 'd' ) fprintf( fp, "DNA\n" );
+       else
+       {
+               if     ( scoremtx ==  0 ) fprintf( fp, "JTT %dPAM\n", pamN );
+               else if( scoremtx ==  1 ) fprintf( fp, "BLOSUM %d\n", nblosum );
+               else if( scoremtx ==  2 ) fprintf( fp, "M-Y\n" );
+       }
+    fprintf( stderr, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+    if( use_fft ) fprintf( fp, "FFT on\n" );
+
+       fprintf( fp, "tree-base method\n" );
+       if( tbrweight == 0 ) fprintf( fp, "unweighted\n" );
+       else if( tbrweight == 3 ) fprintf( fp, "clustalw-like weighting\n" );
+       if( tbitr || tbweight ) 
+       {
+               fprintf( fp, "iterate at each step\n" );
+               if( tbitr && tbrweight == 0 ) fprintf( fp, "  unweighted\n" ); 
+               if( tbitr && tbrweight == 3 ) fprintf( fp, "  reversely weighted\n" ); 
+               if( tbweight ) fprintf( fp, "  weighted\n" ); 
+               fprintf( fp, "\n" );
+       }
+
+        fprintf( fp, "Gap Penalty = %+5.2f, %+5.2f, %+5.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+
+       if( alg == 'a' )
+               fprintf( fp, "Algorithm A\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+\n" );
+       else if( alg == 'C' ) 
+               fprintf( fp, "Apgorithm A+/C\n" );
+       else
+               fprintf( fp, "Unknown algorithm\n" );
+
+       if( treemethod == 'X' )
+               fprintf( fp, "Tree = UPGMA (mix).\n" );
+       else if( treemethod == 'E' )
+               fprintf( fp, "Tree = UPGMA (average).\n" );
+       else if( treemethod == 'q' )
+               fprintf( fp, "Tree = Minimum linkage.\n" );
+       else
+               fprintf( fp, "Unknown tree.\n" );
+
+    if( use_fft )
+    {
+        fprintf( fp, "FFT on\n" );
+        if( dorp == 'd' )
+            fprintf( fp, "Basis : 4 nucleotides\n" );
+        else
+        {
+            if( fftscore )
+                fprintf( fp, "Basis : Polarity and Volume\n" );
+            else
+                fprintf( fp, "Basis : 20 amino acids\n" );
+        }
+        fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+        fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+    }
+       else
+        fprintf( fp, "FFT off\n" );
+       fflush( fp );
+}
+        
+
+int main( int argc, char *argv[] )
+{
+       static int  *nlen;      
+       static float *selfscore;
+       int nogaplen;
+       static char **name, **seq;
+       static char **mseq1, **mseq2;
+       static char **bseq;
+       static float **iscore, **iscore_kozo;
+       static double *eff, *eff_kozo, *eff_kozo_mapped = NULL;
+       int i, j, ien, ik, jk;
+       static int ***topol, ***topol_kozo;
+       static int *addmem;
+       static Treedep *dep;
+       static float **len, **len_kozo;
+       FILE *prep;
+       FILE *infp;
+       FILE *orderfp;
+       FILE *hat2p;
+       double unweightedspscore;
+       int alignmentlength;
+       char *mergeoralign;
+       int foundthebranch;
+       
+       char c;
+       int alloclen;
+       LocalHom **localhomtable = NULL;
+       RNApair ***singlerna;
+       float ssi, ssj, bunbo;
+       static char *kozoarivec;
+       int nkozo;
+
+       arguments( argc, argv );
+#ifndef enablemultithread
+       nthread = 0;
+#endif
+
+       if( inputfile )
+       {
+               infp = fopen( inputfile, "r" );
+               if( !infp ) 
+               {
+                       fprintf( stderr, "Cannot open %s\n", inputfile );
+                       exit( 1 );
+               }
+       }
+       else    
+               infp = stdin;
+
+       getnumlen( infp );
+       rewind( infp );
+
+
+       nkozo = 0;
+
+       if( njob < 2 )
+       {
+               fprintf( stderr, "At least 2 sequences should be input!\n"
+                                                "Only %d sequence found.\n", njob ); 
+               exit( 1 );
+       }
+
+       seq = AllocateCharMtx( njob, nlenmax+1 );
+       mseq1 = AllocateCharMtx( njob, 0 );
+       mseq2 = AllocateCharMtx( njob, 0 );
+
+       name = AllocateCharMtx( njob, B+1 );
+       nlen = AllocateIntVec( njob );
+       selfscore = AllocateFloatVec( njob );
+
+       topol = AllocateIntCub( njob, 2, 0 );
+       len = AllocateFloatMtx( njob, 2 );
+       iscore = AllocateFloatHalfMtx( njob );
+       eff = AllocateDoubleVec( njob );
+       kozoarivec = AllocateCharVec( njob );
+
+       mergeoralign = AllocateCharVec( njob );
+
+       dep = (Treedep *)calloc( njob, sizeof( Treedep ) );
+       if( nadd ) addmem = AllocateIntVec( nadd+1 );
+
+       if( constraint )
+       {
+               localhomtable = (LocalHom **)calloc( njob, sizeof( LocalHom *) );
+               for( i=0; i<njob; i++)
+               {
+                       localhomtable[i] = (LocalHom *)calloc( njob, sizeof( LocalHom ) );
+                       for( j=0; j<njob; j++)
+                       {
+                               localhomtable[i][j].start1 = -1;
+                               localhomtable[i][j].end1 = -1;
+                               localhomtable[i][j].start2 = -1;
+                               localhomtable[i][j].end2 = -1;
+                               localhomtable[i][j].overlapaa = -1.0;
+                               localhomtable[i][j].opt = -1.0;
+                               localhomtable[i][j].importance = -1.0;
+                               localhomtable[i][j].next = NULL;
+                               localhomtable[i][j].korh = 'h';
+                       }
+               }
+
+               fprintf( stderr, "Loading 'hat3' ... " );
+               prep = fopen( "hat3", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat3." );
+               readlocalhomtable( prep, njob, localhomtable, kozoarivec );
+               fclose( prep );
+               fprintf( stderr, "\ndone.\n" );
+
+
+               nkozo = 0;
+               for( i=0; i<njob; i++ ) 
+               {
+//                     fprintf( stderr, "kozoarivec[%d] = %d\n", i, kozoarivec[i] );
+                       if( kozoarivec[i] ) nkozo++;
+               }
+               if( nkozo )
+               {
+                       topol_kozo = AllocateIntCub( nkozo, 2, 0 );
+                       len_kozo = AllocateFloatMtx( nkozo, 2 );
+                       iscore_kozo = AllocateFloatHalfMtx( nkozo );
+                       eff_kozo = AllocateDoubleVec( nkozo );
+                       eff_kozo_mapped = AllocateDoubleVec( njob );
+               }
+
+
+//             outlocalhom( localhomtable, njob );
+
+#if 0
+               fprintf( stderr, "Extending localhom ... " );
+               extendlocalhom2( njob, localhomtable );
+               fprintf( stderr, "done.\n" );
+#endif
+       }
+
+#if 0
+       readData( infp, name, nlen, seq );
+#else
+       readData_pointer( infp, name, nlen, seq );
+       fclose( infp );
+#endif
+
+       constants( njob, seq );
+
+#if 0
+       fprintf( stderr, "params = %d, %d, %d\n", penalty, penalty_ex, offset );
+#endif
+
+       initSignalSM();
+
+       initFiles();
+
+       WriteOptions( trap_g );
+
+       c = seqcheck( seq );
+       if( c )
+       {
+               fprintf( stderr, "Illegal character %c\n", c );
+               exit( 1 );
+       }
+
+//     writePre( njob, name, nlen, seq, 0 );
+
+       if( treein )
+       {
+#if 0
+               if( nkozo )
+               {
+                       fprintf( stderr, "Both structure and user tree have been given. Not yet supported!\n" );
+                       exit( 1 );
+               }
+#endif
+               fprintf( stderr, "Loading a tree ... " );
+               loadtree( njob, topol, len, name, nlen, dep );
+               fprintf( stderr, "\ndone.\n\n" );
+       }
+       else
+       {
+               if( tbutree == 0 )
+               {
+                       for( i=1; i<njob; i++ ) 
+                       {
+                               if( nlen[i] != nlen[0] ) 
+                               {
+                                       fprintf( stderr, "Input pre-aligned seqences or make hat2.\n" );
+                                       exit( 1 );
+                               }
+                       }
+       
+                       fprintf( stderr, "Making a distance matrix .. \n" );
+                       fflush( stderr );
+                       ien = njob-1;
+                       for( i=0; i<njob; i++ ) 
+                       {
+                               selfscore[i] = naivepairscore11( seq[i], seq[i], penalty );
+                       }
+#ifdef enablemultithread
+                       if( nthread > 0 )
+                       {
+                               distancematrixthread_arg_t *targ;
+                               Jobtable jobpos;
+                               pthread_t *handle;
+                               pthread_mutex_t mutex;
+
+                               jobpos.i = 0;
+                               jobpos.j = 0;
+
+                               targ = calloc( nthread, sizeof( distancematrixthread_arg_t ) );
+                               handle = calloc( nthread, sizeof( pthread_t ) );
+                               pthread_mutex_init( &mutex, NULL );
+
+                               for( i=0; i<nthread; i++ )
+                               {
+                                       targ[i].thread_no = i;
+                                       targ[i].njob = njob;
+                                       targ[i].selfscore = selfscore;
+                                       targ[i].iscore = iscore;
+                                       targ[i].seq = seq;
+                                       targ[i].jobpospt = &jobpos;
+                                       targ[i].mutex = &mutex;
+
+                                       pthread_create( handle+i, NULL, distancematrixthread, (void *)(targ+i) );
+                               }
+
+                               for( i=0; i<nthread; i++ )
+                               {
+                                       pthread_join( handle[i], NULL );
+                               }
+                               pthread_mutex_destroy( &mutex );
+                               free( handle );
+                               free( targ );
+                       }
+                       else
+#endif
+                       {
+                               for( i=0; i<ien; i++ ) 
+                               {
+                                       if( i % 10 == 0 )
+                                       {
+                                               fprintf( stderr, "\r% 5d / %d", i, ien );
+                                               fflush( stderr );
+                                       }
+                                       ssi = selfscore[i];
+                                       for( j=i+1; j<njob; j++ ) 
+                                       {
+                                               ssj = selfscore[j];
+                                               bunbo = MIN( ssi, ssj );
+                                               if( bunbo == 0.0 )
+                                                       iscore[i][j-i] = 1.0;
+                                               else
+//                                                     iscore[i][j-i] = 1.0 - naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] );
+                                                       iscore[i][j-i] = 1.0 - naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
+               
+#if 0
+                                               fprintf( stderr, "### ssj = %f\n", ssj );
+                                               fprintf( stderr, "### selfscore[i] = %f\n", selfscore[i] );
+                                               fprintf( stderr, "### selfscore[j] = %f\n", selfscore[j] );
+                                               fprintf( stderr, "### rawscore = %f\n", naivepairscore11( seq[i], seq[j], penalty ) );
+#endif
+                                       }
+                               }
+                       }
+                       fprintf( stderr, "\ndone.\n\n" );
+                       fflush( stderr );
+               }
+               else
+               {
+                       fprintf( stderr, "Loading 'hat2' ... " );
+                       prep = fopen( "hat2", "r" );
+                       if( prep == NULL ) ErrorExit( "Make hat2." );
+                       readhat2_floathalf_pointer( prep, njob, name, iscore );
+                       fclose( prep );
+                       fprintf( stderr, "done.\n" );
+               }
+#if 1
+               if( distout )
+               {
+                       hat2p = fopen( "hat2", "w" );
+                       WriteFloatHat2_pointer_halfmtx( hat2p, njob, name, iscore );
+                       fclose( hat2p );
+               }
+#endif
+               if( nkozo )
+               {
+                       ien = njob-1;
+                       ik = 0;
+                       for( i=0; i<ien; i++ )
+                       {
+                               jk = ik+1;
+                               for( j=i+1; j<njob; j++ ) 
+                               {
+                                       if( kozoarivec[i] && kozoarivec[j] )
+                                       {
+                                               iscore_kozo[ik][jk-ik] = iscore[i][j-i];
+                                       }
+                                       if( kozoarivec[j] ) jk++;
+                               }
+                               if( kozoarivec[i] ) ik++;
+                       }
+               }
+
+               fprintf( stderr, "Constructing a UPGMA tree ... " );
+               fflush( stderr );
+               if( topin )
+               {
+                       fprintf( stderr, "Loading a topology ... " );
+                       loadtop( njob, iscore, topol, len );
+                       fprintf( stderr, "\ndone.\n\n" );
+               }
+               else if( treeout )
+               {
+                       fixed_musclesupg_float_realloc_nobk_halfmtx_treeout( njob, iscore, topol, len, name, nlen, dep );
+               }
+               else
+               {
+                       fixed_musclesupg_float_realloc_nobk_halfmtx( njob, iscore, topol, len, dep );
+               }
+//             else 
+//                     ErrorExit( "Incorrect tree\n" );
+
+               if( nkozo )
+               {
+//                     for( i=0; i<nkozo-1; i++ )
+//                             for( j=i+1; j<nkozo; j++ )
+//                                     fprintf( stderr, "iscore_kozo[%d][%d] =~ %f\n", i, j, iscore_kozo[i][j-i] );
+                       fixed_musclesupg_float_realloc_nobk_halfmtx( nkozo, iscore_kozo, topol_kozo, len_kozo, NULL );
+               }
+               fprintf( stderr, "\ndone.\n\n" );
+               fflush( stderr );
+       }
+
+
+       orderfp = fopen( "order", "w" );
+       if( !orderfp )
+       {
+               fprintf( stderr, "Cannot open 'order'\n" );
+               exit( 1 );
+       }
+       for( i=0; (j=topol[njob-2][0][i])!=-1; i++ )
+       {
+               fprintf( orderfp, "%d\n", j );
+       }
+       for( i=0; (j=topol[njob-2][1][i])!=-1; i++ )
+       {
+               fprintf( orderfp, "%d\n", j );
+       }
+       fclose( orderfp );
+
+       if( treeout && noalign ) 
+       {
+               writeData_pointer( prep_g, njob, name, nlen, seq );
+               fprintf( stderr, "\n" ); 
+               SHOWVERSION;
+               return( 0 );
+       }
+
+//     countnode( njob, topol, node0 );
+       if( tbrweight )
+       {
+               weight = 3; 
+#if 0
+               utree = 0; counteff( njob, topol, len, eff ); utree = 1;
+#else
+               counteff_simple_float( njob, topol, len, eff );
+
+               if( nkozo )
+               {
+//                     counteff_simple_float( nkozo, topol_kozo, len_kozo, eff_kozo ); // single weight nanode iranai
+                       for( i=0,j=0; i<njob; i++ )
+                       {
+                               if( kozoarivec[i] )
+                               {
+//                                     eff_kozo_mapped[i] = eff_kozo[j]; //
+                                       eff_kozo_mapped[i] = eff[i];      // single weight
+                                       j++;
+                               }
+                               else
+                                       eff_kozo_mapped[i] = 0.0;
+//                             fprintf( stderr, "eff_kozo_mapped[%d] = %f\n", i, eff_kozo_mapped[i] );
+//                             fprintf( stderr, "            eff[%d] = %f\n", i, eff[i] );
+                       }
+               }
+
+
+#endif
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) eff[i] = 1.0;
+               if( nkozo ) 
+               {
+                       for( i=0; i<njob; i++ ) 
+                       {
+                               if( kozoarivec[i] ) 
+                                       eff_kozo_mapped[i] = 1.0;
+                               else
+                                       eff_kozo_mapped[i] = 0.0;
+                       }
+               }
+       }
+
+       FreeFloatHalfMtx( iscore, njob );
+       FreeFloatMtx( len );
+
+       alloclen = nlenmax*2+1; //chuui!
+       bseq = AllocateCharMtx( njob, alloclen );
+
+       if( nadd )
+       {
+               alignmentlength = strlen( seq[0] );
+               for( i=0; i<njob-nadd; i++ )
+               {
+                       if( alignmentlength != strlen( seq[i] ) )
+                       {
+                               fprintf( stderr, "#################################################################################\n" );
+                               fprintf( stderr, "# ERROR!                                                                        #\n" );
+                               fprintf( stderr, "# The original%4d sequences must be aligned                                    #\n", njob-nadd );
+                               fprintf( stderr, "#################################################################################\n" );
+                               exit( 1 );
+                       }
+               }
+               if( addprofile )
+               {
+                       alignmentlength = strlen( seq[njob-nadd] );
+                       for( i=njob-nadd; i<njob; i++ )
+                       {
+                               if( alignmentlength != strlen( seq[i] ) )
+                               {
+                                       fprintf( stderr, "###############################################################################\n" );
+                                       fprintf( stderr, "# ERROR!                                                                      #\n" );
+                                       fprintf( stderr, "# The%4d additional sequences must be aligned                                #\n", nadd );
+                                       fprintf( stderr, "# Otherwise, try the '--add' option, instead of '--addprofile' option.        #\n" );
+                                       fprintf( stderr, "###############################################################################\n" );
+                                       exit( 1 );
+                               }
+                       }
+                       for( i=0; i<nadd; i++ ) addmem[i] = njob-nadd+i;
+                       addmem[nadd] = -1;
+                       foundthebranch = 0;
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               if( samemember( topol[i][0], addmem ) ) // jissainiha nai
+                               {
+                                       mergeoralign[i] = '1';
+                                       foundthebranch = 1;
+                               }
+                               else if( samemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = '2';
+                                       foundthebranch = 1;
+                               }
+                               else
+                               {
+                                       mergeoralign[i] = 'n';
+                               }
+                       }
+                       if( !foundthebranch )
+                       {
+                               fprintf( stderr, "###############################################################################\n" );
+                               fprintf( stderr, "# ERROR!                                                                      #\n" );
+                               fprintf( stderr, "# There is no appropriate position to add the%4d sequences in the guide tree.#\n", nadd );
+                               fprintf( stderr, "# Check whether the%4d sequences form a monophyletic cluster.                #\n", nadd );
+                               fprintf( stderr, "# If not, try the '--add' option, instead of the '--addprofile' option.       #\n" );
+                               fprintf( stderr, "############################################################################### \n" );
+                               exit( 1 );
+                       }
+                       commongappick( nadd, seq+njob-nadd );
+                       for( i=njob-nadd; i<njob; i++ ) strcpy( bseq[i], seq[i] );
+               }
+               else
+               {
+                       for( i=0; i<njob-1; i++ ) mergeoralign[i] = 'n';
+                       for( j=njob-nadd; j<njob; j++ )
+                       {
+                               addmem[0] = j;
+                               addmem[1] = -1;
+                               for( i=0; i<njob-1; i++ )
+                               {
+                                       if( samemember( topol[i][0], addmem ) ) // arieru
+                                       {
+//                                             fprintf( stderr, "HIT!\n" );
+                                               if( mergeoralign[i] != 'n' ) mergeoralign[i] = 'w';
+                                               else mergeoralign[i] = '1';
+                                       }
+                                       else if( samemember( topol[i][1], addmem ) )
+                                       {
+//                                             fprintf( stderr, "HIT!\n" );
+                                               if( mergeoralign[i] != 'n' ) mergeoralign[i] = 'w';
+                                               else mergeoralign[i] = '2';
+                                       }
+                               }
+                       }
+       
+                       for( i=0; i<nadd; i++ ) addmem[i] = njob-nadd+i;
+                       addmem[nadd] = -1;
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               if( includemember( topol[i][0], addmem ) && includemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = 'w';
+                               }
+                               else if( includemember( topol[i][0], addmem ) )
+                               {
+                                       mergeoralign[i] = '1';
+                               }
+                               else if( includemember( topol[i][1], addmem ) )
+                               {
+                                       mergeoralign[i] = '2';
+                               }
+                       }
+#if 0
+                       for( i=0; i<njob-1; i++ )
+                       {
+                               fprintf( stderr, "mem0 = " );
+                               for( j=0; topol[i][0][j]>-1; j++ )      fprintf( stderr, "%d ", topol[i][0][j] );
+                               fprintf( stderr, "\n" );
+                               fprintf( stderr, "mem1 = " );
+                               for( j=0; topol[i][1][j]>-1; j++ )      fprintf( stderr, "%d ", topol[i][1][j] );
+                               fprintf( stderr, "\n" );
+                               fprintf( stderr, "i=%d, mergeoralign[] = %c\n", i, mergeoralign[i] );
+                       }
+#endif
+                       for( i=njob-nadd; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+               }
+
+               commongappick( njob-nadd, seq );
+               for( i=0; i<njob-nadd; i++ ) strcpy( bseq[i], seq[i] );
+       }
+       else
+       {
+               for( i=0; i<njob; i++ ) gappick0( bseq[i], seq[i] );
+               for( i=0; i<njob-1; i++ ) mergeoralign[i] = 'a';
+       }
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               singlerna = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               prep = fopen( "hat4", "r" );
+               if( prep == NULL ) ErrorExit( "Make hat4 using mccaskill." );
+               fprintf( stderr, "Loading 'hat4' ... " );
+               for( i=0; i<njob; i++ )
+               {
+                       nogaplen = strlen( bseq[i] );
+                       singlerna[i] = (RNApair **)calloc( nogaplen, sizeof( RNApair * ) );
+                       for( j=0; j<nogaplen; j++ )
+                       {
+                               singlerna[i][j] = (RNApair *)calloc( 1, sizeof( RNApair ) );
+                               singlerna[i][j][0].bestpos = -1;
+                               singlerna[i][j][0].bestscore = -1.0;
+                       }
+                       readmccaskill( prep, singlerna[i], nogaplen );
+               }
+               fclose( prep );
+               fprintf( stderr, "\ndone.\n" );
+       }
+       else
+               singlerna = NULL;
+
+
+       fprintf( stderr, "Progressive alignment ... \n" );
+
+#ifdef enablemultithread
+       if( nthread > 0 && nadd == 0 )
+       {
+               treebasethread_arg_t *targ;     
+               int jobpos;
+               pthread_t *handle;
+               pthread_mutex_t mutex;
+               pthread_cond_t treecond;
+               int *fftlog;
+               int nrun;
+               int nthread_yoyu;
+
+               nthread_yoyu = nthread * 1;
+               nrun = 0;
+               jobpos = 0;
+               targ = calloc( nthread_yoyu, sizeof( treebasethread_arg_t ) );
+               fftlog = AllocateIntVec( njob );
+               handle = calloc( nthread_yoyu, sizeof( pthread_t ) );
+               pthread_mutex_init( &mutex, NULL );
+               pthread_cond_init( &treecond, NULL );
+
+               for( i=0; i<njob; i++ ) dep[i].done = 0;
+               for( i=0; i<njob; i++ ) fftlog[i] = 1;
+
+               if( constraint )
+                       calcimportance( njob, eff, bseq, localhomtable );
+
+               for( i=0; i<nthread_yoyu; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].nrunpt = &nrun;
+                       targ[i].njob = njob;
+                       targ[i].nlen = nlen;
+                       targ[i].jobpospt = &jobpos;
+                       targ[i].topol = topol;
+                       targ[i].dep = dep;
+                       targ[i].aseq = bseq;
+                       targ[i].effarr = eff;
+                       targ[i].alloclenpt = &alloclen;
+                       targ[i].localhomtable = localhomtable;
+                       targ[i].singlerna = singlerna;
+                       targ[i].effarr_kozo = eff_kozo_mapped;
+                       targ[i].fftlog = fftlog;
+                       targ[i].mutex = &mutex;
+                       targ[i].treecond = &treecond;
+
+                       pthread_create( handle+i, NULL, treebasethread, (void *)(targ+i) );
+               }
+
+               for( i=0; i<nthread_yoyu; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+               pthread_mutex_destroy( &mutex );
+               pthread_cond_destroy( &treecond );
+               free( handle );
+               free( targ );
+               free( fftlog );
+       }
+       else
+#endif
+               treebase( nlen, bseq, nadd, mergeoralign, mseq1, mseq2, topol, eff, &alloclen, localhomtable, singlerna, eff_kozo_mapped );
+       fprintf( stderr, "\ndone.\n" );
+       if( scoreout )
+       {
+               unweightedspscore = plainscore( njob, bseq );
+               fprintf( stderr, "\nSCORE %s = %.0f, ", "(treebase)", unweightedspscore );
+               fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( njob * strlen( bseq[0] ) ) );
+               fprintf( stderr, "\n\n" );
+       }
+
+#if 0
+       if( constraint )
+       {
+               LocalHom *tmppt1, *tmppt2;
+               for( i=0; i<njob; i++)
+               {
+                       for( j=0; j<njob; j++)
+                       {
+                               tmppt1 = localhomtable[i]+j;
+                               while( tmppt2 = tmppt1->next )
+                               {
+                                       free( (void *)tmppt1 );
+                                       tmppt1 = tmppt2;
+                               }
+                               free( (void *)tmppt1 );
+                       }
+                       free( (void *)(localhomtable[i]+j) );
+               }
+               free( (void *)localhomtable );
+       }
+#endif
+
+       fprintf( trap_g, "done.\n" );
+       fclose( trap_g );
+       free( mergeoralign );
+
+       writeData_pointer( prep_g, njob, name, nlen, bseq );
+#if 0
+       writeData( stdout, njob, name, nlen, bseq );
+       writePre( njob, name, nlen, bseq, !contin );
+       writeData_pointer( prep_g, njob, name, nlen, aseq );
+#endif
+#if IODEBUG
+       fprintf( stderr, "OSHIMAI\n" );
+#endif
+
+       if( constraint ) FreeLocalHomTable( localhomtable, njob );
+
+       SHOWVERSION;
+       return( 0 );
+}
diff --git a/binaries/src/mafft/core/tddis.c b/binaries/src/mafft/core/tddis.c
new file mode 100644 (file)
index 0000000..4742e78
--- /dev/null
@@ -0,0 +1,940 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+#if 0
+void mdfymtx( char pair[njob][njob], int s1, double **partialmtx, double **mtx )
+#else
+void mdfymtx( char **pair, int s1, double **partialmtx, double **mtx )
+#endif
+{
+       int i, j;
+       int icount, jcount;
+#if DEBUG
+       FILE *fp;
+       static char name[M][B];
+
+       for( i=0; i<M; i++ ) name[i][0] = 0;
+       fprintf( stdout, "s1 = %d\n", s1 );
+       for( i=0; i<njob; i++ ) 
+       {
+               for( j=0; j<njob; j++ ) 
+               {
+                       printf( "%#2d", pair[i][j] );
+               }
+               printf( "\n" );
+       }
+#endif
+
+       for( i=0, icount=0; i<njob-1; i++ )
+       {
+               if( !pair[s1][i] ) continue;
+               for( j=i+1, jcount=icount+1; j<njob; j++ ) 
+               {
+                       if( !pair[s1][j] ) continue;
+                       partialmtx[icount][jcount] = mtx[i][j];
+                       jcount++;
+               }
+               icount++;
+       }
+#if DEBUG
+       fp = fopen( "hat2.org", "w" );
+       WriteHat2( fp, njob, name, mtx );
+       fclose( fp );
+       fp = fopen( "hat2.mdf", "w" );
+       WriteHat2( fp, icount, name, partialmtx );
+       fclose( fp );
+#endif
+               
+}
+
+               
+float score_calc( char **seq, int s )  /* method 3  */
+{
+    int i, j, k, c;
+    int len = strlen( seq[0] );
+    float score;
+    int tmpscore;
+    char *mseq1, *mseq2;
+
+    score = 0.0;
+    for( i=0; i<s-1; i++ )
+    {
+        for( j=i+1; j<s; j++ )
+        {
+            mseq1 = seq[i];
+            mseq2 = seq[j];
+            tmpscore = 0;
+            c = 0;
+            for( k=0; k<len; k++ )
+            {
+                if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                c++;
+                tmpscore += amino_dis[(int)mseq1[k]][(int)mseq2[k]];
+                if( mseq1[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq1[++k] == '-' )
+                        ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+                if( mseq2[k] == '-' )
+                {
+                    tmpscore += penalty;
+                    while( mseq2[++k] == '-' )
+                        ;
+                    k--;
+                    if( k > len-2 ) break;
+                    continue;
+                }
+            }
+            /*
+            if( mseq1[0] == '-' || mseq2[0] == '-' )
+            {
+                for( k=0; k<len; k++ )
+                {
+                    if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                    if( !( mseq1[k] != '-' && mseq2[k] != '-' ) ) 
+                    {
+                        c--;
+                        tmpscore -= penalty;
+                        break;
+                    }
+                    else break;
+                }
+            }
+            if( mseq1[len-1] == '-' || mseq2[len-1] == '-' )
+            {
+                for( k=0; k<len; k++ )
+                {
+                    if( mseq1[k] == '-' && mseq2[k] == '-' ) continue;
+                    if( !( mseq1[k] != '-' && mseq2[k] != '-' ) ) 
+                    {
+                        c--;
+                        tmpscore -= penalty;
+                        break;
+                    }
+                    else break;
+                }
+            }
+            */
+            score += (double)tmpscore / (double)c;
+        }
+    }
+    score = (float)score / ( ( (double)s * ((double)s-1.0) ) / 2.0 );
+       fprintf( stderr, "score in score_calc = %f\n", score );
+    return( score );
+}
+
+void cpmx_calc( char **seq, float **cpmx, double *eff, int lgth, int clus )
+{
+       int  i, j, k;
+       double totaleff = 0.0;
+
+       for( i=0; i<clus; i++ ) totaleff += eff[i]; 
+       for( i=0; i<26; i++ ) for( j=0; j<lgth; j++ ) cpmx[i][j] = 0.0;
+       for( j=0; j<lgth; j++ ) for( k=0; k<clus; k++ )
+                       cpmx[(int)amino_n[(int)seq[k][j]]][j] += (float)eff[k] / totaleff;
+}
+
+
+void cpmx_calc_new_bk( char **seq, float **cpmx, double *eff, int lgth, int clus ) // summ eff must be 1.0 
+{
+    int  i, j, k;
+    float feff;
+
+    for( i=0; i<26; i++ ) for( j=0; j<lgth; j++ ) cpmx[i][j] = 0.0;
+    for( k=0; k<clus; k++ )
+    {
+        feff = (float)eff[k];
+        for( j=0; j<lgth; j++ ) 
+        {
+            cpmx[(int)amino_n[(int)seq[k][j]]][j] += feff;
+        }
+    }
+}
+
+void cpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ) // summ eff must be 1.0
+{
+       int  i, j, k;
+       float feff;
+       float *cpmxpt, **cpmxptpt;
+       char *seqpt;
+
+       j = 26;
+       cpmxptpt = cpmx;
+       while( j-- )
+       {
+               cpmxpt = *cpmxptpt++;
+               i = lgth;
+               while( i-- )
+                       *cpmxpt++ = 0.0;
+       }
+       for( k=0; k<clus; k++ )
+       {
+               feff = (float)eff[k];
+               seqpt = seq[k];
+//             fprintf( stderr, "seqpt = %s, lgth=%d\n", seqpt, lgth );
+               for( j=0; j<lgth; j++ )
+               {
+                       cpmx[(int)amino_n[(int)*seqpt++]][j] += feff;
+               }
+       }
+}
+void MScpmx_calc_new( char **seq, float **cpmx, double *eff, int lgth, int clus ) // summ eff must be 1.0
+{
+       int  i, j, k;
+       float feff;
+       float **cpmxptpt, *cpmxpt;
+       char *seqpt;
+
+       j = lgth;
+       cpmxptpt = cpmx;
+       while( j-- )
+       {
+               cpmxpt = *cpmxptpt++;
+               i = 26;
+               while( i-- )
+                       *cpmxpt++ = 0.0;
+       }
+       for( k=0; k<clus; k++ )
+       {
+               feff = (float)eff[k];
+               seqpt = seq[k];
+               cpmxptpt = cpmx;
+               j = lgth;
+               while( j-- )
+                       (*cpmxptpt++)[(int)amino_n[(int)*seqpt++]] += feff;
+       }
+#if 0
+       for( j=0; j<lgth; j++ ) for( i=0; i<26; i++ ) cpmx[j][i] = 0.0;
+       for( k=0; k<clus; k++ )
+       {
+               feff = (float)eff[k];
+               for( j=0; j<lgth; j++ ) 
+                       cpmx[j][(int)amino_n[(int)seq[k][j]]] += feff;
+       }
+#endif
+}
+
+void cpmx_ribosum( char **seq, char **seqr, char *dir, float **cpmx, double *eff, int lgth, int clus ) // summ eff must be 1.0
+{
+       int  i, j, k;
+       float feff;
+       float **cpmxptpt, *cpmxpt;
+       char *seqpt, *seqrpt, *dirpt;
+       int code, code1, code2;
+
+       j = lgth;
+       cpmxptpt = cpmx;
+       while( j-- )
+       {
+               cpmxpt = *cpmxptpt++;
+               i = 37;
+               while( i-- )
+                       *cpmxpt++ = 0.0;
+       }
+       for( k=0; k<clus; k++ )
+       {
+               feff = (float)eff[k];
+               seqpt = seq[k];
+               seqrpt = seqr[k];
+               dirpt = dir;
+               cpmxptpt = cpmx;
+               j = lgth;
+               while( j-- )
+               {
+#if 0
+                       code1 = amino_n[(int)*seqpt];
+                       if( code1 > 3 ) code = 36;
+                       else
+                               code = code1;
+#else
+                       code1 = amino_n[(int)*seqpt];
+                       code2 = amino_n[(int)*seqrpt];
+                       if( code1 > 3 ) 
+                       {
+                               code = 36;
+                       }
+                       else if( code2 > 3 )
+                       {
+                               code = code1;
+                       }
+                       else if( *dirpt == '5' ) 
+                       {
+                               code = 4 + code2 * 4  + code1;
+                       }
+                       else if( *dirpt == '3' ) 
+                       {
+                               code = 20 + code2 * 4  + code1;
+                       }
+                       else // if( *dirpt == 'o' ) // nai 
+                       {
+                               code = code1;
+                       }
+#endif
+
+//                     fprintf( stderr, "%c -> code=%d toa=%d, tog=%d, toc=%d, tot=%d, ton=%d, efee=%f\n", *seqpt, code%4, ribosumdis[code][4+0], ribosumdis[code][4+1], ribosumdis[code][4+2], ribosumdis[code][20+3], ribosumdis[code][36], feff );
+
+                       seqpt++;
+                       seqrpt++;
+                       dirpt++;
+                       
+                       (*cpmxptpt++)[code] += feff;
+               }
+       }
+}
+
+void mseqcat( char **seq1, char **seq2, double **eff, double *effarr1, double *effarr2, char name1[M][B], char name2[M][B], int clus1, int clus2 )
+{
+       int i, j;
+    for( i=0; i<clus2; i++ )
+        seq1[clus1+i] = seq2[i];
+    for( i=0; i<clus2; i++ ) strcpy( name1[clus1+i], name2[i] );
+
+       for( i=0; i<clus1; i++ ) for( j=0; j<clus1; j++ ) eff[i][j] = effarr1[i]* effarr1[j]; 
+       for( i=0; i<clus1; i++ ) for( j=clus1; j<clus1+clus2; j++ ) eff[i][j] = effarr1[i]* effarr2[j-clus1]; 
+       for( i=clus1; i<clus1+clus2; i++ ) for( j=0; j<clus1; j++ ) eff[i][j] = effarr2[i-clus1] * effarr1[j]; 
+       for( i=clus1; i<clus1+clus2; i++ ) for( j=clus1; j<clus1+clus2; j++ ) eff[i][j] = effarr2[i-clus1] * effarr2[j-clus1]; 
+}
+
+       
+
+#if 0
+int conjuction( char pair[njob][njob], int s, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d )
+#else
+int conjuctionforgaln( int s0, int s1, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d )
+#endif
+{
+       int m, k;
+       char b[B];
+       double total;
+
+#if 0
+       fprintf( stderr, "s0 = %d, s1 = %d\n", s0, s1 );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       for( m=s0, k=0; m<s1; m++ )
+       {
+               {
+                       sprintf( b, " %d", m+1 ); 
+#if 1
+                       if( strlen( d ) < 100 ) strcat( d, b );
+#else
+                       strcat( d, b );
+#endif
+                       aseq[k] = seq[m];
+                       peff[k] = eff[m];
+                       total += peff[k];
+#if 0
+                       strcpy( aname[k], name[m] );
+#endif
+                       k++;
+               }
+       }
+#if 1
+       for( m=0; m<k; m++ )
+       {
+               peff[m] /= total;
+//             fprintf( stderr, "peff[%d] = %f\n", m, peff[m] );
+       }
+#endif
+       return( k );
+}
+
+void makegrouprna( RNApair ***group, RNApair ***all, int *memlist )
+{
+       int k, m;
+       for( k=0; (m=*memlist)!=-1; memlist++, k++ )
+       {
+               group[k] = all[m];
+       }
+}
+
+void makegrouprnait( RNApair ***group, RNApair ***all, char **pair, int s )
+{
+       int k, m;
+       for( m=s, k=0; m<njob; m++ )
+       {
+               if( pair[s][m] != 0 )
+               {
+                       group[k++] = all[m];
+               }
+       }
+}
+
+int fastconjuction_noweight( int *memlist, char **seq, char **aseq, double *peff, char *d )
+{
+       int m, k, dln;
+       char b[B];
+       double total;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       dln = 0;
+       for( k=0; *memlist!=-1; memlist++, k++ )
+       {
+               m = *memlist;
+               dln += sprintf( b, " %d", m+1 ); 
+#if 1
+               if( dln < 100 ) strcat( d, b );
+#else
+               strcat( d, b );
+#endif
+               aseq[k] = seq[m];
+               peff[k] = 1.0;
+               total += peff[k];
+       }
+#if 1
+       for( m=0; m<k; m++ )
+               peff[m] /= total;
+#endif
+       return( k );
+}
+
+int fastconjuction_noname_kozo( int *memlist, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d )
+{
+       int m, k, dln;
+       char b[B];
+       double total;
+       double total_kozo;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       total_kozo = 0.0;
+       d[0] = 0;
+       dln = 0;
+       for( k=0; *memlist!=-1; memlist++, k++ )
+       {
+               m = *memlist;
+               dln += sprintf( b, " %d", m+1 ); 
+#if 1
+               if( dln < 100 ) strcat( d, b );
+#else
+               strcat( d, b );
+#endif
+               aseq[k] = seq[m];
+               peff[k] = eff[m];
+               peff_kozo[k] = eff_kozo[m];
+               total += peff[k];
+               total_kozo += peff_kozo[k];
+       }
+#if 1
+       for( m=0; m<k; m++ )
+       {
+//             fprintf( stderr, "peff[%d] = %f\n", m, peff[m] );
+               peff[m] /= total;
+       }
+       if( total_kozo ) 
+       {
+               for( m=0; m<k; m++ )
+               {
+//                     fprintf( stderr, "peff[%d] = %f\n", m, peff[m] );
+                       peff_kozo[m] /= total_kozo;
+                       if( peff_kozo[m] > 0.0 ) peff_kozo[m] += peff[m];
+               }
+       }
+       else  //iranai
+       {
+               for( m=0; m<k; m++ )
+               {
+                       peff_kozo[m] = 0.0;
+               }
+       }
+#endif
+
+//     fprintf( stderr, "\n\ntbfast_total_kozo = %f\n\n", total_kozo );
+       return( k );
+}
+
+
+int fastconjuction_noname( int *memlist, char **seq, char **aseq, double *peff, double *eff, char *d )
+{
+       int m, k, dln;
+       char b[B];
+       double total;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       dln = 0;
+       for( k=0; *memlist!=-1; memlist++, k++ )
+       {
+               m = *memlist;
+               dln += sprintf( b, " %d", m+1 ); 
+#if 1
+               if( dln < 100 ) strcat( d, b );
+#else
+               strcat( d, b );
+#endif
+               aseq[k] = seq[m];
+               peff[k] = eff[m];
+               total += peff[k];
+       }
+#if 1
+       for( m=0; m<k; m++ )
+       {
+//             fprintf( stderr, "peff[%d] = %f\n", m, peff[m] );
+               peff[m] /= total;
+       }
+#endif
+       return( k );
+}
+
+int fastconjuction( int *memlist, char **seq, char **aseq, double *peff, double *eff, char name[M][B], char aname[M][B], char *d )
+{
+       int m, k, dln;
+       char b[B];
+       double total;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       dln = 0;
+       for( k=0; *memlist!=-1; memlist++, k++ )
+       {
+               m = *memlist;
+               dln += sprintf( b, " %d", m+1 ); 
+#if 1
+               if( dln < 100 ) strcat( d, b );
+#else
+               strcat( d, b );
+#endif
+               aseq[k] = seq[m];
+               peff[k] = eff[m];
+               total += peff[k];
+#if 0
+                       strcpy( aname[k], name[m] );
+#endif
+       }
+#if 1
+       for( m=0; m<k; m++ )
+               peff[m] /= total;
+#endif
+       return( k );
+}
+
+
+int conjuctionfortbfast_kozo( double *tmptmptmp, char **pair, int s, char **seq, char **aseq, double *peff, double *eff, double *peff_kozo, double *eff_kozo, char *d )
+{
+       int m, k;
+       char b[B];
+       double total;
+       double total_kozo;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+//     total_kozo = 0.0;
+       total_kozo = *tmptmptmp; // masaka
+       d[0] = 0;
+       for( m=s, k=0; m<njob; m++ )
+       {
+               if( pair[s][m] != 0 )
+               {
+                       sprintf( b, " %d", m+1 ); 
+#if 1
+                       if( strlen( d ) < 100 ) strcat( d, b );
+#else
+                       strcat( d, b );
+#endif
+                       aseq[k] = seq[m];
+                       peff[k] = eff[m];
+                       peff_kozo[k] = eff_kozo[m];
+                       total += peff[k];
+                       total_kozo += peff_kozo[k];
+#if 0
+                       strcpy( aname[k], name[m] );
+#endif
+                       k++;
+               }
+       }
+#if 1
+       for( m=0; m<k; m++ )
+               peff[m] /= total;
+       if( total_kozo > 0.0 )
+       {
+               for( m=0; m<k; m++ ) 
+               {
+                       peff_kozo[m] /= total_kozo;
+                       if( peff_kozo[m] > 0.0 ) peff_kozo[m] += peff[m];
+               }
+       }
+       else //iranai
+       {
+               for( m=0; m<k; m++ ) peff_kozo[m] = 0.0;
+       }
+#endif
+//     fprintf( stderr, "\n\ndvtditr_total_kozo = %f\n\n", total_kozo );
+       *tmptmptmp = total_kozo;
+       return( k );
+}
+
+int conjuctionfortbfast( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char *d )
+{
+       int m, k;
+       char *b;
+       double total;
+
+       b = calloc( B, sizeof( char ) );
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       for( m=s, k=0; m<njob; m++ )
+       {
+               if( pair[s][m] != 0 )
+               {
+                       sprintf( b, " %d", m+1 ); 
+#if 1
+                       if( strlen( d ) < 100 ) strcat( d, b );
+#else
+                       strcat( d, b );
+#endif
+                       aseq[k] = seq[m];
+                       peff[k] = eff[m];
+                       total += peff[k];
+#if 0
+                       strcpy( aname[k], name[m] );
+#endif
+                       k++;
+               }
+       }
+#if 1
+       for( m=0; m<k; m++ )
+               peff[m] /= total;
+#endif
+       free( b );
+       return( k );
+}
+int conjuction( char **pair, int s, char **seq, char **aseq, double *peff, double *eff, char **name, char **aname, char *d )
+{
+       int m, k;
+       char b[B];
+       double total;
+
+#if DEBUG
+       fprintf( stderr, "s = %d\n", s );
+#endif
+
+       total = 0.0;
+       d[0] = 0;
+       for( m=s, k=0; m<njob; m++ )
+       {
+               if( pair[s][m] != 0 )
+               {
+                       sprintf( b, " %d", m+1 ); 
+#if 1
+                       if( strlen( d ) < 100 ) strcat( d, b );
+#else
+                       strcat( d, b );
+#endif
+                       aseq[k] = seq[m];
+                       peff[k] = eff[m];
+                       total += peff[k];
+#if 0
+                       strcpy( aname[k], name[m] );
+#endif
+                       k++;
+               }
+       }
+#if 0
+       for( m=0; m<k; m++ )
+               peff[m] /= total;
+#endif
+       return( k );
+}
+                       
+void floatdelete( float **cpmx, int d, int len )
+{
+       int i, j;
+
+       for( i=d; i<len-1; i++ )
+       {
+               for( j=0; j<26; j++ )
+               {
+                       cpmx[j][i] = cpmx[j][i+1]; 
+               }
+       }
+}
+               
+void chardelete( char *seq, int d )
+{
+       char b[N]; 
+
+               strcpy( b, seq+d+1 );
+               strcpy( seq+d, b );
+}
+
+int RootBranchNode( int nseq, int ***topol, int step, int branch )
+{
+       int i, j, s1, s2, value;
+
+       value = 1;
+       for( i=step+1; i<nseq-2; i++ ) 
+       {
+               for( j=0; (s1=topol[i][0][j])>-1; j++ ) 
+                       if( s1 == topol[step][branch][0] ) value++;
+               for( j=0; (s2=topol[i][1][j])>-1; j++ ) 
+                       if( s2 == topol[step][branch][0] ) value++;
+       }
+       return( value );
+}
+
+void BranchLeafNode( int nseq, int ***topol, int *node, int step, int branch )
+{
+       int i, j, k, s;
+
+       for( i=0; i<nseq; i++ ) node[i] = 0;
+       for( i=0; i<step-1; i++ )
+               for( k=0; k<2; k++ ) 
+                       for( j=0; (s=topol[i][k][j])>-1; j++ ) 
+                               node[s]++;
+       for( k=0; k<branch+1; k++ ) 
+               for( j=0; (s=topol[step][k][j])>-1; j++ )
+                       node[s]++;
+}
+
+void RootLeafNode( int nseq, int ***topol, int *node )
+{
+       int i, j, k, s;
+       for( i=0; i<nseq; i++ ) node[i] = 0;
+       for( i=0; i<nseq-2; i++ )
+               for( k=0; k<2; k++ ) 
+                       for( j=0; (s=topol[i][k][j])>-1; j++ ) 
+                               node[s]++;
+}
+               
+void nodeFromABranch( int nseq, int *result, int **pairwisenode, int ***topol, double **len, int step, int num )
+{
+       int i, s, count;
+       int *innergroup;
+       int *outergroup1;
+#if 0
+       int outergroup2[nseq];
+       int table[nseq];
+#else
+       static int *outergroup2 = NULL;
+       static int *table = NULL;
+       if( outergroup2 == NULL )
+       {
+               outergroup2 = AllocateIntVec( nseq );
+               table = AllocateIntVec( nseq );
+       }
+#endif
+       innergroup = topol[step][num];
+       outergroup1 = topol[step][!num];
+       for( i=0; i<nseq; i++ ) table[i] = 1;
+       for( i=0; (s=innergroup[i])>-1; i++ ) table[s] = 0;
+       for( i=0; (s=outergroup1[i])>-1; i++ ) table[s] = 0;
+       for( i=0, count=0; i<nseq; i++ ) 
+       {
+               if( table[i] )
+               {
+                       outergroup2[count] = i;
+                       count++;
+               }
+       }
+       outergroup2[count] = -1;
+
+       for( i=0; (s=innergroup[i])>-1; i++ )
+       {
+               result[s] = pairwisenode[s][outergroup1[0]]
+                                 + pairwisenode[s][outergroup2[0]]
+                                 - pairwisenode[outergroup1[0]][outergroup2[0]] - 1;
+               result[s] /= 2;
+       }
+       for( i=0; (s=outergroup1[i])>-1; i++ ) 
+       {
+               result[s] = pairwisenode[s][outergroup2[0]]
+                                 + pairwisenode[s][innergroup[0]]
+                                 - pairwisenode[innergroup[0]][outergroup2[0]] + 1;
+               result[s] /= 2;
+       }
+       for( i=0; (s=outergroup2[i])>-1; i++ ) 
+       {
+               result[s] = pairwisenode[s][outergroup1[0]]
+                                 + pairwisenode[s][innergroup[0]]
+                                 - pairwisenode[innergroup[0]][outergroup1[0]] + 1;
+               result[s] /= 2;
+       }
+
+#if 0
+       for( i=0; i<nseq; i++ ) 
+               fprintf( stderr, "result[%d] = %d\n", i+1, result[i] );
+#endif
+}
+               
+
+
+
+
+       
+
+               
+               
+                                       
+                                       
+
+                               
+               
+
+#if 0
+void OneClusterAndTheOther( int locnjob, char pair[njob][njob], int *s1, int *s2, int ***topol, int step, int branch )
+#else
+void OneClusterAndTheOther( int locnjob, char **pair, int *s1, int *s2, int ***topol, int step, int branch )
+#endif
+{
+       int i;
+       int r1;
+       
+    *s1 = topol[step][branch][0];
+    for( i=0; (r1=topol[step][branch][i])>-1; i++ ) 
+        pair[*s1][r1] = 1;
+    for( i=0; i<locnjob; i++ ) 
+    {
+        if( !pair[*s1][i] ) 
+        {
+            *s2 = i;
+            break;
+        }
+    }
+    for( i=*s2; i<locnjob; i++ ) 
+    {
+        if( !pair[*s1][i] )
+            pair[*s2][i] = 1;
+    }
+}
+
+void makeEffMtx( int nseq, double **mtx, double *vec )
+{
+       int i, j;
+       for( i=0; i<nseq; i++ ) for( j=0; j<nseq; j++ ) 
+               mtx[i][j] = vec[i] * vec[j];
+}
+       
+void node_eff( int nseq, double *eff, int *node )
+{
+       int i;
+       extern double ipower( double, int );
+       for( i=0; i<nseq; i++ ) 
+               eff[i] = ipower( 0.5, node[i] ) + geta2;
+       /*
+               eff[i] = ipower( 0.5, node[i] ) + 0;
+       */
+#if DEBUG
+       for( i=0; i<nseq; i++ ) 
+#endif
+}
+
+
+int shrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink )
+{
+       int m1, k1, m2, k2;
+
+       for( m1=s1, k1=0; m1<njob; m1++ )
+       {
+               if( pair[s1][m1] != 0 )
+               {
+                       for( m2=s2, k2=0; m2<njob; m2++ )
+                       {
+                               if( pair[s2][m2] != 0 )
+                               {
+                                       if( localhom[m1][m2].opt == -1 )
+                                               localhomshrink[k1][k2] = NULL;
+                                       else
+                                               localhomshrink[k1][k2] = localhom[m1]+m2;
+                                       k2++;
+                               }
+                       }
+                       k1++;
+               }
+       }
+       return( 0 );
+}
+int msshrinklocalhom( char **pair, int s1, int s2, LocalHom **localhom, LocalHom ***localhomshrink )
+{
+       int m1, k1, n1, m2, k2, n2;
+
+       for( m1=s1, k1=0; m1<njob; m1++ )
+       {
+               if( pair[s1][m1] != 0 )
+               {
+                       for( m2=s2, k2=0; m2<njob; m2++ )
+                       {
+                               if( pair[s2][m2] != 0 )
+                               {
+                                       n1 = MIN(m1,m2); n2=MAX(m1,m2);
+                                       if( localhom[m1][m2].opt == -1 )
+                                               localhomshrink[k1][k2] = NULL;
+                                       else
+                                               localhomshrink[k1][k2] = localhom[n1]+n2;
+                                       k2++;
+                               }
+                       }
+                       k1++;
+               }
+       }
+       return( 0 );
+}
+
+int fastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink )
+{
+       int k1, k2;
+       int *intpt1, *intpt2;
+
+       
+       for( intpt1=mem1, k1=0; *intpt1!=-1; intpt1++, k1++ )
+       {
+               for( intpt2=mem2, k2=0; *intpt2!=-1; intpt2++, k2++ )
+               {
+                       if( localhom[*intpt1][*intpt2].opt == -1 )
+                               localhomshrink[k1][k2] = NULL;
+                       else
+                               localhomshrink[k1][k2] = localhom[*intpt1]+*intpt2;
+               }
+       }
+       return( 0 );
+}
+
+int msfastshrinklocalhom( int *mem1, int *mem2, LocalHom **localhom, LocalHom ***localhomshrink )
+{
+       int k1, k2;
+       int *intpt1, *intpt2;
+       int m1, m2;
+       
+       for( intpt1=mem1, k1=0; *intpt1!=-1; intpt1++, k1++ )
+       {
+               for( intpt2=mem2, k2=0; *intpt2!=-1; intpt2++, k2++ )
+               {
+                       m1 = MIN(*intpt1,*intpt2); m2 = MAX(*intpt1,*intpt2);
+                       if( localhom[m1][m2].opt == -1 )
+                               localhomshrink[k1][k2] = NULL;
+                       else
+                               localhomshrink[k1][k2] = localhom[m1]+m2;
+               }
+       }
+       return( 0 );
+}
+
diff --git a/binaries/src/mafft/core/tditeration.c b/binaries/src/mafft/core/tditeration.c
new file mode 100644 (file)
index 0000000..e461f09
--- /dev/null
@@ -0,0 +1,2399 @@
+
+/* 
+       tree-dependent iteration   
+    algorithm A+ when group-to-group, C when group-to-singleSeqence 
+                        OR
+    algorithm A+
+*/
+
+#include "mltaln.h"
+
+
+#define DEBUG 0
+#define RECORD 0
+
+extern char **seq_g;
+extern char **res_g;
+
+static int nwa;
+
+#ifdef enablemultithread
+typedef struct _threadarg
+{
+       int thread_no;
+       int *jobposintpt;
+       int *ndonept;
+       int *ntrypt;
+       int *collectingpt;
+       int njob;
+       int nbranch;
+       int maxiter;
+       int nkozo;
+       int *subgenerationpt;
+       float *basegainpt;
+       float *gainlist;
+       float *tscorelist;
+       int *generationofinput;
+       char *kozoarivec;       
+       char **mastercopy;
+       char ***candidates;
+       int *generationofmastercopypt;
+       int *branchtable;
+       RNApair ***singlerna;
+       LocalHom **localhomtable;
+       int alloclen;
+       Node *stopol;
+       int ***topol;
+//     double **len;
+       float **tscorehistory_detail;
+       int *finishpt;
+       pthread_mutex_t *mutex;
+       pthread_cond_t *collection_end;
+       pthread_cond_t *collection_start;
+} threadarg_t;
+#endif
+
+#if 1
+static void shuffle( int *arr, int n )
+{
+       int i;
+       int x;
+       int b;
+
+       for( i=1; i<n; i++ )
+       {
+               x = rand() % (i+1);
+               if( x != i )
+               {
+                       b = arr[i];
+                       arr[i] = arr[x];
+                       arr[x] = b;
+               }
+       }
+}
+#endif
+
+static void Writeoption2( FILE *fp, int cycle, double cut )
+{
+       fprintf( fp, "%dth cycle\n", cycle );
+    fprintf( fp, "marginal score to search : current score * (100-%d) / 100\n", (int)cut );
+}
+
+static void Writeoptions( FILE *fp )
+{
+       fprintf( fp, "Tree-dependent-iteration\n" );
+    if( scoremtx == 1 )
+        fprintf( fp, "Blosum %d\n", nblosum );
+    else if( scoremtx == -1 )
+        fprintf( fp, "DNA\n" );
+    else if( scoremtx == 2 )
+        fprintf( fp, "Miyata-Yasunaga\n" );
+       else
+               fprintf( fp, "JTT %dPAM\n", pamN );
+
+       if( scoremtx == 0 || scoremtx == 1 )
+       fprintf( fp, "Gap Penalty = %+5.3f, %5.2f, %+5.3f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
+       else
+               fprintf( fp, "Gap Penalty = %+5.3f\n", (double)penalty/1000 );
+               
+
+    if( scmtd == 3 )
+        fprintf( fp, "score of rnd or sco\n" );
+    else if( scmtd == 4 )
+        fprintf( fp, "score = sigma( score for a pair of homologous amino acids ) / ( number of amino acids pairs )\n" );
+    else if( scmtd == 5 )
+        fprintf( fp, "score : SP\n" );
+    if( mix )
+        fprintf( fp, "?\n" );
+    else
+    { 
+        if( weight == 2 )
+            fprintf( fp, "weighted rationale-1,  geta2 = %f\n", geta2 );
+        else if( weight == 3 )
+            fprintf( fp, "weighted like ClustalW," );
+        else if( weight == 4 )
+            fprintf( fp, "weighted rationale-2,  geta2 = %f\n", geta2 );
+        else
+            fprintf( fp, "unweighted\n" );
+    }
+    if( weight && utree )
+        fprintf( fp, "using tree defined by the file hat2.\n" );
+    if( weight && !utree )
+        fprintf( fp, "using temporary tree.\n" );
+
+       if( treemethod == 'n' )
+               fprintf( fp, "Tree is calculated with Neighbor-Joining Method.\n" );
+       else if( treemethod == 'q' )
+               fprintf( fp, "Tree is calculated with Minimum linkage.\n" );
+       else if( treemethod == 'X' )
+               fprintf( fp, "Tree is calculated with simplified UPG Method and UPG Method.\n" );
+       else if( treemethod == 'E' )
+               fprintf( fp, "Tree is calculated with UPG Method.\n" );
+       else
+               fprintf( fp, "Tree is calculated with unknown Method.\n" );
+               
+       if( alg == 'C' ) 
+               fprintf( fp, "Algorithm A+ / C\n" );
+       else if( alg == 'A' ) 
+               fprintf( fp, "Algorithm A+ \n" );
+       else if( alg == 'a' ) 
+               fprintf( fp, "Algorithm A \n" );
+       else 
+               fprintf( fp, "Algorithm ? \n" );
+
+       if( use_fft )
+       {
+               if( scoremtx == -1 )
+               {
+                       fprintf( fp, "Basis : 4 nucleotides\n" );
+               }
+               else
+               {
+                       if( fftscore )
+                               fprintf( fp, "Basis : Polarity and Volume\n" );
+                       else
+                               fprintf( fp, "Basis : 20 amino acids\n" );
+               }
+               fprintf( fp, "Threshold   of anchors = %d%%\n", fftThreshold );
+               fprintf( fp, "window size of anchors = %dsites\n", fftWinSize );
+       }
+}
+
+#ifdef enablemultithread
+
+static void freelocalarrays( 
+       float *tscorehistory,
+       RNApair ***grouprna1, RNApair ***grouprna2,
+       RNApair *rnapairboth,
+       char *indication1, char *indication2,
+       double *effarr, double *effarrforlocalhom, double *effarr1, double *effarr2,
+       char **mseq1, char **mseq2,
+       char **localcopy,
+       int *gapmap1, int *gapmap2,
+       double *effarr1_kozo, double *effarr2_kozo, double *effarr_kozo,
+       char **pair,
+       LocalHom *** localhomshrink
+)
+{
+//     fprintf( stderr, "Skipping freelocalarrays\n" );
+//     return;
+       int i;
+       if( commonIP ) FreeIntMtx( commonIP );
+       commonIP = NULL;
+       Falign( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, 0, NULL );
+       Falign_localhom( NULL, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL,NULL, 0, NULL );
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               free( grouprna1 ); // nakamimo?
+               free( grouprna2 ); // nakamimo?
+       }
+
+       free( tscorehistory );
+       free( indication1 );
+       free( indication2 );
+       free( effarr );
+       free( effarrforlocalhom );
+       free( effarr1 );
+       free( effarr2 );
+       free( mseq1 );
+       free( mseq2 );
+       FreeCharMtx( localcopy );
+       free( gapmap1 );
+       free( gapmap2 );
+
+       free( effarr1_kozo );
+       free( effarr2_kozo );
+       free( effarr_kozo );
+
+       FreeCharMtx( pair );
+
+       if( rnakozo ) free( rnapairboth );
+
+       if( constraint )
+       {
+               for( i=0; i<njob; i++)
+               {
+                       free( localhomshrink[i] ); // nakamimo??
+               }
+               free( localhomshrink );
+       }
+}
+
+
+static void *athread( void *arg )
+{
+
+       threadarg_t *targ = (threadarg_t *)arg;
+       int thread_no = targ->thread_no;
+       int njob = targ->njob;
+       int nbranch = targ->nbranch;
+       int maxiter = targ->maxiter;
+       int *ndonept = targ->ndonept;
+       int *ntrypt = targ->ntrypt;
+       int *collectingpt = targ->collectingpt;
+       int *jobposintpt = targ->jobposintpt;
+       int nkozo = targ->nkozo;
+       float *gainlist = targ->gainlist;
+       float *tscorelist = targ->tscorelist;
+       int *generationofinput = targ->generationofinput;
+       int *subgenerationpt = targ->subgenerationpt;
+       float *basegainpt = targ->basegainpt;
+       char *kozoarivec = targ->kozoarivec;    
+       char **mastercopy = targ->mastercopy;
+       char ***candidates = targ->candidates;
+       int *generationofmastercopypt = targ->generationofmastercopypt;
+       int *branchtable = targ->branchtable;
+       RNApair ***singlerna = targ->singlerna;
+       LocalHom **localhomtable = targ->localhomtable;
+       int alloclen = targ->alloclen;
+       Node * stopol = targ->stopol;
+       int ***topol = targ->topol;
+//     double **len = targ->len;
+       float **tscorehistory_detail = targ->tscorehistory_detail;
+       int *finishpt = targ->finishpt;
+
+       int i, j, k, l, ii;
+       float gain;
+       int iterate;
+       char **pair;
+       int locnjob;
+       int s1, s2;
+       int clus1, clus2;
+       char **localcopy;
+       char **mseq1, **mseq2;
+       double *effarr, *effarr_kozo; // re-calc 
+       double *effarr1, *effarr2, *effarr1_kozo, *effarr2_kozo;
+       char *indication1, *indication2;
+       int length;
+       RNApair ***grouprna1, ***grouprna2;
+       RNApair *rnapairboth;
+       LocalHom ***localhomshrink;
+       int *gapmap1, *gapmap2;
+       float tscore, mscore, oimpmatch, impmatch;
+       int identity;
+       double tmpdouble;
+       float naivescore0 = 0, naivescore1;
+       double *effarrforlocalhom;
+       float *tscorehistory;
+       int intdum;
+#if 0
+       int oscillating;
+       int lin, ldf;
+#endif
+       float maxgain;
+       int bestthread;
+       int branchpos;
+       int subgenerationatfirst;
+       double unweightedspscore;
+       int myjob;
+       int converged2 = 0;
+       int chudanres;
+
+
+       locnjob = njob;
+
+       if( utree == 0 )
+       {
+               fprintf( stderr, "Dynamic tree is not supported in the multithread version.\n" );
+               exit( 1 );
+       }
+       if( score_check == 2 )
+       {
+               fprintf( stderr, "Score_check 2 is not supported in the multithread version.\n" );
+               exit( 1 );
+       }
+
+       if( weight == 2 )
+       {
+               fprintf( stderr, "Weight 2 is not supported in the multithread version.\n" );
+               exit( 1 );
+       }
+       if( cooling &&  cut > 0.0 )
+       {
+               fprintf( stderr, "Cooling is not supported in the multithread version.\n" );
+               exit( 1 );
+       }
+
+       tscorehistory = calloc( maxiter, sizeof( float ) );
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       }
+       else
+       {
+               grouprna1 = grouprna2 = NULL;
+       }
+
+       indication1 = AllocateCharVec( njob*3+50 );
+       indication2 = AllocateCharVec( njob*3+50 );
+       effarr = AllocateDoubleVec( locnjob );
+       effarrforlocalhom = AllocateDoubleVec( locnjob );
+       effarr1 = AllocateDoubleVec( locnjob );
+       effarr2 = AllocateDoubleVec( locnjob );
+       mseq1 = AllocateCharMtx( locnjob, 0 );
+       mseq2 = AllocateCharMtx( locnjob, 0 );
+       localcopy = AllocateCharMtx( locnjob, alloclen );
+       gapmap1 = AllocateIntVec( alloclen );
+       gapmap2 = AllocateIntVec( alloclen );
+
+       effarr1_kozo = AllocateDoubleVec( locnjob ); // tsuneni allocate suru.
+       effarr2_kozo = AllocateDoubleVec( locnjob ); // tsuneni allocate suru.
+       effarr_kozo = AllocateDoubleVec( locnjob ); 
+       for( i=0; i<locnjob; i++ )
+               effarr_kozo[i] = effarr1_kozo[i] = effarr2_kozo[i] = 0.0;
+
+       pair = AllocateCharMtx( locnjob, locnjob );
+
+
+       if( rnakozo ) rnapairboth = (RNApair *)calloc( alloclen, sizeof( RNApair ) );
+
+       if( constraint )
+       {
+               localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) );
+               for( i=0; i<njob; i++)
+               {
+                       localhomshrink[i] = (LocalHom **)calloc( njob, sizeof( LocalHom * ) );
+               }
+       }
+
+
+       if( thread_no == 0 )
+       {
+               *ntrypt = 0;
+               srand( randomseed );
+               *finishpt = 0;
+               for( iterate=0; iterate<maxiter; iterate++ ) 
+               {
+                       pthread_mutex_lock( targ->mutex );
+
+                       if( *collectingpt == 1 )
+                       {
+                               *collectingpt = 0;
+                               *generationofmastercopypt = iterate;
+                               *subgenerationpt = 0;
+                               *basegainpt = 0.0;
+                               *ndonept = 0;
+                               *jobposintpt = 0;
+                               for( i=0; i<nwa; i++ ) gainlist[i] = 0;
+                               for( i=0; i<nwa; i++ ) tscorelist[i] = 0.0;
+                               for( i=0; i<nbranch; i++ ) generationofinput[i] = -1;
+                               if( parallelizationstrategy != BESTFIRST && randomseed != 0 ) shuffle( branchtable, nbranch );
+                               pthread_cond_broadcast( targ->collection_end );
+                               pthread_mutex_unlock( targ->mutex );
+                       }
+                       else
+                       {
+                               pthread_cond_broadcast( targ->collection_end );
+                               pthread_mutex_unlock( targ->mutex );
+                               freelocalarrays
+                               ( 
+                                       tscorehistory,
+                                       grouprna1, grouprna2,
+                                       rnapairboth,
+                                       indication1, indication2,
+                                       effarr, effarrforlocalhom, effarr1, effarr2,
+                                       mseq1, mseq2,
+                                       localcopy,
+                                       gapmap1, gapmap2,
+                                       effarr1_kozo, effarr2_kozo, effarr_kozo,
+                                       pair,
+                                       localhomshrink
+                               );
+//                             return( NULL );
+                               pthread_exit( NULL );
+                       }
+
+                       pthread_mutex_lock( targ->mutex );
+                       while( *ndonept < nbranch )
+                               pthread_cond_wait( targ->collection_start, targ->mutex );
+                       pthread_mutex_unlock( targ->mutex );
+//                     fprintf( stderr, "Thread 0 got a signal, *collectionpt = %d\n", *collectingpt );
+
+/* 
+                       Hoka no thread ga keisan
+*/
+
+                       pthread_mutex_lock( targ->mutex );
+                       *collectingpt = 1; // chofuku
+
+#if 0
+                       for( i=0; i<nbranch; i++ )
+                       {
+                               if( generationofinput[i] != iterate )
+                               {
+                                       fprintf( stderr, "Error! generationofinput[%d] = %d, but iterate=%d\n", i, generationofinput[i], iterate );
+                                       exit( 1 );
+
+                               }
+                       }
+#endif
+       
+                       maxgain = gainlist[1];
+                       bestthread = 1;
+                       for( i=2; i<nwa; i++ )
+                       {
+                               if( gainlist[i] > maxgain )
+                               {
+                                       maxgain = gainlist[i];
+                                       bestthread = i;
+                               }
+                       }
+       
+                       if( maxgain > 0.0 )
+                       {
+//                             fprintf( stderr, "\nGain = %f\n", maxgain );
+//                             fprintf( stderr, "best gain = %f by thread %d\n", gainlist[bestthread], bestthread );
+//                             fprintf( stderr, "tscorelist[best] = %f by thread %d\n", tscorelist[bestthread], bestthread );
+                               if( parallelizationstrategy == BESTFIRST )
+                               {
+                                       for( i=0; i<locnjob; i++ ) strcpy( mastercopy[i], candidates[bestthread][i] );
+                                       if( scoreout )
+                                       {
+                                               unweightedspscore = plainscore( locnjob, mastercopy );
+                                               fprintf( stderr, "\nSCORE %d = %.0f, ", iterate * nbranch, unweightedspscore );
+                                               fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( locnjob * strlen( mastercopy[0] ) ) );
+                                               if( weight || constraint ) fprintf( stderr, " (differs from the objective score)" );
+                                               fprintf( stderr, "\n" );
+                                       }
+                               }
+#if 1
+//                             fprintf( stderr, "gain(%d, by %d) = %f\n", iterate, bestthread, maxgain );
+                               for( i=iterate-1; i>0; i-- )
+                               {
+//                                     if( iterate-i < 15 ) fprintf( stderr, "hist[%d] = %f\n", i, tscorehistory[i] );
+                                       if( tscorehistory[i] == tscorelist[bestthread] )
+                                       {
+                                               fprintf( stderr, "\nOscillating? %f == %f\n", tscorehistory[i], tscorelist[bestthread] );
+                                               *collectingpt = -1;
+                                               break;
+                                       }
+                               }
+                               tscorehistory[iterate] = tscorelist[bestthread];
+#endif
+                       }
+                       else
+                       {
+                               fprintf( stderr, "\nConverged.\n" );
+                               *collectingpt = -1;
+//                             pthread_cond_broadcast( targ->collection_end );
+//                             pthread_mutex_unlock( targ->mutex );
+//                             freelocalarrays();
+//                             return( NULL );
+//                             pthread_exit( NULL );
+                       }
+
+#if 1
+                       if( *finishpt )
+                       {
+                               fprintf( stderr, "\nConverged2.\n" );
+                               *collectingpt = -1;
+                       }
+#endif
+
+                       pthread_mutex_unlock( targ->mutex );
+               }
+               pthread_mutex_lock( targ->mutex );
+               fprintf( stderr, "\nReached %d\n", maxiter );
+               *collectingpt = -1;
+               pthread_cond_broadcast( targ->collection_end );
+               pthread_mutex_unlock( targ->mutex );
+               freelocalarrays
+               ( 
+                       tscorehistory,
+                       grouprna1, grouprna2,
+                       rnapairboth,
+                       indication1, indication2,
+                       effarr, effarrforlocalhom, effarr1, effarr2,
+                       mseq1, mseq2,
+                       localcopy,
+                       gapmap1, gapmap2,
+                       effarr1_kozo, effarr2_kozo, effarr_kozo,
+                       pair,
+                       localhomshrink
+               );
+               return( NULL );
+               pthread_exit( NULL );
+       }
+       else
+       {
+               while( 1 )
+               {
+#if 0
+                       if( iterate % 2 == 0 ) 
+                       {
+                               lin = 0; ldf = +1;
+                       }
+                       else
+                       {
+                               lin = locnjob - 2; ldf = -1;
+                       }       
+                       for( l=lin; l < locnjob-1 && l >= 0 ; l+=ldf )
+                               for( k=0; k<2; k++ ) 
+#endif
+
+                       pthread_mutex_lock( targ->mutex );
+                       while( *collectingpt > 0 )
+                               pthread_cond_wait( targ->collection_end, targ->mutex );
+                       if( *collectingpt == -1 )
+                       {
+                               pthread_mutex_unlock( targ->mutex );
+                               freelocalarrays
+                               ( 
+                                       tscorehistory,
+                                       grouprna1, grouprna2,
+                                       rnapairboth,
+                                       indication1, indication2,
+                                       effarr, effarrforlocalhom, effarr1, effarr2,
+                                       mseq1, mseq2,
+                                       localcopy,
+                                       gapmap1, gapmap2,
+                                       effarr1_kozo, effarr2_kozo, effarr_kozo,
+                                       pair,
+                                       localhomshrink
+                               );
+                               return( NULL );
+                               pthread_exit( NULL );
+                       }
+//                     pthread_mutex_unlock( targ->mutex );
+
+
+//                     pthread_mutex_lock( targ->mutex );
+                       if( *jobposintpt == nbranch )
+                       {
+                               if( *collectingpt != -1 ) *collectingpt = 1; // chofuku
+                               pthread_mutex_unlock( targ->mutex );
+                               continue;
+                       }
+//                     fprintf( stderr, "JOB jobposintpt=%d\n", *jobposintpt );
+                       myjob = branchtable[*jobposintpt];
+                       l = myjob / 2;
+                       if( l == locnjob-2 ) k = 1;
+                       else k = myjob - l * 2;
+//                     fprintf( stderr, "JOB l=%d, k=%d\n", l, k );
+                       branchpos = myjob;
+                       (*jobposintpt)++;
+                       iterate = *generationofmastercopypt;
+                       (*ntrypt)++;
+                       pthread_mutex_unlock( targ->mutex );
+
+
+
+//                     fprintf( stderr, "branchpos = %d (thread %d)\n", branchpos, thread_no );
+
+//                     fprintf( stderr, "iterate=%d, l=%d, k=%d (thread %d)\n", iterate, l, k, thread_no );
+
+#if 0
+                       fprintf( stderr, "STEP %03d-%03d-%d (Thread %d)    ", iterate+1, l+1, k, thread_no );
+                       fprintf( stderr, "STEP %03d-%03d-%d (thread %d) %s       ", iterate+1, l+1, k, thread_no, use_fft?"\n":"\n" );
+#endif
+                       for( i=0; i<locnjob; i++ ) for( j=0; j<locnjob; j++ ) pair[i][j] = 0;
+
+                       OneClusterAndTheOther( locnjob, pair, &s1, &s2, topol, l, k );
+#if 0
+                       fprintf( stderr, "STEP%d-%d\n", l, k );
+                       for( i=0; i<locnjob; i++ ) 
+                       {
+                               for( j=0; j<locnjob; j++ ) 
+                               {
+                                       fprintf( stderr, "%#3d", pair[i][j] );
+                               }
+                               fprintf( stderr, "\n" );
+                       }
+#endif
+                       if( !weight )
+                       {
+                               for( i=0; i<locnjob; i++ ) effarr[i] = 1.0;
+                               if( nkozo )
+                               {
+                                       for( i=0; i<locnjob; i++ ) 
+                                       {
+                                               if( kozoarivec[i] )
+                                                       effarr_kozo[i] = 1.0;
+                                               else
+                                                       effarr_kozo[i] = 0.0;
+                                       }
+                               }
+                       }
+                       else if( weight == 4 )
+                       {
+                               weightFromABranch( locnjob, effarr, stopol, topol, l, k );
+                               if( nkozo ) // hitomadu single weight.
+                               {
+                                       for( i=0; i<locnjob; i++ ) 
+                                       {
+                                               if( kozoarivec[i] ) effarr_kozo[i] = effarr[i]; 
+                                               else effarr_kozo[i] = 0.0;
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               fprintf( stderr, "weight error!\n" );
+                               exit( 1 );
+                       }
+
+                       yarinaoshi:
+
+                       pthread_mutex_lock( targ->mutex );
+                       for( i=0; i<locnjob; i++ ) strcpy( localcopy[i], mastercopy[i] );
+                       subgenerationatfirst = *subgenerationpt;
+                       pthread_mutex_unlock( targ->mutex );
+                       length = strlen( localcopy[0] );
+
+                       if( nkozo )
+                       {
+                               double tmptmptmp;
+                               tmptmptmp = 0.0;
+                               clus1 = conjuctionfortbfast_kozo( &tmptmptmp, pair, s1, localcopy, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 );
+                               for( i=0; i<clus1; i++ ) effarr1_kozo[i] *= 1.0; // 0.5 ga sairyo ?
+                               tmptmptmp = 0.0;
+                               clus2 = conjuctionfortbfast_kozo( &tmptmptmp, pair, s2, localcopy, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 );
+                               for( i=0; i<clus2; i++ ) effarr2_kozo[i] *= 1.0; // 0.5 ga sairyo ?
+
+#if 0
+                               fprintf( stderr, "\ngroup1 = %s\n", indication1 );
+                               for( i=0; i<clus1; i++ ) fprintf( stderr, "effarr1_kozo[%d], effarr1[]  = %f, %f\n", i, effarr1_kozo[i], effarr1[i] );
+                               fprintf( stderr, "\ngroup2 = %s\n", indication2 );
+                               for( i=0; i<clus2; i++ ) fprintf( stderr, "effarr2_kozo[%d], effarr2[]  = %f, %f\n", i, effarr2_kozo[i], effarr2[i] );
+#endif
+                       }
+                       else
+                       {
+                               clus1 = conjuctionfortbfast( pair, s1, localcopy, mseq1, effarr1, effarr, indication1 );
+                               clus2 = conjuctionfortbfast( pair, s2, localcopy, mseq2, effarr2, effarr, indication2 );
+                       }
+
+               if( rnakozo && rnaprediction == 'm' )
+               {       
+                               makegrouprnait( grouprna1, singlerna, pair, s1 );
+                               makegrouprnait( grouprna2, singlerna, pair, s2 );
+               }       
+
+                       if( score_check == 2 )
+                       {
+                               fprintf( stderr, "Score_check 2 is not supported in the multithread version.\n" );
+                               exit( 1 );
+                       }
+                       else if( score_check )
+                       {
+                               if( RNAscoremtx == 'r' )
+                                       intergroup_score_gapnomi( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble ); // gappick mae denaito dame
+                               else
+                                       intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble ); // gappick mae denaito dame
+
+                               if( constraint )
+                               {
+                                       shrinklocalhom( pair, s1, s2, localhomtable, localhomshrink );
+//                                     weightimportance4( clus1, clus2,  effarr1, effarr2, localhomshrink ); // >>>
+                                       oimpmatch = 0.0;
+                                       if( use_fft )
+                                       {
+                                               if( alg == 'Q' )
+                                               {
+                                                       part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                       if( rnakozo ) part_imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += part_imp_match_out_scQ( i, i );
+//                                                             fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                       if( rnakozo ) part_imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += part_imp_match_out_sc( i, i );
+//                                                             fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                       }
+                                               }
+//                                             fprintf( stderr, "otmpmatch = %f\n", oimpmatch );
+                                       }
+                                       else
+                                       {
+                                               if( alg == 'Q' )
+                                               {
+                                                       imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                       if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += imp_match_out_scQ( i, i );
+//                                                             fprintf( stderr, "#### i=%d, initial impmatch = %f\n", i, oimpmatch );
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+
+                                                       fprintf( stderr, "not supported\n" );
+                                                       exit( 1 );
+
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += imp_match_out_sc( i, i );
+//                                                             fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                       }
+                                               }
+//                                             fprintf( stderr, "otmpmatch = %f\n", oimpmatch );
+                                       }
+//                                     fprintf( stderr, "#### initial impmatch = %f\n", oimpmatch );
+                               }
+                               else
+                               {
+                                       oimpmatch = 0.0;
+                               }
+
+
+//                             fprintf( stderr, "#### tmpdouble = %f\n", tmpdouble );
+                               mscore = (double)oimpmatch + tmpdouble;
+                       }
+                       else
+                       {
+                               fprintf( stderr, "score_check = %d\n", score_check );
+                               fprintf( stderr, "Not supported\n" );
+                               exit( 1 );
+                       }
+
+
+//                     if( rnakozo ) foldalignedrna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, rnapairboth );
+
+//                     if( !use_fft && !rnakozo )
+                       if( !use_fft )
+                       {
+                               commongappick_record( clus1, mseq1, gapmap1 );
+                               commongappick_record( clus2, mseq2, gapmap2 );
+                       }
+
+#if 0
+                       fprintf( stderr, "##### mscore = %f\n", mscore );
+#endif
+
+#if DEBUG
+                       if( !devide )
+                       {
+                       fprintf( trap_g, "\n%d-%d-%d\n", iterate+1, l+1, k );
+                       fprintf( trap_g, "group1 = %s\n", indication1 );
+                       fprintf( trap_g, "group2 = %s\n", indication2 );
+                               fflush( trap_g );
+                       }
+
+#endif
+#if 0
+                       printf( "STEP %d-%d-%d\n", iterate, l, k );
+                       for( i=0; i<clus2; i++ ) printf( "%f ", effarr2[i] );
+                       printf( "\n" );
+#endif
+                       if( constraint == 2 )
+                       {
+                               if( use_fft )
+                               {
+//                                     if( alg == 'Q' )
+//                                             part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+//                                     else
+//                                             part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                       chudanres = 0;
+                                       Falign_localhom( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, gapmap1, gapmap2, subgenerationpt, subgenerationatfirst, &chudanres );
+//                                     fprintf( stderr, "##### impmatch = %f\n", impmatch );
+                                       if( chudanres && parallelizationstrategy == BAATARI2 )
+                                       {
+//                                             fprintf( stderr, "#### yarinaoshi!!! INS-i\n" );
+                                               goto yarinaoshi;
+                                       }
+                               }
+                               else
+                               {
+                                       if( alg == 'Q' )
+                                       {
+                                               float wm;
+//                                             imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap  wo tsukuttakara iranai.
+//                                             if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, gapmap1, gapmap2, rnapairboth );
+
+                                               wm = Q__align_gapmap( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL, gapmap1, gapmap2 );
+                                               fprintf( stderr, "wm = %f\n", wm );
+#if 0
+                                               fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                               naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+                                               fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+
+                                               if( naivescore1 > naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                               else if( naivescore1 < naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                               else
+                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 0 // chuui
+                                               if( abs( wm - naivescore1 ) > 100 )
+                                               {
+//                                                     fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+//                                                     rewind( stdout );
+//                                                     for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                                     for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                                     exit( 1 );
+                                               }
+#endif
+#endif
+                                       }
+                                       else if( alg == 'R' )
+                                       {
+                                               float wm;
+                                               imp_match_init_strictR( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap ha mada
+                                               wm = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL );
+//                                             fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                               naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+//                                             fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+
+                                               if( naivescore1 > naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: %f->%f UP!\n", clus1, clus2, naivescore0, naivescore1 );
+                                               else if( naivescore1 < naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                               else
+                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 0 // chuui
+                                               if( abs( wm - naivescore1 ) > 100 )
+                                               {
+//                                                     fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+                                                       rewind( stdout );
+                                                       for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+                                                       for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+                                                       exit( 1 );
+                                               }
+#endif
+                                       }
+                                       else if( alg == 'H' )
+                                       {
+                                                       float wm;
+                                               imp_match_init_strictH( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap ha mada
+                                               wm = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL );
+                                               fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                               naivescore1 = naivepairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+                                               fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+
+                                               if( naivescore1 > naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                               else if( naivescore1 < naivescore0 )
+                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                               else
+                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 0 // chuui
+                                               if( abs( wm - naivescore1 ) > 100 )
+                                               {
+//                                                     fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+//                                                     for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                                     for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                                     exit( 1 );
+                                               }
+#endif
+                                       }
+                                       else
+                                       {
+//                                             imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                               A__align_gapmap( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, gapmap1, gapmap2 );
+                                               fprintf( stderr, "A__align_gapmap\n" );
+//                                             fprintf( stderr, "##### impmatch = %f\n", impmatch );
+                                       }
+                               }
+                       }
+                       else if( use_fft )
+                       {
+                               float totalwm;
+                               chudanres = 0;
+                               totalwm = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, subgenerationpt, subgenerationatfirst, &chudanres );
+                               if( chudanres && parallelizationstrategy == BAATARI2 )
+                               {
+//                                     fprintf( stderr, "#### yarinaoshi!!! FFT-NS-i\n" );
+                                       goto yarinaoshi;
+                               }
+
+//                             fprintf( stderr, "totalwm = %f\n", totalwm );
+#if 0
+                               if( alg == 'Q' )
+                               {
+                                       fprintf( stderr, "totalwm = %f\n", totalwm );
+                                       naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+
+                                       if( naivescore1 > naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                       else if( naivescore1 < naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                       else
+                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 1 // chuui
+                                       if( totalwm != 0.0 && abs( totalwm - naivescore1 ) > 100 )
+                                       {
+//                                             fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+//                                             for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                             for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                             exit( 1 );
+                                       }
+#endif
+                               }
+#endif
+                               if( alg == 'R' )
+                               {
+                                       fprintf( stderr, "totalwm = %f\n", totalwm );
+                                       naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+
+                                       if( naivescore1 > naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                       else if( naivescore1 < naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                       else
+                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 1 // chuui
+                                       if( totalwm != 0.0 && abs( totalwm - naivescore1 ) > 100 )
+                                       {
+//                                             fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+//                                             for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                             for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                             exit( 1 );
+                                       }
+                               }
+#endif
+                       }
+                       else
+                       {
+                               if( alg == 'M' )
+                               {
+                                       chudanres = 0;
+                                       MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, subgenerationpt, subgenerationatfirst, &chudanres, outgap, outgap );
+                                       if( chudanres && parallelizationstrategy == BAATARI2 )
+                                       {
+//                                             fprintf( stderr, "#### yarinaoshi!!! NW-NS-i\n" );
+                                               goto yarinaoshi;
+                                       }
+                               }
+                               else if( alg == 'A' )
+                               {
+                                       A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL, NULL, 0, NULL, 1, 1 ); //outgap==1
+                               }
+                               else if( alg == 'Q' )
+                               {
+                                       float wm;
+                                       wm = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                       fprintf( stderr, "wm = %f\n", wm );
+                                       fprintf( stderr, "impmatch = %f\n", impmatch );
+                                       naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+
+                                       if( naivescore1 > naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                       else if( naivescore1 < naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: DOWN!\n", clus1, clus2 );
+                                       else
+                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 1 // chuui
+                                       if( abs( wm - naivescore1 ) > 100 )
+                                       {
+//                                             fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+//                                             rewind( stderr );
+//                                             rewind( stdout );
+//                                             for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                             for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                             exit( 1 );
+                                       }
+#endif
+                               }
+                               else if( alg == 'R' )
+                               {
+                                       float wm;
+                                       wm = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                       naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+
+                                       if( naivescore1 > naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                       else if( naivescore1 < naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                       else
+                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+#if 1 // chuui
+                                       if( abs( wm - naivescore1 ) > 100 )
+                                       {
+//                                             fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+//                                             rewind( stderr );
+//                                             rewind( stdout );
+//                                             for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+//                                             for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+//                                             exit( 1 );
+                                       }
+#endif
+                               }
+                               else if( alg == 'H' )
+                               {
+                                       float wm;
+                                       wm = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                       naivescore1 = naivepairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+
+                                       if( naivescore1 > naivescore0 )
+                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                       else if( naivescore1 < naivescore0 )
+                                       {
+                                               fprintf( stderr, "%d-%d, ns: DOWN!\n", clus1, clus2 );
+                                       }
+                                       else
+                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+
+#if 0 // chuui
+                                       if( abs( wm - naivescore1 ) > 100 )
+                                       {
+                                               rewind( stdout );
+                                               for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+                                               for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+                                               exit( 1 );
+                                       }
+#endif
+                               }
+                               else if( alg == 'a' ) 
+                               {
+                                       Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+                               }
+                               else ErrorExit( "Sorry!" );
+                       }
+//                     fprintf( stderr, "## impmatch = %f\n", impmatch );
+
+#if 1
+                       if( parallelizationstrategy == BAATARI2 && *subgenerationpt != subgenerationatfirst )
+                       {
+//                             fprintf( stderr, "\nYarinaoshi2!! (Thread %d)\n", thread_no );
+                               goto yarinaoshi;
+                       }
+#endif
+                                               
+                       identity = !strcmp( localcopy[s1], mastercopy[s1] );
+                       identity *= !strcmp( localcopy[s2], mastercopy[s2] );
+
+
+/* Bug?  : idnetitcal but score change when scoreing mtx != JTT  */
+
+                       length = strlen( mseq1[0] );
+
+                       if( identity )
+                       {
+                               tscore = mscore;
+//                             if( !devide ) fprintf( trap_g, "tscore =  %f   identical.\n", tscore );
+//                             fprintf( stderr, " identical." );
+                               fprintf( stderr, "%03d-%04d-%d (thread %4d) identical     \r", iterate+1, *ndonept, k, thread_no );
+                       }
+                       else
+                       {
+                               if( score_check )
+                               {
+                                       if( constraint == 2 )
+                                       {
+#if 1
+                                               if( RNAscoremtx == 'r' )
+                                                       intergroup_score_gapnomi( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+                                               else
+                                                       intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+#else
+                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+#endif
+
+                                               tscore = impmatch + tmpdouble;
+
+//                                             fprintf( stderr, "tmpdouble=%f, impmatch = %f -> %f, tscore = %f\n", tmpdouble, oimpmatch, impmatch, tscore );
+                                       }
+                                       else
+                                       {
+                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+                                               tscore = tmpdouble;
+                                       }
+//                                     fprintf( stderr, "#######ii=%d, iterate=%d score = %f -> %f \n", ii, iterate , mscore, tscore );
+       #if 0
+                                       for( i=0; i<1; i++ )
+                                               fprintf( stderr, "%s\n", mseq1[i] );
+                                       fprintf( stderr, "+++++++\n" );
+                                       for( i=0; i<1; i++ )
+                                               fprintf( stderr, "%s\n", mseq2[i] );
+       #endif
+
+                               }
+                               else
+                               {
+                                       tscore = mscore + 1.0;
+//                                     tscore = 0.0;
+//                                     fprintf( stderr, "in line 705, tscore=%f\n", tscore );
+//                                     for( i=0; i<length; i++ )
+//                                             tscore = tscore + (double)mseq1[0][i];
+//                                     mscore = tscore - 1.0;
+                               }
+
+                               if( isnan( mscore ) )
+                               {
+                                       fprintf( stderr, "\n\nmscore became NaN\n" );
+                                       exit( 1 );
+                               }
+                               if( isnan( tscore ) )
+                               {
+                                       fprintf( stderr, "\n\ntscore became NaN\n" );
+                                       exit( 1 );
+                               }
+
+
+
+//                             fprintf( stderr, "@@@@@ mscore,tscore = %f,%f\n", mscore, tscore );
+
+#if 1
+                               if( parallelizationstrategy == BAATARI1 && *subgenerationpt != subgenerationatfirst )
+                               {
+//                                     fprintf( stderr, "\nYarinaoshi1!! (Thread %d)\n", thread_no );
+                                       goto yarinaoshi;
+                               }
+#endif
+                               gain = tscore - ( mscore - cut/100.0*mscore );
+                               if( gain > 0 )
+                               {
+                                       if( parallelizationstrategy == BESTFIRST )
+                                       {
+                                               if( gain > gainlist[thread_no] ) 
+                                               {
+                                                       gainlist[thread_no] = gain;
+                                                       for( i=0; i<locnjob; i++ ) strcpy( candidates[thread_no][i], localcopy[i] );
+                                                       tscorelist[thread_no] = tscore;
+//                                             if( iterate == 0 ) fprintf( stderr, "hist %d-%d-%d, gain=%f (Thread %d)\n", iterate, l, k, gain, thread_no );
+                                               }
+                                       }
+                                       else
+                                       {
+                                               pthread_mutex_lock( targ->mutex );
+                                               for( i=0; i<locnjob; i++ ) strcpy( mastercopy[i], localcopy[i] );
+                                               *subgenerationpt += 1;
+                                               gainlist[thread_no] = *basegainpt + gain;
+                                               *basegainpt += gain;
+
+                                               if( scoreout )
+                                               {
+                                                       unweightedspscore = plainscore( locnjob, localcopy );
+                                                       fprintf( stderr, "\nSCORE %d = %.0f, ", *ntrypt, unweightedspscore );
+                                                       fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( locnjob * strlen( mastercopy[0] ) ) );
+                                                       if( weight || constraint ) fprintf( stderr, " (differs from the objective score)" );
+                                                       fprintf( stderr, "\n" );
+                                               }
+
+                                               pthread_mutex_unlock( targ->mutex );
+                                               tscorelist[thread_no] = tscore;
+                                       }
+#if 0
+                                       fprintf( stderr, "tscore =  %f   mscore = %f  accepted.\n", tscore, mscore );
+                                       fprintf( stderr, "\nbetter! gain = %f (thread %d)\r", gain, thread_no );
+#else
+                                       fprintf( stderr, "%03d-%04d-%d (thread %4d) better     \r", iterate+1, *ndonept, k, thread_no );
+#endif
+
+                               }
+                               else 
+                               {
+#if 0
+                                       fprintf( stderr, "tscore =  %f   mscore = %f  rejected.\r", tscore, mscore );
+                                       fprintf( stderr, "worse! gain = %f", gain );
+#else
+                                       fprintf( stderr, "%03d-%04d-%d (thread %4d) worse      \r", iterate+1, *ndonept, k, thread_no );
+#endif
+                                       tscore = mscore;
+                               }
+                       }
+                       converged2 = 0;
+                       for( ii=iterate-2; ii>=0; ii-=1 ) 
+                       {
+//                             fprintf( stderr, "Checking tscorehistory %f ?= %f\n", tscore, tscorehistory_detail[ii][branchpos] );
+                               if( tscore == tscorehistory_detail[ii][branchpos] )
+                               {
+                                       converged2 = 1;
+                                       break;
+                               }
+                       }
+                       if( parallelizationstrategy != BESTFIRST && converged2 ) 
+                       {
+//                             fprintf( stderr, "\nFINISH!\n" );
+                               pthread_mutex_lock( targ->mutex );
+                               *finishpt = 1;
+                               pthread_mutex_unlock( targ->mutex );
+                       }
+
+                       tscorehistory_detail[iterate][branchpos] = tscore;
+                       fprintf( stderr, "\r" );
+
+                       pthread_mutex_lock( targ->mutex );
+                       (*ndonept)++;
+//                     fprintf( stderr, "*ndonept = %d, nbranch = %d (thread %d) iterate=%d\n", *ndonept, nbranch, thread_no, iterate );
+                       generationofinput[branchpos] = iterate;
+                       if( *ndonept == nbranch )
+                       {
+                               if( *collectingpt != -1 ) *collectingpt = 1; // chofuku
+//                             fprintf( stderr, "Thread %d sends a signal, *ndonept = %d\n", thread_no, *ndonept );
+                               pthread_cond_signal( targ->collection_start );
+                       }
+                       pthread_mutex_unlock( targ->mutex );
+               }            /* while( 1 ) */
+
+       }                  /* for( iterate ) */
+//     return( NULL );
+}
+#endif
+
+
+int TreeDependentIteration( int locnjob, char **name, int nlen[M], 
+                             char **aseq, char **bseq, int ***topol, double **len, 
+                             int alloclen, LocalHom **localhomtable, 
+                                                        RNApair ***singlerna,
+                                                        int nkozo, char *kozoarivec )
+{
+       int i, j, k, l, iterate, ii, iu, ju;
+       int lin, ldf, length; 
+       int clus1, clus2;
+       int s1, s2;
+       static double **imanoten;
+       static Node *stopol;
+       static double *effarrforlocalhom = NULL;
+       static double *effarr = NULL;
+       static double *effarr1 = NULL;
+       static double *effarr2 = NULL;
+       static double *effarr_kozo = NULL;
+       static double *effarr1_kozo = NULL;
+       static double *effarr2_kozo = NULL;
+       static double **mtx = NULL;
+       static int **node = NULL;
+       static int *branchnode = NULL;
+       static double **branchWeight = NULL;
+       static char **mseq1, **mseq2;
+       static float ***history;
+       FILE *trap;
+       double tscore, mscore;
+       int identity;
+       int converged;
+       int oscillating;
+       float naivescore0 = 0.0; // by D.Mathog, a guess
+       float naivescore1;
+#if 0
+       char pair[njob][njob];
+#else
+       static char **pair;
+#endif
+#if DEBUG + RECORD
+       double score_for_check0, score_for_check1;
+       static double **effmtx = NULL;
+       extern double score_calc0();
+#endif
+       static char *indication1, *indication2;
+       static LocalHom ***localhomshrink = NULL;
+       float impmatch = 0.0, oimpmatch = 0.0;
+       static int *gapmap1;
+       static int *gapmap2;
+       double tmpdouble;
+       int intdum;
+       static RNApair *rnapairboth;
+       RNApair ***grouprna1, ***grouprna2;
+       double unweightedspscore;
+
+       if( rnakozo && rnaprediction == 'm' )
+       {
+               grouprna1 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+               grouprna2 = (RNApair ***)calloc( njob, sizeof( RNApair ** ) );
+       }
+       else
+       {
+               grouprna1 = grouprna2 = NULL;
+       }
+
+       Writeoptions( trap_g );
+       fflush( trap_g );
+
+       if( effarr == NULL ) /* locnjob == njob ni kagiru */
+       {
+               indication1 = AllocateCharVec( njob*3+50 );
+               indication2 = AllocateCharVec( njob*3+50 );
+               effarr = AllocateDoubleVec( locnjob );
+               effarrforlocalhom = AllocateDoubleVec( locnjob );
+               effarr1 = AllocateDoubleVec( locnjob );
+               effarr2 = AllocateDoubleVec( locnjob );
+               mseq1 = AllocateCharMtx( locnjob, 0 );
+               mseq2 = AllocateCharMtx( locnjob, 0 );
+               mtx = AllocateDoubleMtx( locnjob, locnjob );
+               node = AllocateIntMtx( locnjob, locnjob );
+               branchnode = AllocateIntVec( locnjob );
+               branchWeight = AllocateDoubleMtx( locnjob, 2 );
+               history = AllocateFloatCub( niter, locnjob, 2 );
+               stopol = (Node *)calloc( locnjob * 2, sizeof( Node ) );
+               gapmap1 = AllocateIntVec( alloclen );
+               gapmap2 = AllocateIntVec( alloclen );
+               if( score_check == 2 ) imanoten = AllocateDoubleMtx( njob, njob );
+
+               effarr1_kozo = AllocateDoubleVec( locnjob ); // tsuneni allocate suru.
+               effarr2_kozo = AllocateDoubleVec( locnjob ); // tsuneni allocate suru.
+               effarr_kozo = AllocateDoubleVec( locnjob ); 
+               for( i=0; i<locnjob; i++ )
+                       effarr_kozo[i] = effarr1_kozo[i] = effarr2_kozo[i] = 0.0;
+
+#if 0
+#else
+               pair = AllocateCharMtx( locnjob, locnjob );
+               if( rnakozo ) rnapairboth = (RNApair *)calloc( alloclen, sizeof( RNApair ) );
+
+               if( constraint )
+               {
+                       localhomshrink = (LocalHom ***)calloc( njob, sizeof( LocalHom ** ) );
+                       for( i=0; i<njob; i++)
+                       {
+                               localhomshrink[i] = (LocalHom **)calloc( njob, sizeof( LocalHom * ) );
+                       }
+               }
+#endif
+       }
+#if DEBUG + RECORD
+       if( !effmtx ) effmtx = AllocateDoubleMtx( locnjob, locnjob );
+       for( i=0; i<locnjob; i++ ) for( j=0; j<locnjob; j++ ) effmtx[i][j] = 1.0;
+#endif
+
+       for( i=0; i<locnjob; i++ ) strcpy( bseq[i], aseq[i] );
+
+       writePre( locnjob, name, nlen, aseq, 0 );
+
+       if( utree )
+       {
+               if( constraint )
+               {
+                       counteff_simple( locnjob, topol, len, effarrforlocalhom );
+                       calcimportance( locnjob, effarrforlocalhom, aseq, localhomtable );
+               }
+
+               if( weight == 2 ) 
+               {
+                       countnode_int( locnjob, topol, node );
+                       if( nkozo )
+                       {
+                               fprintf( stderr, "Not supported, weight=%d nkozo=%d.\n", weight, nkozo );
+                       }
+               }
+               else if( weight == 4 )
+               {
+                       treeCnv( stopol, locnjob, topol, len, branchWeight );
+                       calcBranchWeight( branchWeight, locnjob, stopol, topol, len );
+               }
+       }
+
+#ifdef enablemultithread
+       if( nthread > 0 )
+       {
+               threadarg_t *targ;
+               pthread_t *handle;
+               pthread_mutex_t mutex;
+               pthread_cond_t collection_end;
+               pthread_cond_t collection_start;
+               int jobposint;
+               int generationofmastercopy;
+               int subgeneration;
+               float basegain;
+               int *generationofinput;
+               float *gainlist;
+               float *tscorelist;
+               int ndone;
+               int ntry;
+               int collecting;
+               int nbranch;
+               int maxiter;
+               char ***candidates;
+               int *branchtable;
+               float **tscorehistory_detail;
+               int finish;
+
+               nwa = nthread + 1;
+               nbranch = (njob-1) * 2 - 1;
+               maxiter = niter;
+
+               targ = calloc( nwa, sizeof( threadarg_t ) );
+               handle = calloc( nwa, sizeof( pthread_t ) );
+               pthread_mutex_init( &mutex, NULL );
+               pthread_cond_init( &collection_end, NULL );
+               pthread_cond_init( &collection_start, NULL );
+
+               gainlist = calloc( nwa, sizeof( float ) );
+               tscorelist = calloc( nwa, sizeof( float ) );
+               branchtable = calloc( nbranch, sizeof( int ) );
+               generationofinput = calloc( nbranch, sizeof( int ) );
+               if( parallelizationstrategy == BESTFIRST )
+                       candidates = AllocateCharCub( nwa, locnjob, alloclen );
+               for( i=0; i<nbranch; i++ ) branchtable[i] = i;
+               tscorehistory_detail = AllocateFloatMtx( maxiter, nbranch );
+
+               collecting = 1;
+
+               for( i=0; i<nwa; i++ )
+               {
+                       targ[i].thread_no = i;
+                       targ[i].njob = njob;
+                       targ[i].nbranch = nbranch;
+                       targ[i].maxiter = maxiter;
+                       targ[i].ndonept = &ndone;
+                       targ[i].ntrypt = &ntry;
+                       targ[i].collectingpt = &collecting;
+                       targ[i].jobposintpt = &jobposint;
+                       targ[i].gainlist = gainlist;
+                       targ[i].tscorelist = tscorelist;
+                       targ[i].nkozo = nkozo;
+                       targ[i].kozoarivec = kozoarivec;
+                       targ[i].mastercopy = bseq;
+                       targ[i].candidates = candidates;
+                       targ[i].subgenerationpt = &subgeneration;
+                       targ[i].basegainpt = &basegain;
+                       targ[i].generationofmastercopypt = &generationofmastercopy;
+                       targ[i].generationofinput = generationofinput;
+                       targ[i].branchtable = branchtable;
+                       targ[i].singlerna = singlerna;
+                       targ[i].localhomtable = localhomtable;
+                       targ[i].alloclen = alloclen;
+                       targ[i].stopol = stopol;
+                       targ[i].topol = topol;
+//                     targ[i].len = len;
+                       targ[i].mutex = &mutex;
+                       targ[i].collection_end = &collection_end;
+                       targ[i].collection_start = &collection_start;
+                       targ[i].tscorehistory_detail = tscorehistory_detail;
+                       targ[i].finishpt = &finish;
+       
+                       pthread_create( handle+i, NULL, athread, (void *)(targ+i) );
+               }
+
+               for( i=0; i<nwa; i++ )
+               {
+                       pthread_join( handle[i], NULL );
+               }
+
+               pthread_mutex_destroy( &mutex );
+               pthread_cond_destroy( &collection_end );
+               pthread_cond_destroy( &collection_start );
+
+               free( targ );
+               free( handle );
+               free( gainlist );
+               free( tscorelist );
+               free( branchtable );
+               free( generationofinput );
+               if( parallelizationstrategy == BESTFIRST )
+                       FreeCharCub( candidates );
+               FreeFloatMtx( tscorehistory_detail );
+       }
+       else
+#endif
+       {
+#if 0
+               int *branchtable;
+               int jobpos;
+               int myjob;
+
+               int nbranch;
+               nbranch = (njob-1) * 2 - 1;
+
+               branchtable = calloc( nbranch, sizeof( int ) );
+               for( i=0; i<nbranch; i++ ) branchtable[i] = i;
+
+               srand( randomseed );
+#endif
+
+               if( parallelizationstrategy == BESTFIRST )
+               {
+                       fprintf( stderr, "Not implemented.  Try --thread 1 --bestfirst\n" );
+                       exit( 1 );
+               }
+               converged = 0;
+               if( cooling ) cut *= 2.0;
+               for( iterate = 0; iterate<niter; iterate++ ) 
+               {
+                       if( cooling ) cut *= 0.5; /* ... */
+
+#if 0
+                       if( randomseed != 0 ) shuffle( branchtable, nbranch );
+#endif
+       
+                       fprintf( trap_g, "\n" );
+                       Writeoption2( trap_g, iterate, cut );
+                       fprintf( trap_g, "\n" );
+
+       
+                       if( utree == 0 )
+                       {
+                               if( nkozo )
+                               {
+                                       fprintf( stderr, "The combination of dynamic tree and kozo is not supported.\n" );
+                                       exit( 1 );
+                               }
+                               if( devide )
+                               {
+                                       static char *buff1 = NULL;
+                                       static char *buff2 = NULL;
+                                       if( !buff1 )
+                                       {
+                                               buff1 = AllocateCharVec( alloclen );
+                                               buff2 = AllocateCharVec( alloclen );
+                                       }       
+       
+                                       for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ )       
+                                       {
+                                               buff1[0] = buff2[0] = 0;
+                                               strcat( buff1, res_g[i] ); strcat( buff2, res_g[j] );
+                                               strcat( buff1,  bseq[i] ); strcat( buff2,  bseq[j] );
+                                               strcat( buff1, seq_g[i] ); strcat( buff2, seq_g[j] );
+       
+                                               mtx[i][j] = (double)substitution_hosei( buff1, buff2 );
+                                       }
+                               }
+                               else
+                               {
+                                       for( i=0; i<locnjob-1; i++ ) for( j=i+1; j<locnjob; j++ )       
+                                               mtx[i][j] = (double)substitution_hosei( bseq[i], bseq[j] );
+                               }
+       
+                               if     ( treemethod == 'n' )
+                                       nj( locnjob, mtx, topol, len );
+                               else if( treemethod == 's' )
+                                       spg( locnjob, mtx, topol, len );
+                               else if( treemethod == 'X' )
+                                       supg( locnjob, mtx, topol, len );
+                               else if( treemethod == 'p' )
+                                       upg2( locnjob, mtx, topol, len );
+                               /* veryfastsupg\e$B$O!":#$N$H$3$m;H$($^$;$s!#\e(B*/
+                               /* \e$B=gHV$NLdBj$,$"$k$N$G\e(B                  */
+       
+                               if( weight == 2 )
+                                       countnode_int( locnjob, topol, node );
+                               else if( weight == 4 )
+                               {
+                                       treeCnv( stopol, locnjob, topol, len, branchWeight );
+                                       calcBranchWeight( branchWeight, locnjob, stopol, topol, len );
+                               }
+                               trap = fopen( "hat2", "w" );
+                               if( !trap ) ErrorExit( "Cannot open hat2." );
+                               WriteHat2_pointer( trap, locnjob, name, mtx );
+                               fclose( trap );
+                               if( constraint )
+                               {
+                                       counteff_simple( locnjob, topol, len, effarrforlocalhom );
+                                       calcimportance( locnjob, effarrforlocalhom, aseq, localhomtable );
+                               }
+                       }
+       
+                       if( iterate % 2 == 0 ) 
+                       {
+                               lin = 0; ldf = +1;
+                       }
+                       else
+                       {
+                               lin = locnjob - 2; ldf = -1;
+                       }       
+       
+                       if( score_check == 2 )
+                       {
+                               effarr1[0] = 1.0;
+                               effarr2[0] = 1.0;
+                               length = strlen( bseq[0] );
+                               for( i=0; i<locnjob-1; i++ )
+                                       for( j=i+1; j<locnjob; j++ )
+                                               intergroup_score( bseq+i, bseq+j, effarr1, effarr2, 1, 1, length, imanoten[i]+j );
+                       }
+       
+#if 1
+                       for( l=lin; l < locnjob-1 && l >= 0 ; l+=ldf )
+                       {
+
+
+                               for( k=0; k<2; k++ ) 
+                               {
+                                       if( l == locnjob-2 ) k = 1;
+#else
+
+                       for( jobpos=0; jobpos<nbranch; jobpos++)
+                       {
+                               {
+                                       myjob = branchtable[jobpos];
+                                       l = myjob / 2;
+                                       if( l == locnjob-2 ) k = 1;
+                                       else k = myjob - l * 2;
+#endif
+       #if 1
+                                       fprintf( stderr, "STEP %03d-%03d-%d ", iterate+1, l+1, k );
+                                       fflush( stderr );
+       #else
+                                       fprintf( stderr, "STEP %03d-%03d-%d %s", iterate+1, l+1, k, use_fft?"\n":"\n" );
+       #endif
+                                       for( i=0; i<locnjob; i++ ) for( j=0; j<locnjob; j++ ) pair[i][j] = 0;
+       
+                                       OneClusterAndTheOther( locnjob, pair, &s1, &s2, topol, l, k );
+       #if 0
+                                       fprintf( stderr, "STEP%d-%d\n", l, k );
+                                       for( i=0; i<locnjob; i++ ) 
+                                       {
+                                               for( j=0; j<locnjob; j++ ) 
+                                               {
+                                                       fprintf( stderr, "%#3d", pair[i][j] );
+                                               }
+                                               fprintf( stderr, "\n" );
+                                       }
+       #endif
+                                       if( !weight )
+                                       {
+                                               for( i=0; i<locnjob; i++ ) effarr[i] = 1.0;
+                                               if( nkozo )
+                                               {
+                                                       for( i=0; i<locnjob; i++ ) 
+                                                       {
+                                                               if( kozoarivec[i] )
+                                                                       effarr_kozo[i] = 1.0;
+                                                               else
+                                                                       effarr_kozo[i] = 0.0;
+                                                       }
+                                               }
+                                       }
+                                       else if( weight == 2 ) 
+                                       {
+                                               nodeFromABranch( locnjob, branchnode, node, topol, len, l, k );
+                                               node_eff( locnjob, effarr, branchnode );
+                                       }
+                                       else if( weight == 4 )
+                                       {
+                                               weightFromABranch( locnjob, effarr, stopol, topol, l, k );
+       #if 0
+                                               if( nkozo )
+                                               {
+                                                       assignstrweight( locnjob, effarr_kozo, stopol, topol, l, k, kozoarivec, effarr );
+                                               }
+       
+       #else
+                                               if( nkozo ) // hitomadu single weight.
+                                                       for( i=0; i<locnjob; i++ ) 
+                                                       {
+                                                               if( kozoarivec[i] ) effarr_kozo[i] = effarr[i]; 
+                                                               else effarr_kozo[i] = 0.0;
+                                                       }
+       #endif
+       #if 0
+                                               fprintf( stderr, "\n" );
+                                               fprintf( stderr, "effarr_kozo = \n" );
+                                               for( i=0; i<locnjob; i++ ) fprintf( stderr, "%5.3f ", effarr_kozo[i] );
+                                               fprintf( stderr, "\n" );
+                                               fprintf( stderr, "effarr = \n" );
+                                               for( i=0; i<locnjob; i++ ) fprintf( stderr, "%5.3f ", effarr[i] );
+                                               fprintf( stderr, "\n\n" );
+       #endif
+                                       }
+       
+                                       for( i=0; i<locnjob; i++ ) strcpy( aseq[i], bseq[i] );
+                                       length = strlen( aseq[0] );
+       
+                                       if( nkozo )
+                                       {
+       #if 1
+                                               double tmptmptmp;
+                                               tmptmptmp = 0.0;
+                                               clus1 = conjuctionfortbfast_kozo( &tmptmptmp, pair, s1, aseq, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 );
+                                               for( i=0; i<clus1; i++ ) effarr1_kozo[i] *= 1.0; // 0.5 ga sairyo ?
+                                               tmptmptmp = 0.0;
+                                               clus2 = conjuctionfortbfast_kozo( &tmptmptmp, pair, s2, aseq, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 );
+                                               for( i=0; i<clus2; i++ ) effarr2_kozo[i] *= 1.0; // 0.5 ga sairyo ?
+       
+       #if 0
+                                               fprintf( stderr, "\ngroup1 = %s\n", indication1 );
+                                               for( i=0; i<clus1; i++ ) fprintf( stderr, "effarr1_kozo[%d], effarr1[]  = %f, %f\n", i, effarr1_kozo[i], effarr1[i] );
+                                               fprintf( stderr, "\ngroup2 = %s\n", indication2 );
+                                               for( i=0; i<clus2; i++ ) fprintf( stderr, "effarr2_kozo[%d], effarr2[]  = %f, %f\n", i, effarr2_kozo[i], effarr2[i] );
+       #endif
+       
+       
+       
+       
+       
+       #else
+                                               clus1 = conjuctionfortbfast_kozo_BUG( pair, s1, aseq, mseq1, effarr1, effarr, effarr1_kozo, effarr_kozo, indication1 );
+                                               clus2 = conjuctionfortbfast_kozo_BUG( pair, s2, aseq, mseq2, effarr2, effarr, effarr2_kozo, effarr_kozo, indication2 );
+       #endif
+                                       }
+                                       else
+                                       {
+                                               clus1 = conjuctionfortbfast( pair, s1, aseq, mseq1, effarr1, effarr, indication1 );
+                                               clus2 = conjuctionfortbfast( pair, s2, aseq, mseq2, effarr2, effarr, indication2 );
+                                       }
+       
+       
+       
+                               if( rnakozo && rnaprediction == 'm' )
+                               {       
+                                               makegrouprnait( grouprna1, singlerna, pair, s1 );
+                                               makegrouprnait( grouprna2, singlerna, pair, s2 );
+                               }       
+       
+                                       if( score_check == 2 )
+                                       {
+                                               if( constraint )
+                                               {
+       //                                              msshrinklocalhom( pair, s1, s2, localhomtable, localhomshrink );
+                                                       shrinklocalhom( pair, s1, s2, localhomtable, localhomshrink );
+                                                       oimpmatch = 0.0;
+                                                       if( use_fft )
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                                       for(  i=length-1; i>=0; i-- ) oimpmatch += part_imp_match_out_scQ( i, i );
+                                                               }
+                                                               else
+                                                               {
+                                                                       part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                                       for(  i=length-1; i>=0; i-- ) oimpmatch += part_imp_match_out_sc( i, i );
+                                                               }
+                                                       }
+                                                       else
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                                       for(  i=length-1; i>=0; i-- ) oimpmatch += imp_match_out_scQ( i, i );
+                                                               }
+                                                               else
+                                                               {
+                                                                       imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                                       fprintf( stderr, "not supported\n" );
+                                                                       exit( 1 );
+                                                               }
+                                                       }
+       //                                              fprintf( stderr, "### oimpmatch = %f\n", oimpmatch );
+                                               }
+                                               else
+                                               {
+                                                       oimpmatch = 0.0;
+                                               }
+                                               tmpdouble = 0.0;
+                                               iu=0; 
+                                               for( i=s1; i<locnjob; i++ ) 
+                                               {
+                                                       if( !pair[s1][i] ) continue;
+                                                       ju=0;
+                                                       for( j=s2; j<locnjob; j++ )
+                                                       {
+                                                               if( !pair[s2][j] ) continue;
+       //                                                      fprintf( stderr, "i = %d, j = %d, effarr1=%f, effarr2=%f\n", i, j, effarr1[iu], effarr2[ju] );
+                                                               tmpdouble += effarr1[iu] * effarr2[ju] * imanoten[MIN(i,j)][MAX(i,j)];
+                                                               ju++;
+                                                       }
+                                                       iu++;
+                                               }
+                                               mscore = oimpmatch + tmpdouble;
+                                       }
+                                       else if( score_check )
+                                       {
+       #if 1
+                                               if( RNAscoremtx == 'r' )
+                                                       intergroup_score_gapnomi( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble ); // gappick mae denaito dame
+                                               else
+                                                       intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble ); // gappick mae denaito dame
+       #else
+                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble ); // gappick mae denaito dame
+       #endif
+       
+                                               if( constraint )
+                                               {
+                                                       shrinklocalhom( pair, s1, s2, localhomtable, localhomshrink );
+               //                                      weightimportance4( clus1, clus2,  effarr1, effarr2, localhomshrink ); // >>>
+                                                       oimpmatch = 0.0;
+                                                       if( use_fft )
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                                       for(  i=length-1; i>=0; i-- )
+                                                                       {
+                                                                               oimpmatch += part_imp_match_out_scQ( i, i );
+       //                                                                      fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                                       }
+                                                               }
+                                                               else
+                                                               {
+                                                                       part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                                       for(  i=length-1; i>=0; i-- )
+                                                                       {
+                                                                               oimpmatch += part_imp_match_out_sc( i, i );
+               //                                                              fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                                       }
+                                                               }
+               //                                              fprintf( stderr, "otmpmatch = %f\n", oimpmatch );
+                                                       }
+                                                       else
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+       
+                                                                       for(  i=length-1; i>=0; i-- )
+                                                                       {
+                                                                               oimpmatch += imp_match_out_scQ( i, i );
+       //                                                                      fprintf( stderr, "#### i=%d, initial impmatch = %f\n", i, oimpmatch );
+                                                                       }
+                                                               }
+                                                               else
+                                                               {
+                                                                       imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+       
+                                                                       fprintf( stderr, "not supported\n" );
+                                                                       exit( 1 );
+       
+                                                                       for(  i=length-1; i>=0; i-- )
+                                                                       {
+                                                                               oimpmatch += imp_match_out_sc( i, i );
+               //                                                              fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                                       }
+                                                               }
+               //                                              fprintf( stderr, "otmpmatch = %f\n", oimpmatch );
+                                                       }
+               //                                      fprintf( stderr, "#### initial impmatch = %f\n", oimpmatch );
+                                               }
+                                               else
+                                               {
+                                                       oimpmatch = 0.0;
+                                               }
+       
+       
+       //                                      fprintf( stderr, "#### tmpdouble = %f\n", tmpdouble );
+                                               mscore = (double)oimpmatch + tmpdouble;
+                                       }
+                                       else
+                                       {
+       //                                      fprintf( stderr, "score_check = %d\n", score_check );
+       /* atode kousokuka */
+                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+                                               mscore = tmpdouble;
+       /* atode kousokuka */
+       
+                                               if( constraint )
+                                               {
+                                                       oimpmatch = 0.0;
+                                                       shrinklocalhom( pair, s1, s2, localhomtable, localhomshrink );
+                                                       if( use_fft )
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                               }
+                                                               else
+                                                               {
+                                                                       part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                                       if( rnakozo ) part_imp_rna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                               }
+                                                       }
+                                                       else
+                                                       {
+                                                               if( alg == 'Q' )
+                                                               {
+                                                                       imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                                       if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, grouprna1, grouprna2, gapmap1, gapmap2, NULL );
+                                                               }
+                                                               else
+                                                               {
+                                                                       imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                                       fprintf( stderr, "Not supported\n" );
+                                                                       exit( 1 );
+                                                               }
+                                                       }
+                                               }
+                                       }
+       
+       //                              oimpmatch = 0.0;
+                                       if( constraint )
+                                       {
+       #if 0 // iranai
+                                               if( alg == 'Q' )
+                                               {
+                                                       imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += imp_match_out_scQ( i, i );
+       //                                                      fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                       for(  i=length-1; i>=0; i-- )
+                                                       {
+                                                               oimpmatch += imp_match_out_sc( i, i );
+       //                                                      fprintf( stderr, "#### i=%d, initial impmatch = %f seq1 = %c, seq2 = %c\n", i, oimpmatch, mseq1[0][i], mseq2[0][i] );
+                                                       }
+                                               }
+       #endif
+                                       }
+       #if 0
+                                       if( alg == 'H' )
+                                               naivescore0 = naivepairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + oimpmatch;
+                                       else if( alg == 'Q' )
+                                               naivescore0 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + oimpmatch;
+                                       else if( alg == 'R' )
+                                               naivescore0 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + oimpmatch;
+       #endif
+       
+       //                              if( rnakozo ) foldalignedrna( clus1, clus2, mseq1, mseq2, effarr1, effarr2, rnapairboth );
+       
+       //                              if( !use_fft && !rnakozo )
+                                       if( !use_fft )
+                                       {
+                                               commongappick_record( clus1, mseq1, gapmap1 );
+                                               commongappick_record( clus2, mseq2, gapmap2 );
+                                       }
+       
+       #if 0
+                                       fprintf( stderr, "##### mscore = %f\n", mscore );
+       #endif
+               
+       #if DEBUG
+                                       if( !devide )
+                                       {
+                                       fprintf( trap_g, "\nSTEP%d-%d-%d\n", iterate+1, l+1, k );
+                               fprintf( trap_g, "group1 = %s\n", indication1 );
+                                       fprintf( trap_g, "group2 = %s\n", indication2 );
+                                               fflush( trap_g );
+                                       }
+               
+       #endif
+       #if 0
+                                       printf( "STEP %d-%d-%d\n", iterate, l, k );
+                                       for( i=0; i<clus2; i++ ) printf( "%f ", effarr2[i] );
+                                       printf( "\n" );
+       #endif
+                                       if( constraint == 2 )
+                                       {
+                                               if( use_fft )
+                                               {
+       //                                              if( alg == 'Q' )
+       //                                                      part_imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 );
+       //                                              else
+       //                                                      part_imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                       Falign_localhom( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, gapmap1, gapmap2, NULL, 0, NULL );
+       //                                              fprintf( stderr, "##### impmatch = %f\n", impmatch );
+                                               }
+                                               else
+                                               {
+                                                       if( alg == 'Q' )
+                                                       {
+                                                               float wm;
+       //                                                      imp_match_init_strictQ( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap  wo tsukuttakara iranai.
+       //                                                      if( rnakozo ) imp_rnaQ( clus1, clus2, mseq1, mseq2, effarr1, effarr2, gapmap1, gapmap2, rnapairboth );
+       
+                                                               wm = Q__align_gapmap( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL, gapmap1, gapmap2 );
+                                                               fprintf( stderr, "wm = %f\n", wm );
+       #if 0
+                                                               fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                                               naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+                                                               fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+       
+                                                               if( naivescore1 > naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                               else if( naivescore1 < naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                               else
+                                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 0 // chuui
+                                                               if( abs( wm - naivescore1 ) > 100 )
+                                                               {
+       //                                                              fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+       //                                                              rewind( stdout );
+       //                                                              for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                              for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                              exit( 1 );
+                                                               }
+       #endif
+       #endif
+                                                       }
+                                                       else if( alg == 'R' )
+                                                       {
+                                                               float wm;
+                                                               imp_match_init_strictR( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap ha mada
+                                                               wm = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL );
+       //                                                      fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                                               naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+       //                                                      fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+       
+                                                               if( naivescore1 > naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: %f->%f UP!\n", clus1, clus2, naivescore0, naivescore1 );
+                                                               else if( naivescore1 < naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                               else
+                                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 0 // chuui
+                                                               if( abs( wm - naivescore1 ) > 100 )
+                                                               {
+       //                                                              fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+                                                                       rewind( stdout );
+                                                                       for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+                                                                       for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+                                                                       exit( 1 );
+                                                               }
+       #endif
+                                                       }
+                                                       else if( alg == 'H' )
+                                                       {
+                                                               float wm;
+                                                               imp_match_init_strictH( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, localhomshrink, 1 ); // Ichijiteki, gapmap ha mada
+                                                               wm = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, NULL, NULL, NULL, NULL );
+                                                               fprintf( stderr, "##### impmatch = %f->%f\n", oimpmatch, impmatch );
+                                                               naivescore1 = naivepairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty ) + impmatch;
+                                                               fprintf( stderr, "##### naivscore1 = %f\n", naivescore1 );
+       
+                                                               if( naivescore1 > naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                               else if( naivescore1 < naivescore0 )
+                                                                       fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                               else
+                                                                       fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 0 // chuui
+                                                               if( abs( wm - naivescore1 ) > 100 )
+                                                               {
+       //                                                              fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+       //                                                              for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                              for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                              exit( 1 );
+                                                               }
+       #endif
+                                                       }
+                                                       else
+                                                       {
+       //                                                      imp_match_init_strict( NULL, clus1, clus2, length, length, mseq1, mseq2, effarr1, effarr2, effarr1_kozo, effarr2_kozo, localhomshrink, 1 );
+                                                               A__align_gapmap( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, localhomshrink, &impmatch, gapmap1, gapmap2 );
+       //                                                      fprintf( stderr, "##### impmatch = %f\n", impmatch );
+                                                       }
+                                               }
+                                       }
+                                       else if( use_fft )
+                                       {
+                                               float totalwm;
+                                               totalwm = Falign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, &intdum, NULL, 0, NULL );
+       
+       //                                      fprintf( stderr, "totalwm = %f\n", totalwm );
+       #if 0
+                                               if( alg == 'Q' )
+                                               {
+                                                       fprintf( stderr, "totalwm = %f\n", totalwm );
+                                                       naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+               
+                                                       if( naivescore1 > naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                       else if( naivescore1 < naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                       else
+                                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 1 // chuui
+                                                       if( totalwm != 0.0 && abs( totalwm - naivescore1 ) > 100 )
+                                                       {
+       //                                                      fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+       //                                                      for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                      for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                      exit( 1 );
+                                                       }
+       #endif
+                                               }
+       #endif
+                                               if( alg == 'R' )
+                                               {
+                                                       fprintf( stderr, "totalwm = %f\n", totalwm );
+                                                       naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+               
+                                                       if( naivescore1 > naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                       else if( naivescore1 < naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                       else
+                                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 1 // chuui
+                                                       if( totalwm != 0.0 && abs( totalwm - naivescore1 ) > 100 )
+                                                       {
+       //                                                      fprintf( stderr, "WARNING, totalwm=%f but naivescore=%f\n", totalwm, naivescore1 );
+       //                                                      for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                      for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                      exit( 1 );
+                                                       }
+                                               }
+       #endif
+                                       }
+                                       else
+                                       {
+                                               if( alg == 'M' )
+                                               {
+                                                       MSalignmm( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, NULL, NULL, NULL, NULL, 0, NULL, outgap, outgap );
+                                               }
+                                               else if( alg == 'A' )
+                                               {
+                                                       A__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL, NULL, 0, NULL, 1, 1 ); // outgap==1
+                                               }
+                                               else if( alg == 'Q' )
+                                               {
+                                                       float wm;
+                                                       wm = Q__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                                       fprintf( stderr, "wm = %f\n", wm );
+                                                       fprintf( stderr, "impmatch = %f\n", impmatch );
+                                                       naivescore1 = naiveQpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+       
+                                                       if( naivescore1 > naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                       else if( naivescore1 < naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: DOWN!\n", clus1, clus2 );
+                                                       else
+                                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 1 // chuui
+                                                       if( abs( wm - naivescore1 ) > 100 )
+                                                       {
+       //                                                      fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+       //                                                      rewind( stderr );
+       //                                                      rewind( stdout );
+       //                                                      for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                      for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                      exit( 1 );
+                                                       }
+       #endif
+                                               }
+                                               else if( alg == 'R' )
+                                               {
+                                                       float wm;
+                                                       wm = R__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                                       naivescore1 = naiveRpairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+       
+                                                       if( naivescore1 > naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                       else if( naivescore1 < naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: DOWN! %f->%f\n", clus1, clus2, naivescore0, naivescore1 );
+                                                       else
+                                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       #if 1 // chuui
+                                                       if( abs( wm - naivescore1 ) > 100 )
+                                                       {
+       //                                                      fprintf( stderr, "WARNING, wm=%f but naivescore=%f\n", wm, naivescore1 );
+       //                                                      rewind( stderr );
+       //                                                      rewind( stdout );
+       //                                                      for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+       //                                                      for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+       //                                                      exit( 1 );
+                                                       }
+       #endif
+                                               }
+                                               else if( alg == 'H' )
+                                               {
+                                                       float wm;
+                                                       wm = H__align( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen, NULL, &impmatch, NULL, NULL, NULL, NULL );
+                                                       naivescore1 = naivepairscore( clus1, clus2, mseq1, mseq2, effarr1, effarr2, penalty );
+       
+                                                       if( naivescore1 > naivescore0 )
+                                                               fprintf( stderr, "%d-%d, ns: UP!\n", clus1, clus2 );
+                                                       else if( naivescore1 < naivescore0 )
+                                                       {
+                                                               fprintf( stderr, "%d-%d, ns: DOWN!\n", clus1, clus2 );
+                                                       }
+                                                       else
+                                                               fprintf( stderr, "%d-%d, ns: IDENTICAL\n", clus1, clus2 );
+       
+       #if 0 // chuui
+                                                       if( abs( wm - naivescore1 ) > 100 )
+                                                       {
+                                                               rewind( stdout );
+                                                               for( i=0; i<clus1; i++ ) printf( ">\n%s\n", mseq1[i] );
+                                                               for( i=0; i<clus2; i++ ) printf( ">\n%s\n", mseq2[i] );
+                                                               exit( 1 );
+                                                       }
+       #endif
+                                               }
+                                               else if( alg == 'a' ) 
+                                               {
+                                                       Aalign( mseq1, mseq2, effarr1, effarr2, clus1, clus2, alloclen );
+                                               }
+                                               else ErrorExit( "Sorry!" );
+                                       }
+       //                              fprintf( stderr, "## impmatch = %f\n", impmatch );
+                                                               
+                                               if( checkC )
+                                               {
+                                                       extern double DSPscore();
+                                                       extern double SSPscore();
+                                                       static double cur;
+                                                       static double pre;
+               
+       /*
+                                                       pre = SSPscore( locnjob, bseq );
+                                                       cur = SSPscore( locnjob, aseq );
+       */
+                                                       pre = DSPscore( locnjob, bseq );
+                                                       cur = DSPscore( locnjob, aseq );
+               
+                                                       fprintf( stderr, "Previous Sscore = %f\n", pre );
+                                                       fprintf( stderr, "Currnet  Sscore = %f\n\n", cur );
+                                               }
+                                               
+       //                              fprintf( stderr, "## impmatch = %f\n", impmatch );
+                                       identity = !strcmp( aseq[s1], bseq[s1] );
+                                       identity *= !strcmp( aseq[s2], bseq[s2] );
+       
+       
+       /* Bug?  : idnetitcal but score change when scoreing mtx != JTT  */
+       
+                                       length = strlen( mseq1[0] );
+               
+                                       if( identity )
+                                       {
+                                               tscore = mscore;
+                                               if( !devide ) fprintf( trap_g, "tscore =  %f   identical.\n", tscore );
+                                               fprintf( stderr, " identical." );
+                                               converged++;
+                                       }
+                                       else
+                                       {
+                                               if( score_check )
+                                               {
+                                                       if( constraint == 2 )
+                                                       {
+       #if 1
+                                                               if( RNAscoremtx == 'r' )
+                                                                       intergroup_score_gapnomi( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+                                                               else
+                                                                       intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+       #else
+                                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+       #endif
+       
+                                                               tscore = impmatch + tmpdouble;
+       
+       //                                                      fprintf( stderr, "tmpdouble=%f, impmatch = %f -> %f, tscore = %f\n", tmpdouble, oimpmatch, impmatch, tscore );
+                                                       }
+                                                       else
+                                                       {
+                                                               intergroup_score( mseq1, mseq2, effarr1, effarr2, clus1, clus2, length, &tmpdouble );
+                                                               tscore = tmpdouble;
+                                                       }
+       //                                              fprintf( stderr, "#######ii=%d, iterate=%d score = %f -> %f \n", ii, iterate , mscore, tscore );
+               #if 0
+                                                       for( i=0; i<1; i++ )
+                                                               fprintf( stderr, "%s\n", mseq1[i] );
+                                                       fprintf( stderr, "+++++++\n" );
+                                                       for( i=0; i<1; i++ )
+                                                               fprintf( stderr, "%s\n", mseq2[i] );
+               #endif
+               
+                                               }
+                                               else
+                                               {
+                                                       tscore = mscore + 1.0;
+       //                                              tscore = 0.0;
+       //                                              fprintf( stderr, "in line 705, tscore=%f\n", tscore );
+       //                                              for( i=0; i<length; i++ )
+       //                                                      tscore = tscore + (double)mseq1[0][i];
+       //                                              mscore = tscore - 1.0;
+                                               }
+       
+                                               if( isnan( mscore ) )
+                                               {
+                                                       fprintf( stderr, "\n\nmscore became NaN\n" );
+                                                       exit( 1 );
+                                               }
+                                               if( isnan( tscore ) )
+                                               {
+                                                       fprintf( stderr, "\n\ntscore became NaN\n" );
+                                                       exit( 1 );
+                                               }
+       
+       
+       
+       //                                      fprintf( stderr, "@@@@@ mscore,tscore = %f,%f\n", mscore, tscore );
+       
+                                               if( tscore > mscore - cut/100.0*mscore ) 
+                                               {
+                                                       writePre( locnjob, name, nlen, aseq, 0 );
+                                                       for( i=0; i<locnjob; i++ ) strcpy( bseq[i], aseq[i] );
+                                                       if( score_check == 2 )
+                                                       {
+                                                               effarr1[0] = 1.0;
+                                                               effarr2[0] = 1.0;
+                                                               for( i=0; i<locnjob-1; i++ )
+                                                                       for( j=i+1; j<locnjob; j++ )
+                                                                               intergroup_score( bseq+i, bseq+j, effarr1, effarr2, 1, 1, length, imanoten[i]+j );
+                                                       }
+               
+       #if 0
+                                                       fprintf( stderr, "tscore =  %f   mscore = %f  accepted.\n", tscore, mscore );
+       #endif
+                                                       fprintf( stderr, " accepted." );
+                                                       converged = 0;
+               
+                                               }
+                                               else 
+                                               {
+       #if 0
+                                                       fprintf( stderr, "tscore =  %f   mscore = %f  rejected.\n", tscore, mscore );
+       #endif
+                                                       fprintf( stderr, " rejected." );
+                                                       tscore = mscore;
+                                                       converged++;
+                                               }
+                                       }
+                                       fprintf( stderr, "\r" );
+       
+       
+                                       history[iterate][l][k] = (float)tscore;
+       
+       //                              fprintf( stderr, "tscore = %f\n", tscore );
+               
+                                       if( converged >= locnjob * 2 )
+                                       {
+                                               fprintf( trap_g, "Converged.\n\n" );
+                                               fprintf( stderr, "\nConverged.\n\n" );
+                                               if( scoreout )
+                                               {
+                                                       unweightedspscore = plainscore( njob, bseq );
+                                                       fprintf( stderr, "\nSCORE %d = %.0f, ", iterate * ( (njob-1)*2-1 ), unweightedspscore );
+                                                       fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( njob * strlen( bseq[0] ) ) );
+                                                       if( weight || constraint ) fprintf( stderr, " (differs from the objective score)" );
+                                                       fprintf( stderr, "\n\n" );
+                                               }
+                                               return( 0 );
+                                       }
+                                       if( iterate >= 1 )
+                                       {
+               /*   oscillation check    */
+                                               oscillating = 0;
+                                               for( ii=iterate-2; ii>=0; ii-=2 ) 
+                                               {
+                                                       if( (float)tscore == history[ii][l][k] )
+                                                       {
+                                                               oscillating = 1;
+                                                               break;
+                                                       }
+                                               }
+                                               if( ( oscillating && !cooling ) || ( oscillating && cut < 0.001 && cooling ) )
+                                               {
+                                                       fprintf( trap_g, "Oscillating.\n" );
+                                                       fprintf( stderr, "\nOscillating.\n\n" );
+                                                       if( scoreout )
+                                                       {
+                                                               unweightedspscore = plainscore( njob, bseq );
+                                                               fprintf( stderr, "\nSCORE %d = %.0f, ", iterate * ( (njob-1)*2-1 ), unweightedspscore );
+                                                               fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( njob * strlen( bseq[0] ) ) );
+                                                               if( weight || constraint ) fprintf( stderr, " (differs from the objective score)" );
+                                                               fprintf( stderr, "\n\n" );
+                                                       }
+       #if 1 /* hujuubun */
+                                                       return( -1 );
+       #endif
+                                               }
+                                       }      /* if( iterate ) */
+                               }          /* for( k ) */
+                       }              /* for( l ) */
+                       if( scoreout )
+                       {
+                               unweightedspscore = plainscore( njob, bseq );
+                               fprintf( stderr, "\nSCORE %d = %.0f, ", iterate * ( (njob-1)*2-1 ), unweightedspscore );
+                               fprintf( stderr, "SCORE / residue = %f", unweightedspscore / ( njob * strlen( bseq[0] ) ) );
+                               if( weight || constraint ) fprintf( stderr, " (differs from the objective score)" );
+                               fprintf( stderr, "\n\n" );
+                       }
+               }                  /* for( iterate ) */
+       }
+       return( 2 );
+}                         /* int Tree... */
diff --git a/binaries/src/mafft/core/test.c b/binaries/src/mafft/core/test.c
new file mode 100644 (file)
index 0000000..5b9ae6d
--- /dev/null
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <unistd.h>
+main()
+{
+       fprintf( stdout, "nprocess = %d\n", sysconf( _SC_NPROCESSORS_ONLN ) );
+       fprintf( stdout, "nprocess = %d\n", sysconf( _SC_NPROCESSORS_CONF ) );
+}
diff --git a/binaries/src/mafft/core/treeOperation.c b/binaries/src/mafft/core/treeOperation.c
new file mode 100644 (file)
index 0000000..2738fc1
--- /dev/null
@@ -0,0 +1,658 @@
+#include "mltaln.h"
+
+#define DEBUG 0
+
+#define EF_THREEWAY 1.0
+#define MAXBW 1.0
+#define MINBW 0.01
+
+#define MINLEN 0.001
+
+#if DEBUG
+Node *stopol_g;
+#endif
+
+
+void checkMinusLength( int nseq, double **len )
+{
+       int i, j;
+       for( i=0; i<nseq-1; i++ ) for( j=0; j<2; j++ ) 
+               if( len[i][j] < MINLEN ) len[i][j] = MINLEN;
+}
+
+void negativeMember2( int *mem, int *query, int locnseq )
+{
+       int *ptr;
+       char *tmp;
+       int i;
+       int n;
+
+       tmp = AllocateCharVec( locnseq );
+
+       for( i=0; i<locnseq; i++ ) tmp[i] = 0;
+       while( (n=*query++) != -1 ) tmp[n] = 1;
+
+       ptr = mem;
+       for( i=0; i<locnseq; i++ ) 
+       {
+               if( !tmp[i] ) 
+               {
+                       *ptr++ = i;
+               }
+       }
+       *ptr = -1;
+       free( tmp );
+}
+
+int *negativeMember( int *query, int locnseq )
+{
+       int *bk, *value = NULL;
+       char *tmp;
+       int i;
+       int n;
+
+       tmp = AllocateCharVec( locnseq );
+       bk = value = AllocateIntVec( locnseq );
+       if( !value ) ErrorExit( "Cannot allocate value" );
+
+       for( i=0; i<locnseq; i++ ) tmp[i] = 0;
+       while( (n=*query++) != -1 ) tmp[n] = 1;
+
+       for( i=0; i<locnseq; i++ ) 
+       {
+               if( !tmp[i] )
+               {
+                       fprintf( stderr, "%3d ", i );
+                       *value++ = i;
+               }
+       }
+       fprintf( stderr, "\n" );
+       *value = -1;
+       free( tmp );
+       return( bk );
+}
+
+int IntExistsInVec( int query, int *vector )
+{
+       while( *vector != -1 )
+               if( query == *vector++ ) return( 1 );
+       return( 0 );
+}
+
+NodeInCub searchParent( int top, int ***topol, int Start, int End )
+{
+       int i, j;
+       NodeInCub value;
+       for( i=Start; i<End; i++ ) 
+       {
+               for( j=0; j<2; j++ ) 
+               {
+                       if( IntExistsInVec( top, topol[i][j] ) )
+                       {
+                               value.step = i; 
+                               value.LorR = j; 
+                               return( value );
+                       }
+               }
+       }
+       fprintf( stderr, "ERROR!!!\n" );
+       ErrorExit( "Error in searchParent" );
+       value.step=0; // by D.Mathog, katoh
+       value.LorR=0; // by D.Mathog, katoh
+       return( value );
+}
+
+void stopolInit( int n, Node *stopol )
+{
+       int i, j;
+       for( i=0; i<n; i++ )
+       {
+               for( j=0; j<3; j++ ) 
+               {       
+                       stopol[i].length[j] = 0.0;
+                       stopol[i].children[j] = NULL;
+                       stopol[i].tmpChildren[j] = -1;
+                       stopol[i].top[j] = -1;
+                       stopol[i].members[j] = NULL;
+                       stopol[i].weightptr[j] = NULL;
+               }
+       }
+#if 0
+       while( --numintvec >= 0 )
+       {
+               free( tmpintvec[numintvec] );
+       }
+       free( tmpintvec );
+       numintvec = 0;
+#endif
+}
+
+void treeCnv( Node *stopol, int locnseq, int ***topol, double **len, double **bw )
+{
+       int i;
+       NodeInCub parent;
+       int *count;
+       int ccount;
+       int rep;
+       int tmpint;
+       static int **tmpintvec = NULL;
+       static int numintvec = 0;
+
+       count = AllocateIntVec(  2 * locnseq ); /* oome */
+       if( !count ) ErrorExit( "Cannot allocate count.\n" );
+
+       checkMinusLength( locnseq, len ); /* uwagaki */
+
+       stopolInit( locnseq * 2, stopol );
+       for( i=0; i<locnseq * 2; i++ ) count[i] = 0;
+
+       for( i=locnseq; i<locnseq*2; i++ ) 
+       {
+               rep = i - locnseq;
+               parent = searchParent( rep, topol, 0, locnseq-1 ); 
+#if DEBUG
+               fprintf( stderr, "Parent of node No.%d ( Seq No.%d )  = %d - %d\n", i, i-locnseq, parent.step, parent.LorR );
+#endif
+
+               ccount = count[parent.step];
+               stopol[parent.step].length[ccount] = len[parent.step][parent.LorR];
+               stopol[parent.step].weightptr[ccount] = &(bw[parent.step][parent.LorR]);
+               stopol[parent.step].children[ccount] = &stopol[i];
+               stopol[parent.step].tmpChildren[ccount] = i;
+               stopol[parent.step].members[ccount] = topol[parent.step][parent.LorR];
+               count[parent.step]++;
+
+               ccount = count[i];
+               stopol[i].length[ccount] = len[parent.step][parent.LorR];
+               stopol[i].weightptr[ccount] = &(bw[parent.step][parent.LorR]);
+               stopol[i].children[ccount] = &stopol[parent.step];
+               stopol[i].tmpChildren[ccount] = parent.step;
+               stopol[i].members[ccount] = topol[parent.step][parent.LorR];
+               count[i]++;
+       }
+       for( i=0; i<locnseq-2; i++ ) 
+       {
+               rep = MIN( topol[i][0][0], topol[i][1][0] );
+               parent = searchParent( rep, topol, i+1, locnseq-1 ); 
+               ccount = count[parent.step];
+               stopol[parent.step].length[ccount] = len[parent.step][parent.LorR];
+               stopol[parent.step].weightptr[ccount] = &(bw[parent.step][parent.LorR]);
+               stopol[parent.step].children[ccount] = &stopol[i];
+               stopol[parent.step].tmpChildren[ccount] = i;
+               stopol[parent.step].members[ccount] = topol[parent.step][parent.LorR];
+               count[parent.step]++;
+
+               ccount = count[i];
+               stopol[i].length[ccount] = len[parent.step][parent.LorR];
+               stopol[i].weightptr[ccount] = &(bw[parent.step][parent.LorR]);
+               stopol[i].children[ccount] = &stopol[parent.step];
+               stopol[i].tmpChildren[ccount] = parent.step;
+#if 0
+               stopol[i].members[ccount] = negativeMember( topol[parent.step][parent.LorR], locnseq );
+#else
+//             fprintf( stderr, "allocating numintvec = %d\n",  numintvec );
+               tmpintvec = (int **)realloc( (void *)tmpintvec, (numintvec+1) * sizeof( int * ) );
+               tmpintvec[numintvec] = (int *)calloc( locnseq, sizeof( int ) );
+               negativeMember2( tmpintvec[numintvec], topol[parent.step][parent.LorR], locnseq );
+               stopol[i].members[ccount] = tmpintvec[numintvec];
+               numintvec++;
+#endif
+               count[i]++;
+#if DEBUG
+               fprintf( stderr, "Parent of node No.%d = %d - %d\n", i, parent.step, parent.LorR );
+#endif
+       }
+/*
+                       Unrooted tree.
+                       locnseq-2 no children no nakade, 
+                       locnseq-3 wo sashiteinai mono wo sagashite,
+                       locnseq-3 no children ni kuwae,
+                       locnseq-2 wo sashiteita node no chilren wo
+                       locnseq-3 ni kaeru.
+*/
+#if DEBUG
+       fprintf( stderr, "BEFORE MODIFY\n" );
+       for( i=0; i<locnseq*2; i++ )  
+       {
+               for( j=0; j<3; j++ ) 
+               {
+                       fprintf( stderr, "stopol[%d].tmpChildren[%d] = %d, children[%d] = %d \n", i, j, stopol[i].tmpChildren[j], j, stopol[i].children[j] - stopol );
+               }
+       }
+#endif
+
+       if     ( stopol[locnseq-2].children[0] == &stopol[locnseq-3] ) i = 1;
+       else if( stopol[locnseq-2].children[1] == &stopol[locnseq-3] ) i = 0;
+       else ErrorExit( "?\n" );
+
+       stopol[locnseq-3].length[2] = len[locnseq-2][0] + len[locnseq-2][1];
+       stopol[locnseq-3].weightptr[2] = &bw[locnseq-2][0];
+       stopol[locnseq-3].children[2] = stopol[locnseq-2].children[i];
+       stopol[locnseq-3].tmpChildren[2] = stopol[locnseq-2].tmpChildren[i];
+
+       tmpint = (int)( stopol[locnseq-2].children[i] - stopol );
+
+       stopol[tmpint].children[2] = &stopol[locnseq-3];
+       stopol[tmpint].length[2] = len[locnseq-2][0] + len[locnseq-2][1];
+       stopol[tmpint].weightptr[2] = &bw[locnseq-2][0];
+       stopol[tmpint].tmpChildren[2] = locnseq-3;
+
+
+#if DEBUG
+       for( i=0; i<locnseq*2; i++ )  
+       {
+               for( j=0; j<3; j++ ) 
+               {
+                       fprintf( stderr, "stopol[%d].tmpChildren[%d] = %d, children[%d] = %d \n", i, j, stopol[i].tmpChildren[j], j, stopol[i].children[j] - stopol );
+               }
+       }
+
+       for( i=0; i<locnseq*2; i++ )  
+       {
+               fprintf( stderr, "-- stopol[%d]\n", i );
+               for( j=0; j<3; j++ ) 
+               {
+                       if( !stopol[i].members[j] ) 
+                       {
+                               fprintf( stderr, "LEAF\n" );
+                               break;
+                       }
+                       fprintf( stderr, "      group %d are \n", j );
+                       for( k=0; (n=stopol[i].members[j][k]) != -1; k++ ) 
+                       {       
+                               fprintf( stderr, "%#5d", n );
+                       }
+                       fprintf( stderr, "\n" );
+               }
+               fprintf( stderr, "\n" );
+       }
+#endif
+
+#if DEBUG
+       stopol_g = stopol;
+#endif
+       free( count );
+}
+
+int isLeaf( Node node )
+{
+       if( node.children[1] ) return( 0 );
+       else                   return( 1 );
+}
+
+double syntheticLength( Node *ob, Node *oppositeNode )
+{
+       int i, count;
+       int dir_ch[3];
+       int dir_pa = -10; // by katoh
+       double value, tmpvalue0, tmpvalue1;
+       int nanflag = 0;
+
+#if DEBUG
+       fprintf( stderr, "In syntheticLength\n" );
+       fprintf( stderr, "ob - stopol_g = %d\n", ob - stopol_g );
+       fprintf( stderr, "op - stopol_g = %d\n", oppositeNode - stopol_g );
+#endif
+
+       if( isLeaf( *ob ) ) 
+       {
+#if DEBUG
+               fprintf( stderr, "LEAF\n\n" );
+#endif
+               return( ob->length[0] );
+       }
+
+       for( i=0, count=0; i<3; i++ ) 
+       {
+#if DEBUG
+               fprintf( stderr, "ob->tmpChildren[%d] = %d\n", i, ob->tmpChildren[i] );
+#endif
+               if( oppositeNode != ob->children[i] ) dir_ch[count++] = i;
+               else dir_pa = i;
+       }
+#if DEBUG
+               fprintf( stderr, "\n" );
+#endif
+       if( count != 2 ) 
+       {
+#if DEBUG
+               fprintf( stderr, "Node No.%d has no child like No.%d \n", ob-stopol_g, oppositeNode-stopol_g );
+#endif
+               ErrorExit( "Invalid call\n" );
+       }
+
+       tmpvalue0 = syntheticLength( ob->children[dir_ch[0]], ob ); 
+       tmpvalue1 = syntheticLength( ob->children[dir_ch[1]], ob ); 
+
+#if DEBUG
+       fprintf( stderr, "tmpvalue0 = %f\n", tmpvalue0 );
+       fprintf( stderr, "tmpvalue1 = %f\n", tmpvalue1 );
+#endif 
+       if( tmpvalue0 ) tmpvalue0 = 1.0 / tmpvalue0;
+       else nanflag = 1;
+       if( tmpvalue1 ) tmpvalue1 = 1.0 / tmpvalue1;
+       else nanflag = 1;
+
+       if( nanflag ) value = 0.0;
+       else
+       {
+               value = tmpvalue0 + tmpvalue1;
+               value = 1.0 / value;
+       }
+       value += ob->length[dir_pa];
+#if DEBUG
+       fprintf( stderr, "value = %f\n", value  );
+#endif
+
+       return( value );
+}
+
+double calcW( Node *ob, Node *op )
+{
+       int i, count;
+       int dir_ch[3];
+       int dir_pa = -10; // by katoh
+       double a, b, c, f, s;
+       double value;
+
+       if( isLeaf( *ob ) ) 
+               return( 1.0 );
+
+       for( i=0, count=0; i<3; i++ ) 
+       {
+               if( op != ob->children[i] ) dir_ch[count++] = i;
+               else dir_pa = i;
+       }
+       if( count != 2 ) ErrorExit( "Invalid call of calcW\n" );
+
+#if DEBUG
+       fprintf( stderr, "In calcW\n" );
+       fprintf( stderr, "ob = %d\n", ob - stopol_g );
+       fprintf( stderr, "op = %d\n", op - stopol_g );
+       fprintf( stderr, "ob->children[c1] = %d\n", ob->children[dir_ch[0]] - stopol_g );
+       fprintf( stderr, "ob->children[c2] = %d\n", ob->children[dir_ch[1]] - stopol_g );
+       fprintf( stderr, "ob->children[pa] = %d\n", ob->children[dir_pa] - stopol_g );
+       fprintf( stderr, "\n" );
+#endif
+
+       a = syntheticLength( ob->children[dir_ch[0]], ob );
+       b = syntheticLength( ob->children[dir_ch[1]], ob );
+       c = syntheticLength( ob->children[dir_pa], ob );
+
+#if DEBUG
+       fprintf( stderr, "a = %f\n", a );
+       fprintf( stderr, "b = %f\n", b );
+       fprintf( stderr, "c = %f\n", c );
+#endif
+
+       if( !c ) return( MAXBW );
+       if ( !a || !b ) return( MINBW );  /* ? */
+
+       f = EF_THREEWAY;
+       s = ( b*c + c*a + a*b );
+
+       value = a*b*(c+a)*(c+b) / ( c*(a+b) * f * s );
+
+       value = sqrt( value );
+
+       return( value );
+}
+
+void calcBranchWeight( double **bw, int locnseq, Node *stopol, int ***topol, double **len )
+{
+       NodeInCub parent;
+       int i;
+       int rep;
+       Node *topNode, *btmNode;
+       double topW, btmW;
+
+       for( i=locnseq; i<locnseq*2; i++ )
+       {
+               rep = i - locnseq;
+               parent = searchParent( rep, topol, 0, locnseq-1 );
+               if( parent.step == locnseq - 2 ) continue;
+
+               topNode = stopol+parent.step; btmNode = stopol+i;
+#if DEBUG
+               fprintf( stderr, "In calcBranchWeight, topNode=%d, btmNode=%d\n", topNode-stopol_g, btmNode-stopol_g );
+#endif
+               topW = calcW( topNode, btmNode );
+               btmW = calcW( btmNode, topNode );
+               bw[parent.step][parent.LorR] = topW * btmW;
+       }
+       for( i=0; i<locnseq-3; i++ ) 
+       {
+               rep = MIN( topol[i][0][0], topol[i][1][0] );
+               parent = searchParent( rep, topol, i+1, locnseq-1 ); 
+               if( parent.step == locnseq - 2 ) continue;
+               topNode = stopol+parent.step;
+               btmNode = stopol+i;
+#if DEBUG
+               fprintf( stderr, "In calcBranchWeight, topNode=%d, btmNode=%d\n", topNode-stopol_g, btmNode-stopol_g );
+#endif
+               topW = calcW( topNode, btmNode );
+               btmW = calcW( btmNode, topNode );
+               bw[parent.step][parent.LorR] = topW * btmW;
+       }
+
+       topNode = stopol[locnseq-3].children[2];
+       btmNode = stopol + i;
+       topW = calcW( topNode, btmNode );
+       btmW = calcW( btmNode, topNode );
+       bw[locnseq-2][0] = topW * btmW;
+       bw[locnseq-2][1] = 1.0;
+}
+
+void branchWeightToPairWeight( int locnseq, int ***topol, double **pw, double **bw )
+{
+       int i, j, k, n0, n1;
+#if 0
+       double wFromLeaf[locnseq];
+#else
+       static double *wFromLeaf = NULL;
+       if( wFromLeaf == NULL )
+               wFromLeaf = AllocateDoubleVec( locnseq );
+#endif
+
+#if DEBUG
+       for( i=0; i<locnseq-1; i++ ) for( j=0; j<2; j++ ) 
+               fprintf( stderr, "pw[%d][%d] = %f\n", i, j, bw[i][j] );
+#endif
+
+       for( i=0; i<locnseq; i++ ) wFromLeaf[i] = 1.0;
+       for( i=0; i<locnseq; i++ ) for( j=0; j<locnseq; j++ ) 
+               pw[i][j] = 0.0;
+       for( i=0; i<locnseq-1; i++ ) 
+       {
+               for( j=0; (n0=topol[i][0][j])!=-1; j++ ) 
+                       for( k=0; (n1=topol[i][1][k])!=-1; k++ ) 
+                               pw[MIN( n0, n1 )][MAX( n0, n1 )] 
+                               = wFromLeaf[n0] * wFromLeaf[n1] * bw[i][0] * bw[i][1];
+               for( j=0; (n0=topol[i][0][j])!=-1; j++ ) 
+                       wFromLeaf[n0] *= bw[i][0];
+               for( j=0; (n1=topol[i][1][j])!=-1; j++ ) 
+                       wFromLeaf[n1] *= bw[i][1];
+       }
+}
+
+void weightFromABranch_rec( double *result, Node *ob, Node *op )
+{
+       int i, n, count;
+       int dir_ch[3], dir_pa;
+
+#if DEBUG
+       fprintf( stderr, "In weightFromABranch_rec, ob = %d\n", ob - stopol_g );
+#endif
+       if( isLeaf( *ob ) ) return;
+       for( i=0, count=0; i<3; i++ ) 
+       {
+               if( ob->children[i] != op ) dir_ch[count++] = i;
+               else dir_pa = i;
+       }
+       if( count != 2 ) 
+       {
+#if DEBUG
+               fprintf( stderr, "Node No.%d has no child like No.%d \n", ob-stopol_g, op-stopol_g );
+#endif
+               ErrorExit( "Incorrect call of weightFromABranch_rec" );
+       }
+       for( i=0; (n=ob->members[dir_ch[0]][i])!=-1; i++ ) 
+               result[n] *= *ob->weightptr[dir_ch[0]];
+       weightFromABranch_rec( result, ob->children[dir_ch[0]], ob );
+
+       for( i=0; (n=ob->members[dir_ch[1]][i])!=-1; i++ ) 
+               result[n] *= *ob->weightptr[dir_ch[1]];
+       weightFromABranch_rec( result, ob->children[dir_ch[1]], ob );
+}
+
+void weightFromABranch( int nseq, double *result, Node *stopol, int ***topol, int step, int LorR )
+{
+       Node *topNode, *btmNode;
+       int i;
+
+       if( step == nseq - 2 )
+       {
+               topNode = stopol[nseq-2].children[0];
+               btmNode = stopol + nseq-3;
+#if DEBUG
+               fprintf( stderr, "Now step == nseq-3, topNode = %d, btmNode = %d\n", topNode - stopol_g, btmNode-stopol_g );
+#endif
+       }
+               
+       else
+       {
+               for( i=0; i<3; i++ ) 
+               {
+                       if( stopol[step].members[i][0] == topol[step][LorR][0] )
+                       break;
+               }
+               if( i== 3 ) ErrorExit( "Incorrect call of weightFromABranch." );
+               btmNode = stopol[step].children[i];
+               topNode = stopol+step;
+       }
+
+       for( i=0; i<nseq; i++ ) result[i] = 1.0;
+       weightFromABranch_rec( result, btmNode, topNode ); 
+       weightFromABranch_rec( result, topNode, btmNode ); 
+#if 0
+       for( i=0; i<nseq; i++ )
+               fprintf( stdout, "w[%d] = %f\n", i, result[i] );
+#endif
+//     fprintf( stderr, "new weight!\n" );
+//     for( i=0; i<nseq; i++ )
+//             result[i] *= result[i];
+
+
+}
+void assignstrweight_rec( double *strweight, Node *ob, Node *op, char *kozoari, double *seqweight )
+{
+       int i, n, count, lastkozo;
+       int dir_ch[3], dir_pa;
+       double sumweight;
+
+#if DEBUG
+       fprintf( stderr, "In weightFromABranch_rec, ob = %d\n", ob - stopol_g );
+#endif
+       if( isLeaf( *ob ) )
+       {
+//             fprintf( stderr, "Leaf!\n" );
+               return;
+       }
+       for( i=0, count=0; i<3; i++ ) 
+       {
+               if( ob->children[i] != op ) dir_ch[count++] = i;
+               else dir_pa = i;
+       }
+       if( count != 2 ) 
+       {
+#if DEBUG
+               fprintf( stderr, "Node No.%d has no child like No.%d \n", ob-stopol_g, op-stopol_g );
+#endif
+               ErrorExit( "Incorrect call of weightFromABranch_rec" );
+       }
+
+
+//     fprintf( stderr, "\n" );
+       sumweight = 0.0;
+       count = 0;
+       lastkozo = -1;
+       for( i=0; (n=ob->members[dir_ch[0]][i])!=-1; i++ ) 
+       {
+//             fprintf( stderr, "member1! n=%d\n", n );
+               sumweight += seqweight[n];
+               if( kozoari[n] ) 
+               {
+                       count++;
+                       lastkozo = n;
+               }
+       }
+       for( i=0; (n=ob->members[dir_ch[1]][i])!=-1; i++ ) 
+       {
+//             fprintf( stderr, "member2! n=%d\n", n );
+               sumweight += seqweight[n];
+               if( kozoari[n] ) 
+               {
+                       count++;
+                       lastkozo = n;
+               }
+       }
+
+//     fprintf( stderr, "count = %d\n", count );
+
+       if( count == 1 )
+               strweight[lastkozo] = sumweight;
+       else if( count > 1 )
+       {
+               assignstrweight_rec( strweight, ob->children[dir_ch[0]], ob, kozoari, seqweight );
+               assignstrweight_rec( strweight, ob->children[dir_ch[1]], ob, kozoari, seqweight );
+       }
+}
+
+void assignstrweight( int nseq, double *strweight, Node *stopol, int ***topol, int step, int LorR, char *kozoari, double *seqweight )
+{
+       Node *topNode, *btmNode;
+       int i;
+
+       if( step == nseq - 2 )
+       {
+               topNode = stopol[nseq-2].children[0];
+               btmNode = stopol + nseq-3;
+#if DEBUG
+               fprintf( stderr, "Now step == nseq-3, topNode = %d, btmNode = %d\n", topNode - stopol_g, btmNode-stopol_g );
+#endif
+       }
+               
+       else
+       {
+               for( i=0; i<3; i++ ) 
+               {
+                       if( stopol[step].members[i][0] == topol[step][LorR][0] )
+                       break;
+               }
+               if( i== 3 ) ErrorExit( "Incorrect call of weightFromABranch." );
+               btmNode = stopol[step].children[i];
+               topNode = stopol+step;
+       }
+
+       for( i=0; i<nseq; i++ ) strweight[i] = 0.0;
+       for( i=0; i<nseq; i++ ) if( kozoari[i] ) strweight[i] = seqweight[i];
+//     fprintf( stderr, "calling _rec (1)\n" );
+       assignstrweight_rec( strweight, btmNode, topNode, kozoari, seqweight ); 
+//     fprintf( stderr, "calling _rec (2)\n" );
+       assignstrweight_rec( strweight, topNode, btmNode, kozoari, seqweight ); 
+
+#if 1 // nazeka kokowo tobasuto seido ga sagaru ?????
+       fprintf( stderr, "STEP %d\n", step );
+       for( i=0; topol[step][0][i]>-1; i++ )
+               fprintf( stderr, "%3d ", topol[step][0][i] );
+       fprintf( stderr, "\n" );
+       for( i=0; topol[step][1][i]>-1; i++ )
+               fprintf( stderr, "%3d ", topol[step][1][i] );
+       fprintf( stderr, "\n" );
+       for( i=0; i<nseq; i++ )
+               fprintf( stderr, "seqweight[%d] = %f\n", i, seqweight[i] );
+       for( i=0; i<nseq; i++ )
+               fprintf( stderr, "strweight[%d] = %f\n", i, strweight[i] );
+       fprintf( stderr, "\n" );
+#endif
+}
diff --git a/binaries/src/mafft/core/univscript.tmpl b/binaries/src/mafft/core/univscript.tmpl
new file mode 100644 (file)
index 0000000..221c457
--- /dev/null
@@ -0,0 +1,35 @@
+progs="_PROGS"
+for prog in $progs; do
+       printf  $prog" "
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch ppc64 -m64 -O3 -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.ppc64
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch ppc -m32 -O3 -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.ppc32
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch i386 -fast -m32 -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.intel32
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch x86_64 -fast -m64 -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.intel64
+done
+
+set $progs
+for prog in $progs; do
+#      lipo -create $prog.icc $prog.ppc32 $prog.ppc64 -output $prog
+       lipo -create $prog.intel64 $prog.intel32 $prog.ppc32 $prog.ppc64 -output $prog
+       cp $prog ../binaries
+done
diff --git a/binaries/src/mafft/extensions/Makefile b/binaries/src/mafft/extensions/Makefile
new file mode 100644 (file)
index 0000000..9cc6933
--- /dev/null
@@ -0,0 +1,34 @@
+PREFIX = /usr/local
+LIBDIR = $(PREFIX)/libexec/mafft
+
+#MNO_CYGWIN = -mno-cygwin
+
+INSTALL = install
+
+PROGS = mxscarnamod
+SCARNASRC = mxscarna_src/* mxscarna_src/*/*
+
+all : $(PROGS)
+       cp $(PROGS) ../binaries
+       chmod 755 ../binaries/*
+       @echo done.
+
+univscript: univscript.tmpl Makefile
+       sed "s:_PROGS:$(PROGS):" univscript.tmpl  > univscript
+
+
+mxscarnamod: $(SCARNASRC)
+       $(MAKE) CFLAGS1="$(MNO_CYGWIN)" -C mxscarna_src
+       mv mxscarna_src/mxscarna mxscarnamod
+
+
+clean :
+       rm -f *.o *.a *.exe *~ $(PROGS)
+#      rm -f ../binaries/* ../scripts/*
+       $(MAKE) clean -C mxscarna_src
+
+install : all
+       mkdir -p $(LIBDIR)
+       chmod 755 $(LIBDIR)
+       chmod 755 $(PROGS)
+       $(INSTALL) $(PROGS) $(LIBDIR)
diff --git a/binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.cpp b/binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.cpp
new file mode 100644 (file)
index 0000000..340353f
--- /dev/null
@@ -0,0 +1,211 @@
+#include "AlifoldMEA.h"
+
+namespace MXSCARNA{
+
+const int AlifoldMEA::TURN = 3;
+
+void
+AlifoldMEA::
+Run()
+{
+    makeProfileBPPMatrix(alignment);
+    Initialization();
+    DP();
+    TraceBack();
+}
+
+void
+AlifoldMEA::
+makeProfileBPPMatrix(const MultiSequence *Sequences)
+{
+    int length = Sequences->GetSequence(0)->GetLength();
+
+    Trimat<float> *consBppMat = new Trimat<float>(length + 1);
+    fill(consBppMat->begin(), consBppMat->end(), 0);
+
+    for(int i = 1; i <= length; i++) 
+       for (int j = i; j <= length; j++) 
+           bppMat.ref(i, j) = 0;
+
+
+    int number = Sequences->GetNumSequences();
+    for(int seqNum = 0; seqNum < number; seqNum++) {
+       SafeVector<int> *tmpMap = Sequences->GetSequence(seqNum)->GetMappingNumber();
+       int label = Sequences->GetSequence(seqNum)->GetLabel();
+       BPPMatrix *tmpBppMatrix = BPPMatrices[label];
+       
+       for(int i = 1; i <= length ; i++) {
+           int originI = tmpMap->at(i);
+           for(int j = i; j <= length; j++) {
+               int originJ = tmpMap->at(j);
+               if(originI != 0 && originJ != 0) {
+                   float tmpProb = tmpBppMatrix->GetProb(originI, originJ);
+                   bppMat.ref(i, j) += tmpProb;
+               }
+           }
+       }
+    }
+
+       /* compute the mean of base pairing probability  */
+    for(int i = 1; i <= length; i++) {
+       for(int j = i; j <= length; j++) {
+           bppMat.ref(i,j) = bppMat.ref(i,j)/(float)number;
+       }
+    }
+
+    for (int i = 1; i <= length; i++) {
+       float sum = 0;
+       for (int j = i; j <= length; j++) {
+           sum += bppMat.ref(i,j);
+       }
+       Qi[i] = 1 - sum;
+    }
+
+    for (int i = 1; i <= length; i++) {
+       float sum = 0;
+       for (int j = i; j >= 1; j--) {
+           sum += bppMat.ref(j, i);
+       }
+       Qj[i] = 1 - sum;
+    }
+}
+
+void
+AlifoldMEA::
+Initialization()
+{
+    int length = alignment->GetSequence(0)->GetLength();
+
+    for (int i = 1; i <= length; i++) {
+       for (int j = i; j <= length; j++) {
+           M.ref(i,j) = 0;
+           traceI.ref(i,j) = 0;
+           traceJ.ref(i,j) = 0;
+       }
+    }
+
+    for (int i = 1; i <= length; i++) {
+       M.ref(i,i)   = Qi[i]; 
+       traceI.ref(i,i) = 0;
+       traceJ.ref(i,i) = 0;
+    }
+
+    for (int i = 1; i <= length - 1; i++) {
+       M.ref(i, i+1) =  Qi[i+1];
+       traceI.ref(i,i + 1) = 0;
+       traceJ.ref(i,i + 1) = 0;
+    }
+
+    for (int i = 0; i <= length; i++) {
+       ssCons[i] = '.';
+    }
+}
+
+void
+AlifoldMEA::
+DP()
+{
+    float g    = BasePairConst; // see scarna.hpp
+    int length = alignment->GetSequence(0)->GetLength();
+    
+    for (int i = length - 1; i >= 1; i--) {
+       for (int j = i + TURN + 1; j <= length; j++) {
+           float qi       = Qi[i];
+           float qj       = Qj[j];
+           float p        = bppMat.ref(i,j);
+
+           
+           float maxScore = qi + M.ref(i+1, j);
+           int tmpI = i+1;
+           int tmpJ = j;
+           
+           float tmpScore = qj + M.ref(i, j-1);
+           if (tmpScore > maxScore) {
+               maxScore = tmpScore;
+               tmpI     = i;
+               tmpJ     = j - 1;
+           }
+           
+           tmpScore = g*2*p + M.ref(i+1, j-1);
+           if (tmpScore > maxScore) {
+               maxScore = tmpScore;
+               tmpI     = i + 1;
+               tmpJ     = j - 1;
+           }
+           
+           for (int k = i + 1; k < j - 1; k++) {
+               tmpScore = M.ref(i,k) + M.ref(k+1,j);
+               if (tmpScore > maxScore) {
+                   maxScore = tmpScore;
+                   tmpI = i;
+                   tmpJ = j;
+               }
+           }
+           M.ref(i,j)       = maxScore;
+           traceI.ref(i, j) = tmpI;
+           traceJ.ref(i, j) = tmpJ;
+       }
+    }
+}
+
+void
+AlifoldMEA::
+TraceBack()
+{
+
+    int length = alignment->GetSequence(0)->GetLength();
+    SafeVector<int> stackI((length + 1)*(length+1));
+    SafeVector<int> stackJ((length + 1)*(length+1));
+    int pt = 0;
+
+    stackI[pt] = traceI.ref(1, length);
+    stackJ[pt] = traceJ.ref(1, length);
+    ++pt;
+    
+    while(pt != 0) {
+       --pt;
+       int tmpI = stackI[pt];
+       int tmpJ = stackJ[pt];
+       int nextI = traceI.ref(tmpI, tmpJ);
+       int nextJ = traceJ.ref(tmpI, tmpJ);
+
+       if (tmpI < tmpJ) {
+           if (tmpI + 1  == nextI && tmpJ == nextJ) {
+               stackI[pt] = nextI;
+               stackJ[pt] = nextJ;
+               ++pt;
+           }
+           else if (tmpI == nextI && tmpJ - 1 == nextJ) {
+               stackI[pt] = nextI;
+               stackJ[pt] = nextJ;
+               ++pt;
+           }
+           else if (tmpI + 1 == nextI && tmpJ - 1== nextJ) {
+               stackI[pt] = nextI;
+               stackJ[pt] = nextJ;
+               ++pt;
+               ssCons[tmpI] = '(';
+               ssCons[tmpJ] = ')';
+           }
+           else if (tmpI == nextI && tmpJ == nextJ) {
+               float maxScore = IMPOSSIBLE;
+               int maxK = 0;
+
+               for (int k = tmpI + 1; k < tmpJ - 1; k++) {
+                   float tmpScore = M.ref(tmpI,k) + M.ref(k+1,tmpJ);
+                   if (tmpScore > maxScore) {
+                       maxScore = tmpScore;
+                       maxK = k;
+                   }
+               }
+               stackI[pt] = traceI.ref(tmpI, maxK);
+               stackJ[pt] = traceJ.ref(tmpI, maxK);
+               ++pt;
+               stackI[pt] = traceI.ref(maxK+1, tmpJ);
+               stackJ[pt] = traceJ.ref(maxK+1, tmpJ);
+               ++pt;
+           }
+       }
+    }
+}
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.h b/binaries/src/mafft/extensions/mxscarna_src/AlifoldMEA.h
new file mode 100644 (file)
index 0000000..02c06c5
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef _ALIFOLDMEA_H_
+#define _ALIFOLDMEA_H_
+
+#include <iostream>
+#include <string>
+#include <cassert>
+#include "scarna.hpp"
+#include "nrutil.h"
+#include "Util.hpp"
+#include "Beta.hpp"
+#include "BPPMatrix.hpp"
+#include "MultiSequence.h"
+#include "Sequence.h"
+#include "SafeVector.h"
+
+using namespace std;
+
+namespace MXSCARNA {
+class AlifoldMEA {
+    MultiSequence *alignment;
+    SafeVector<BPPMatrix*> BPPMatrices;
+    float BasePairConst;
+    Trimat<float> M;
+    Trimat<int> traceI;
+    Trimat<int> traceJ;
+    Trimat<float> bppMat;
+    NRVec<float>  Qi;
+    NRVec<float>  Qj;
+    NRVec<char> ssCons;
+    
+    static const int TURN;
+
+    void Initialization();
+    void makeProfileBPPMatrix(const MultiSequence *Sequences);
+    void DP();
+    void TraceBack();
+ public:
+    AlifoldMEA(MultiSequence *inalignment, SafeVector<BPPMatrix*> &inBPPMatrices, float inBasePairConst = 6) :
+       alignment(inalignment), BPPMatrices(inBPPMatrices),
+       BasePairConst(inBasePairConst),
+       M(inalignment->GetSequence(0)->GetLength()+1), 
+       traceI(inalignment->GetSequence(0)->GetLength()+1),
+       traceJ(inalignment->GetSequence(0)->GetLength()+1),
+       bppMat(inalignment->GetSequence(0)->GetLength() + 1), 
+       Qi(inalignment->GetSequence(0)->GetLength() + 1), 
+       Qj(inalignment->GetSequence(0)->GetLength() + 1), 
+       ssCons(inalignment->GetSequence(0)->GetLength() + 1){}
+
+    void Run();
+
+    string *getSScons() {
+       string *sscons = new string();
+       sscons->push_back(' ');
+       int length = alignment->GetSequence(0)->GetLength();
+       for (int i = 1; i <= length; i++) {
+           sscons->push_back(ssCons[i]);
+       }
+       
+       return sscons;
+    }
+};
+}
+#endif // _ALIFOLDMEA_H_
diff --git a/binaries/src/mafft/extensions/mxscarna_src/BPPMatrix.hpp b/binaries/src/mafft/extensions/mxscarna_src/BPPMatrix.hpp
new file mode 100644 (file)
index 0000000..1c16ed7
--- /dev/null
@@ -0,0 +1,130 @@
+//////////////////////////////////////////////////////////////
+// BPPMatrix.hpp
+//
+// save the Base Pairing Probability Matrix for each sequences
+//////////////////////////////////////////////////////////////
+
+#ifndef __BBPMatrix_HPP__
+#define __BBPMatrix_HPP__
+
+#include <iostream>
+#include <string>
+#include "SparseMatrix.h"
+#include "McCaskill.hpp"
+#include "nrutil.h"
+
+
+
+using namespace std;
+
+namespace MXSCARNA{
+class BPPMatrix {
+private:
+
+    int seqLength;       // sequence length;
+    float cutOff;        // the threshold of probability 
+
+    BPPMatrix() {}
+public:
+    SparseMatrix bppMat; // base pairing probability matrix 1-origin(1..seqLength)
+    BPPMatrix(int bppmode, const string &seq, int seqLength, float inCutOff = 0.0001) : seqLength (seqLength), cutOff(inCutOff) {
+      if( bppmode == 'r' ) // by katoh
+        readBPPMatrix(seq);
+      else if( bppmode == 'w' )
+        setandwriteBPPMatrix(seq);
+      else
+        setBPPMatrix(seq);
+    }
+    BPPMatrix(int seqLength, float inCutOff, const Trimat<float> & tmpBppMat) : seqLength(seqLength), cutOff(inCutOff) {
+      bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
+    }
+
+      
+    void setBPPMatrix(const string &seq) {
+       const char *tmpSeq = seq.c_str();
+       McCaskill mc(seqLength, &tmpSeq[1]);
+       mc.calcPartitionFunction();
+       Trimat<float> tmpBppMat(seqLength + 1);
+
+       for (int i = 0; i < seqLength; i++) {
+         for(int j = i; j < seqLength; j++) {
+           tmpBppMat.ref(i+1, j+1) = mc.getProb(i,j);
+         }
+       }
+       bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
+    }
+
+    void setandwriteBPPMatrix(const string &seq) { // by katoh
+        const char *tmpSeq = seq.c_str();
+       McCaskill mc(seqLength, &tmpSeq[1]);
+       mc.calcPartitionFunction();
+       Trimat<float> tmpBppMat(seqLength + 1);
+        float tmpbp;
+
+        fprintf( stdout, ">\n" );
+       for (int i = 0; i < seqLength; i++) {
+         for(int j = i; j < seqLength; j++) {
+        tmpbp = mc.getProb(i,j);
+        if (tmpbp > 0.0001)
+          fprintf( stdout, "%d %d %50.40f\n", i, j, tmpbp );
+           tmpBppMat.ref(i+1, j+1) = tmpbp;
+         }
+       }
+       bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
+    }
+
+    void readBPPMatrix(const string &seq) { // by katoh
+       const char *tmpSeq = seq.c_str();
+       char oneline[1000];
+       int onechar;
+       float prob;
+       int posi, posj;
+       static FILE *bppfp = NULL;
+
+
+       if( bppfp == NULL )
+       {
+               bppfp = fopen( "_bpp", "r" );
+               if( bppfp == NULL )
+               {
+                       fprintf( stderr, "Cannot open _bpp.\n" );
+                       exit( 1 );
+               }
+       }
+
+       Trimat<float> tmpBppMat(seqLength + 1);
+       fgets( oneline, 999, bppfp );
+       if( oneline[0] != '>' )
+       {
+               fprintf( stderr, "Format error\n" );
+               exit( 1 );
+       }
+       while( 1 )
+       {
+               onechar = getc( bppfp ); 
+               ungetc( onechar, bppfp );
+               if( onechar == '>' || onechar == EOF ) break;
+
+               fgets( oneline, 999, bppfp );
+               sscanf( oneline, "%d %d %f", &posi, &posj, &prob );
+//             fprintf( stderr, "%d %d -> %f\n", posi, posj, prob );
+               tmpBppMat.ref(posi+1, posj+1) = prob;
+       }
+
+       bppMat.SetSparseMatrix(seqLength, seqLength, tmpBppMat, cutOff);
+    }
+
+    float GetProb(int i, int j) {
+       return bppMat.GetValue(i,j);
+    }
+
+    float GetLength() const {
+       return seqLength;
+    }
+    
+    void updateBPPMatrix(const Trimat<float> &inbppMat) {
+       bppMat.SetSparseMatrix(seqLength, seqLength, inbppMat, cutOff);
+    }
+};
+}
+#endif // __BPPMatrix_HPP__
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Beta.hpp b/binaries/src/mafft/extensions/mxscarna_src/Beta.hpp
new file mode 100644 (file)
index 0000000..f1e77a4
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ *
+ * Beta.hpp
+ *
+ */
+#ifndef BETA_HPP
+#define BETA_HPP
+using namespace std;
+
+struct Beta {
+  static const int NBASE = 4;// A, C, G, U
+  static const int NBASEG = (NBASE + 1);     // A, C, G, U, Gap
+  static const int NBASENG = (NBASE + 2);    // A, C, G, U, N, Gap
+  static const int NPBASE = (NBASE * NBASE);
+  static const int NPBASEG = (NBASEG * NBASEG);
+  static const int NPBASENG = (NBASENG * NBASENG);
+  static const int NCODE = 7;
+  static const int BASEBIT = 2;
+  static const int BASEMSK = ~(~0 << BASEBIT);
+  enum BaseCode {
+    A_CODE       = 0,
+    C_CODE       = 1,
+    G_CODE       = 2,
+    U_CODE       = 3,
+    N_CODE       = 4,
+    GAP_CODE     = 5,
+    INVALID_CODE = 16
+  };
+  enum PairCode {
+    AA_CODE =  0, AC_CODE =  1, AG_CODE =  2, AU_CODE =  3,
+    CA_CODE =  4, CC_CODE =  5, CG_CODE =  6, CU_CODE =  7,
+    GA_CODE =  8, GC_CODE =  9, GG_CODE = 10, GU_CODE = 11,
+    UA_CODE = 12, UC_CODE = 13, UG_CODE = 14, UU_CODE = 15,
+    INVALID_PAIR_CODE = 16
+  };
+  enum ReducedPairCode {
+    REDUCED_NPBASE = 7,
+    REDUCED_AU_CODE = 0,
+    REDUCED_CG_CODE = 1,
+    REDUCED_GC_CODE = 2,
+    REDUCED_GU_CODE = 3,
+    REDUCED_UA_CODE = 4,
+    REDUCED_UG_CODE = 5,
+    REDUCED_MM_CODE = 6,
+    REDUCED_INVALID_PAIR_CODE = 16
+  };
+
+  static const int N_CANONICAL = 6;
+  static const int canonicalPairs[N_CANONICAL];
+  static const int N_NON_CANONICAL = 10;
+  static const int nonCanonicalPairs[N_NON_CANONICAL];
+  static const int i2nt[NCODE];
+  static const int nt2i[256];
+  static const bool isCanonicalBasePair[NPBASE];
+
+  static bool IsValidCode(const int& c) {return A_CODE <= c && c <= GAP_CODE;}
+  static bool IsBaseCode(const int& c) {return (A_CODE <= c && c <= U_CODE);}
+  static bool IsBasePairCode(const int& c){return (AA_CODE <= c && c <= UU_CODE);}
+  static bool IsReducedBasePairCode(const int& c) {
+    return (REDUCED_AU_CODE <= c && c <= REDUCED_MM_CODE);
+  }
+  static bool IsAmbiguousCode(const int& c) {return c == N_CODE;}
+  static bool IsGapCode(const int& c) {return c == GAP_CODE;}
+  static bool IsValidChar(const unsigned char& c) {
+    return IsValidCode(nt2i[c]);
+  }
+  static bool IsBaseChar(const int& c) {return IsBaseCode(nt2i[c]);}
+  static bool IsAmbiguousChar(const int& c) {return IsAmbiguousCode(nt2i[c]);}
+  static bool IsGapChar(const int& c) {return IsGapCode(nt2i[c]);}
+  static int nt2code(const int& nt) {
+    if (0 <= nt && nt < 256) {
+      return nt2i[nt];
+    } else {
+      return INVALID_CODE;
+    }
+  }
+  static int getPairCode(const int& c, const int& c1) {
+    return (IsBaseCode(c) && IsBaseCode(c1) 
+           ? ((c << BASEBIT) | c1)
+           : INVALID_PAIR_CODE);
+  }
+  static bool isValidPairCode(const int& pairCode) {
+    return (0 <= pairCode && pairCode < NPBASE);
+  }
+  static void pair2Bases(const int& pairCode, int& c, int& c1) {
+      //Assert(IsBasePairCode(pairCode));
+    c1 = pairCode & BASEMSK;
+    c = (pairCode >> BASEBIT) & BASEMSK;
+  }
+  static int getReducedPairCode(const int& c, const int& c1) {
+    return reducePairCode(getPairCode(c, c1));
+  }
+  static int reducePairCode(const int& pairCode) {
+    static const int table[NPBASE] = {
+      REDUCED_MM_CODE, REDUCED_MM_CODE, REDUCED_MM_CODE, REDUCED_AU_CODE,
+      REDUCED_MM_CODE, REDUCED_MM_CODE, REDUCED_CG_CODE, REDUCED_MM_CODE,
+      REDUCED_MM_CODE, REDUCED_GC_CODE, REDUCED_MM_CODE, REDUCED_GU_CODE,
+      REDUCED_UA_CODE, REDUCED_MM_CODE, REDUCED_UG_CODE, REDUCED_MM_CODE,
+    };
+    return (IsBasePairCode(pairCode)
+           ? table[pairCode]
+           : REDUCED_INVALID_PAIR_CODE);
+  }
+  static bool isValidReducedPairCode(const int& pairCode) {
+    return (0 <= pairCode && pairCode < REDUCED_NPBASE);
+  }
+  static bool isCanonicalReducedPairCode(const int& pairCode) {
+    return (REDUCED_AU_CODE <= pairCode
+           && pairCode <= REDUCED_UG_CODE);
+  }
+  static int flipReducedPairCode(const int& reducedPairCode) {
+    static const int table[REDUCED_NPBASE + 1] = {
+      REDUCED_UA_CODE,
+      REDUCED_GC_CODE,
+      REDUCED_CG_CODE,
+      REDUCED_UG_CODE,
+      REDUCED_AU_CODE,
+      REDUCED_GU_CODE,
+      REDUCED_MM_CODE,
+      REDUCED_INVALID_PAIR_CODE
+    };
+    return (IsReducedBasePairCode(reducedPairCode)
+           ? table[reducedPairCode] : table[REDUCED_NPBASE]);
+  }
+  static void seq2i(char* s, const char* t, int len) {
+    const char* const s_end = s + len;
+    while (s < s_end) *s++ = nt2i[(unsigned) (*t++)];
+  }
+  static void i2seq(char* s, const char* t, int len) {
+    const char* const s_end = s + len;
+    while (s < s_end) *s++ = i2nt[(unsigned) (*t++)];
+  }
+  static void i2seq(ostream& fo, const char* t, int len) {
+    const char* const t_end = t + len;
+    while (t < t_end) fo << (char) i2nt[(unsigned) (*t++)];
+  }
+  static char* wd2str(unsigned int wdSize, unsigned int wd) {
+    const unsigned int MAX_WD_SIZE = (sizeof(unsigned int) * 8 / BASEBIT);
+    static char buf[MAX_WD_SIZE + 1] = {};
+    //Assert(wdSize <= MAX_WD_SIZE);
+
+    char* s = buf + wdSize;
+    *s = '\0';
+    do {
+      *(--s) = Beta::i2nt[wd & BASEMSK];
+      wd >>= BASEBIT;
+    } while (s > buf);
+    return buf;
+  }
+  static void printWd(ostream& fo, unsigned int wdSize, unsigned int wd) {
+    fo << wd2str(wdSize, wd);
+  }
+  static const char* code2str(const int& code) {
+    static const char table[NBASENG+1][2] = {
+      "A", "C", "G", "U", "N", ".", "?"
+    };
+    return ((A_CODE <= code && code <= GAP_CODE)
+           ? table[code] : table[NBASENG]);
+  }
+  static const char* pairCode2str(const int& pairCode) {
+    static const char table[NPBASE+1][3] = {
+      "AA", "AC", "AG", "AU",
+      "CA", "CC", "CG", "CU",
+      "GA", "GC", "GG", "GU",
+      "UA", "UC", "UG", "UU",
+      "??"
+    };
+    return (IsBasePairCode(pairCode) ? table[pairCode] : table[NPBASE]);
+  }
+  static const char* reducedPairCode2str(const int& reducedPairCode) {
+    static const char table[REDUCED_NPBASE+1][3] = {
+      "AU", "CG", "GC", "GU", "UA", "UG", "MM", "??"
+    };
+    return (IsReducedBasePairCode(reducedPairCode)
+           ? table[reducedPairCode] : table[REDUCED_NPBASE]);
+  }
+  static char nt2Code(const char& c){
+      if (!IsValidChar(c)) { cerr << "character " <<  c << " is not valid"; }
+
+    return (char) nt2i[(int) c];
+  }
+  static char code2char(const int& c) {
+     static const char table[NBASENG+1] = {
+      'A', 'C', 'G', 'U', 'N', '.', '?'
+    };
+    return ((A_CODE <= c && c <= GAP_CODE)
+           ? table[(int) c] : table[NBASENG]);
+  }
+    /*
+  static string generateRandomRNA(const int& len) {
+    static const char nt[5] = "ACGU";
+    string rna(len, '\0');
+    for (int i = 0; i < len; i++) {
+      rna[i] = nt[Rand(4)];
+    }
+    return rna;
+  }
+    */
+};
+
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/GlobalParameters.cpp b/binaries/src/mafft/extensions/mxscarna_src/GlobalParameters.cpp
new file mode 100644 (file)
index 0000000..4d32c8e
--- /dev/null
@@ -0,0 +1,27 @@
+//////////////////////////////////////////////////////////////
+// GlobalParameters.cpp
+// This file include Global Parameters, command line options, etc.
+//////////////////////////////////////////////////////////////
+
+#include "scarna.hpp"
+
+// These paramenters are defined in scarna.hpp
+
+float RNA_Match_AA      = RNAMATCHAA;
+float RNA_Match_AT      = RNAMATCHAT;
+float RNA_Match_AG      = RNAMATCHAG;
+float RNA_Match_AC      = RNAMATCHAC;
+float RNA_Match_TT      = RNAMATCHTT;
+float RNA_Match_TG      = RNAMATCHTG;
+float RNA_Match_TC      = RNAMATCHTC;
+float RNA_Match_GG      = RNAMATCHGG;
+float RNA_Match_GC      = RNAMATCHGC;
+float RNA_Match_CC      = RNAMATCHCC;
+float RNA_Gap_Penalty   = GAPPENALTY;
+float RNA_Gap_Extension = GAPEXTENTIONPENALTY;
+
+int   numIterativeRefinementReps = REFINEMENTREPS;
+bool  PostProcessAlignment = false;
+int   scsLength = SCSLENGTH;
+float BaseProbThreshold = BASEPROBTHRESHOLD;
+float BasePairConst     = BASEPAIRCONST;
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Globaldp.cpp b/binaries/src/mafft/extensions/mxscarna_src/Globaldp.cpp
new file mode 100644 (file)
index 0000000..daabff4
--- /dev/null
@@ -0,0 +1,557 @@
+#include "Globaldp.hpp"
+
+namespace MXSCARNA {
+
+double Globaldp::ribosum_matrix[16][16]
+= { { -2.49,  -7.04,  -8.24,  -4.32,  -8.84,  -14.37,  -4.68, -12.64, -6.86, -5.03, -8.39,  -5.84, -4.01, -11.32, -6.16, -9.05 },
+    { -7.04,  -2.11,  -8.89,  -2.04,  -9.37,  -9.08,   -5.86, -10.45, -9.73, -3.81, -11.05, -4.72, -5.33, -8.67,  -6.93, -7.83 },
+    { -8.24,  -8.89,  -0.80,  -5.13,  -10.41, -14.53,  -4.57, -10.14, -8.61, -5.77, -5.38,  -6.60, -5.43, -8.87,  -5.94, -11.07 },
+    { -4.32,  -2.04,  -5.13,   4.49,  -5.56,  -6.71,    1.67, -5.17,  -5.33,  2.70, -5.61,   0.59,  1.61, -4.81,  -0.51, -2.98 },
+    { -8.84,  -9.37,  -10.41, -5.56,  -5.13,  -10.45,  -3.57, -8.49,  -7.98, -5.95, -11.36, -7.93, -2.42, -7.08,  -5.63, -8.39 },
+    { -14.37, -9.08,  -14.53, -6.71,  -10.45, -3.59,   -5.71, -5.77, -12.43, -3.70, -12.58, -7.88, -6.88, -7.40,  -8.41, -5.41 },
+    { -4.68,  -5.86,  -4.57,   1.67,  -3.57,  -5.71,    5.36, -4.96,  -6.00,  2.11, -4.66,  -0.27,  2.75, -4.91,   1.32, -3.67 },
+    { -12.64, -10.45, -10.14, -5.17,  -8.49,  -5.77,   -4.96, -2.28,  -7.71, -5.84, -13.69, -5.61, -4.72, -3.83,  -7.36, -5.21 },
+    { -6.86,  -9.73,  -8.61,  -5.33,  -7.98,  -12.43,  -6.00, -7.71,  -1.05, -4.88, -8.67,  -6.10, -5.85, -6.63,  -7.55, -11.54 },
+    { -5.03,  -3.81,  -5.77,   2.70,  -5.95,  -3.70,    2.11, -5.84,  -4.88,  5.62, -4.13,   1.21,  1.60, -4.49,  -0.08, -3.90 },
+    { -8.39,  -11.05, -5.38,  -5.61,  -11.36, -12.58,  -4.66, -13.69, -8.67, -4.13, -1.98,  -5.77, -5.75, -12.01, -4.27, -10.79 },
+    { -5.84,  -4.72,  -6.60,   0.59,  -7.93,  -7.88,   -0.27, -5.61,  -6.10,  1.21, -5.77,   3.47, -0.57, -5.30,  -2.09, -4.45 },
+    { -4.01,  -5.33,  -5.43,   1.61,  -2.42,  -6.88,    2.75, -4.72,  -5.85,  1.60, -5.75,  -0.57,  4.97, -2.98,   1.14, -3.39 },
+    { -11.32, -8.67,  -8.87,  -4.81,  -7.08,  -7.40,   -4.91, -3.83,  -6.63, -4.49, -12.01, -5.30, -2.98, -3.21,  -4.76, -5.97 },
+    { -6.16,  -6.93,  -5.94,  -0.51,  -5.63,  -8.41,    1.32, -7.36,  -7.55, -0.08, -4.27,  -2.09,  1.14, -4.76,   3.36, -4.28 },
+    { -9.05,  -7.83,  -11.07, -2.98,  -8.39,  -5.41,   -3.67, -5.21, -11.54, -3.90, -10.79, -4.45, -3.39, -5.97,  -4.28, -0.02 }
+};
+
+
+Trimat<float>* 
+Globaldp::
+makeProfileBPPMatrix(const MultiSequence *Sequences)
+{
+    int length = Sequences->GetSequence(0)->GetLength();
+    float thr  = THR;
+    Trimat<float> *consBppMat = new Trimat<float>(length + 1);
+    fill(consBppMat->begin(), consBppMat->end(), 0);
+
+    int number = Sequences->GetNumSequences();
+    for(int seqNum = 0; seqNum < number; seqNum++) {
+       SafeVector<int> *tmpMap = Sequences->GetSequence(seqNum)->GetMappingNumber();
+       int label = Sequences->GetSequence(seqNum)->GetLabel();
+       BPPMatrix *tmpBppMatrix = BPPMatrices[label];
+           
+       for(int i = 1; i <= length ; i++) {
+           int originI = tmpMap->at(i);
+           for(int j = i; j <= length; j++) {
+               int originJ = tmpMap->at(j);
+               if(originI != 0 && originJ != 0) {
+                   float tmpProb = tmpBppMatrix->GetProb(originI, originJ);
+
+                   if(tmpProb >= thr) {
+                       consBppMat->ref(i, j) += tmpProb;
+                   }
+               }
+           }
+       }
+    }
+
+       /* compute the mean of base pairing probability  */
+    for(int i = 1; i <= length; i++) {
+       for(int j = i; j <= length; j++) {
+           consBppMat->ref(i,j) = consBppMat->ref(i,j)/(float)number;
+       }
+    }
+
+    return consBppMat;   
+}
+
+float 
+Globaldp::
+incrementalScorePSCPair(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    int wordLength = WORDLENGTH;
+
+    int pos1, rvpos1;
+    if (sc1.GetDistance() > 0) {
+       pos1   = sc1.GetPosition();
+       rvpos1 = sc1.GetRvposition();
+    }
+    else {
+       pos1   = sc1.GetRvposition();
+       rvpos1 = sc1.GetPosition();
+    }
+
+    int pos2, rvpos2;
+    if (sc2.GetDistance() > 0) {
+       pos2   = sc2.GetPosition();
+       rvpos2 = sc2.GetRvposition();
+    }
+    else {
+       pos2   = sc2.GetRvposition();
+       rvpos2 = sc2.GetPosition();
+    }
+/*
+    cout << "1:" << i << " " << j << " " << sc1.GetDistance() << " " << sc2.GetDistance() << endl;
+    cout << sc1.GetPosition() << " " << sc1.GetRvposition() << " " << sc2.GetPosition() << " " << sc2.GetRvposition() << endl;
+*/  
+    float score = 
+         posterior[sc1.GetPosition() + wordLength - 1][sc2.GetPosition() + wordLength - 1]
+//     * sc1.GetBaseScore(wordLength - 1)
+       * profileBPPMat1->ref(pos1 + wordLength - 1, rvpos1)
+       * posterior[sc1.GetRvposition()][sc2.GetRvposition()]
+//     * sc2.GetBaseScore(wordLength - 1);
+       * profileBPPMat2->ref(pos2 + wordLength - 1, rvpos2);
+       
+       
+/*
+         incrementalWordSimilarity(sc1, sc2, i, j)
+       + incrementalProbabilityScore(sc1, sc2) * multiDeltaScore
+       + incrementalStackingScore(sc1, sc2) * multiDeltaStacking;
+*/
+
+    return score*sc1.GetNumSeq()*sc2.GetNumSeq();
+}
+
+float
+Globaldp::
+incrementalProbabilityScore(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    int wordLength = WORDLENGTH;
+    return sc1.GetBaseScore(wordLength-1) + sc2.GetBaseScore(wordLength-1);
+}
+
+float
+Globaldp::
+incrementalStackingScore(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    return - (sc1.GetStacking() + sc2.GetStacking());
+}
+
+float
+Globaldp::
+incrementalWordSimilarity(const StemCandidate &sc1, const StemCandidate &sc2, int i, int j)
+{
+    int numSeq1 = sc1.GetNumSeq();
+    int numSeq2 = sc2.GetNumSeq();
+
+    float score = 0;
+
+    for(int k = 0; k < 16; k++) {
+       for(int l = 0; l < 16; l++) {
+           score += countContConp1[k][i]*countContConp2[l][j]*ribosum_matrix[k][l];
+       }
+    }
+
+    return score/(numSeq1*numSeq2);
+}
+
+float 
+Globaldp::
+scorePSCPair(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+
+
+    int wordLength = WORDLENGTH;
+    float score = 0;
+    
+    int pos1, rvpos1;
+    if (sc1.GetDistance() > 0) {
+       pos1   = sc1.GetPosition();
+       rvpos1 = sc1.GetRvposition();
+    }
+    else {
+       pos1   = sc1.GetRvposition();
+       rvpos1 = sc1.GetPosition();
+    }
+
+    int pos2, rvpos2;
+    if (sc2.GetDistance() > 0) {
+       pos2   = sc2.GetPosition();
+       rvpos2 = sc2.GetRvposition();
+    }
+    else {
+       pos2   = sc2.GetRvposition();
+       rvpos2 = sc2.GetPosition();
+    }
+    
+    for (int k = 0; k < wordLength; k++) {
+       score +=
+             posterior[sc1.GetPosition() + k][sc2.GetPosition() + k]
+           * profileBPPMat1->ref(pos1 + k, rvpos1 + wordLength - 1 - k)
+//         * sc1.GetBaseScore(k)
+           * posterior[sc1.GetRvposition() + wordLength - 1 - k][sc2.GetRvposition() + wordLength - 1 - k]
+//         * sc2.GetBaseScore(k);
+           * profileBPPMat2->ref(pos2 + k, rvpos2 + wordLength - 1 - k);
+    }
+    // validation code
+    /*
+    if (profileBPPMat1->ref(pos1 , rvpos1 + wordLength - 1) != sc1.GetBaseScore(0)) {
+       cout << "1 " << profileBPPMat1->ref(pos1, rvpos1 + wordLength - 1) << " " << sc1.GetBaseScore(0) << endl;
+    }
+    if (profileBPPMat2->ref(pos2, rvpos2 + wordLength - 1) != sc2.GetBaseScore(0)) {
+       cout << profileBPPMat2->ref(pos2, rvpos2 + wordLength - 1) << " " << sc2.GetBaseScore(0) << endl;
+    }
+    if (profileBPPMat1->ref(pos1 + 1, rvpos1 + wordLength - 1 - 1) != sc1.GetBaseScore(1)) {
+       cout << "1 " << profileBPPMat1->ref(pos1 + 1, rvpos1 + wordLength - 1 - 1) << " " << sc1.GetBaseScore(1) << endl;
+    }
+    if (profileBPPMat2->ref(pos2 + 1, rvpos2 + wordLength - 1 - 1) != sc2.GetBaseScore(1)) {
+       cout << profileBPPMat2->ref(pos2 + 1, rvpos2 + wordLength - 1 - 1) << " " << sc2.GetBaseScore(1) << endl;
+       }*/
+
+//    cout << sc1.GetPosition() << " " << sc1.GetRvposition() << " " << sc1.GetDistance() << endl;
+//    cout << sc2.GetPosition() << " " << sc2.GetRvposition() << " " << sc2.GetDistance() << endl;
+/*
+         wordSimilarity(sc1, sc2, i, j)
+       + probabilityScore(sc1, sc2) * multiScore
+       + stackingScore(sc1, sc2) * multiStacking
+
+*/ 
+/*
+    if (sc1.GetDistance() < 0 && sc2.GetDistance() < 0) {
+       cout << "2:" << i << " " << j << " " << sc1.GetDistance() << " " << sc2.GetDistance() << endl;
+       cout << sc1.GetPosition() << " " << sc1.GetRvposition() << " " << sc2.GetPosition() << " " << sc2.GetRvposition() << endl;
+       cout << "2:score" << score << endl;
+
+    }
+*/
+    return score*sc1.GetNumSeq()*sc2.GetNumSeq();
+}
+
+float
+Globaldp::
+wordSimilarity(const StemCandidate &sc1, const StemCandidate &sc2, int i, int j)
+{
+    int wordLength = WORDLENGTH;
+
+    int numSeq1 = sc1.GetNumSeq();
+    int numSeq2 = sc2.GetNumSeq();
+
+    float score = 0;
+
+    for(int k = 0; k < 16; k++) {
+       for(int l = 0; l < 16; l++) {
+           for(int iter = 0; iter < wordLength; iter++) {
+               score += countConp1[iter][k][i]*countConp2[iter][l][j]*ribosum_matrix[k][l];
+           }
+       }
+    }
+
+    return score/(numSeq1*numSeq2);
+}
+
+int
+Globaldp::
+returnBasePairType(char s, char r)
+{
+    if  (s == 'A') {
+       if      (r == 'A') return 0;
+       else if (r == 'C') return 1;
+       else if (r == 'G') return 2;
+       else if (r == 'U') return 3;
+    }
+    else if (s == 'C') {
+       if      (r == 'A') return 4;
+       else if (r == 'C') return 5;
+       else if (r == 'G') return 6;
+       else if (r == 'U') return 7;
+    }
+    else if (s == 'G') {
+       if      (r == 'A') return 8;
+       else if (r == 'C') return 9;
+       else if (r == 'G') return 10;
+       else if (r == 'U') return 11;
+    }
+    else if (s == 'U') {
+       if      (r == 'A') return 12;
+       else if (r == 'C') return 13;
+       else if (r == 'G') return 14;
+       else if (r == 'U') return 15;
+    }
+
+    return 16;
+}
+
+float
+Globaldp::
+probabilityScore(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    return sc1.GetScore() + sc2.GetScore();
+}
+
+float
+Globaldp::
+stackingScore(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    return - (sc1.GetStemStacking() + sc2.GetStemStacking());
+}
+
+float
+Globaldp::
+distancePenalty(const StemCandidate &sc1, const StemCandidate &sc2)
+{
+    return std::sqrt((float)std::abs(sc1.GetDistance() - sc2.GetDistance()));
+}
+
+float
+Globaldp::
+Run()
+{
+    Initialize();
+    DP();
+    float score = traceBack();
+    
+    // printMatch();
+    //cout << "score=" << score << endl;
+    return score;
+}
+
+void
+Globaldp::
+Initialize()
+{
+    int nPscs1 = pscs1->size();
+    int nPscs2 = pscs2->size();
+
+
+    for(int i = 0; i < nPscs1; i++) {
+       for(int j = 0; j < nPscs2; j++) {
+           VM[i][j] = 0;
+           VG[i][j] = 0;
+       }
+    }
+
+    VM[0][0] = 0;
+    VG[0][0] = IMPOSSIBLE;
+
+    for (int i = 1; i < nPscs1; i++) {
+       VM[i][0] = IMPOSSIBLE; VG[i][0] = 0;
+    }
+    for (int j = 1; j < nPscs2; j++) {
+       VM[0][j] = IMPOSSIBLE; VG[0][j] = 0;
+    }
+
+    for (int i = 0; i < nPscs1; i++) {
+       for (int j = 0; j < nPscs2; j++) {
+           traceMI[i][j] = 0; traceMJ[i][j] = 0;
+           traceGI[i][j] = 0; traceGJ[i][j] = 0;
+       }
+    }
+
+    int wordLength = WORDLENGTH;
+    int size1   = pscs1->size();
+    int size2   = pscs2->size();
+
+    for(int i = 0; i < wordLength; i++) {
+       for(int j = 0; j < 17; j++) {
+           for(int k = 0; k < (int)pscs1->size(); k++) {
+               countConp1[i][j][k] = 0;
+           }
+       }
+    }
+    for(int i = 0; i < wordLength; i++) {
+       for(int j = 0; j < 17; j++) {
+           for(int k = 0; k < (int)pscs2->size(); k++) {
+               countConp2[i][j][k] = 0;
+           }
+       }
+    }
+    for(int i = 0; i < 17; i++) {
+       for(int j = 0; j < (int)pscs1->size()+1; j++) {
+           countContConp1[i][j] = 0;
+       }
+    }
+    for(int i = 0; i < 17; i++) {
+       for(int j = 0; j < (int)pscs2->size()+1; j++) {
+           countContConp2[i][j] = 0;
+       }
+    }
+
+    for(int iter = 1; iter < size1; iter++) {
+
+       const StemCandidate &sc1 = pscs1->at(iter);
+       int numSeq1 = sc1.GetNumSeq();
+       for (int i = 0; i < wordLength; i++) {
+       
+           for(int k = 0; k < numSeq1; k++) {
+//             const Sequence *seq = seqs1->GetSequence(k);
+               string substr = sc1.GetSubstr(k);
+               string rvstr  = sc1.GetRvstr(k);
+           
+               char sChar = substr[i];
+               char rChar = rvstr[wordLength - 1 -i];
+           
+               int type = returnBasePairType(sChar, rChar);
+               ++countConp1[i][type][iter];
+           }
+       }
+       for(int k = 0; k < numSeq1; k++) {
+//         const Sequence *seq = seqs1->GetSequence(k);
+           string substr = sc1.GetSubstr(k);
+           string rvstr  = sc1.GetRvstr(k);
+
+           char sChar = substr[wordLength-1];
+           char rChar = rvstr[0];
+           
+           int type = returnBasePairType(sChar, rChar);
+           ++countContConp1[type][iter];
+
+       }
+    }
+    for(int iter = 1; iter < size2; iter++) {
+       const StemCandidate &sc2 = pscs2->at(iter);
+       int numSeq2 = sc2.GetNumSeq();
+       for (int i = 0; i < wordLength; i++) {
+       
+           for(int k = 0; k < numSeq2; k++) {
+//             const Sequence *seq = seqs2->GetSequence(k);
+               string substr = sc2.GetSubstr(k);
+               string rvstr  = sc2.GetRvstr(k);
+           
+               char sChar = substr[i];
+               char rChar = rvstr[wordLength - 1 -i];
+           
+               int type = returnBasePairType(sChar, rChar);
+               ++countConp2[i][type][iter];
+           }
+       }
+       for(int k = 0; k < numSeq2; k++) {
+//         const Sequence *seq = seqs2->GetSequence(k);
+           string substr = sc2.GetSubstr(k);
+           string rvstr  = sc2.GetRvstr(k);
+
+           char sChar = substr[wordLength-1];
+           char rChar = rvstr[0];
+           
+           int type = returnBasePairType(sChar, rChar);
+           ++countContConp2[type][iter];
+
+       }
+    }
+    profileBPPMat1 = makeProfileBPPMatrix(seqs1);
+    profileBPPMat2 = makeProfileBPPMatrix(seqs2);
+}
+
+void
+Globaldp::
+DP()
+{
+    int nPscs1 = pscs1->size();
+    int nPscs2 = pscs2->size();
+    
+    for(int i = 1; i < nPscs1; i++) {
+       const StemCandidate &sc1 = pscs1->at(i);
+
+       for(int j = 1; j < nPscs2; j++) {
+           const StemCandidate &sc2 = pscs2->at(j);
+           
+           float max = IMPOSSIBLE;
+           int traceI = 0; 
+           int traceJ = 0;
+           int alpha = sc1.GetContPos(), beta = sc2.GetContPos();
+           if( (alpha > 0) && (beta > 0) ) {
+               max = VM[alpha][beta] + incrementalScorePSCPair(sc1, sc2);
+               traceI = alpha;
+               traceJ = beta;
+           }
+           
+           float similarity = scorePSCPair(sc1, sc2);
+           int p = sc1.GetBeforePos(), q = sc2.GetBeforePos();
+           float tmpScore = VM[p][q] + similarity;
+//         cout << i << " " << j << " " << p << " " << q << " " << tmpScore << " " << VM[p][q] << " " << similarity << " " << endl;
+               
+           if(max <= tmpScore) {
+               max = tmpScore;
+               traceI = p;
+               traceJ = q;
+           }
+
+           tmpScore = VG[p][q] + similarity;
+           if(max <= tmpScore) {
+               max = tmpScore;
+               traceI = traceGI[p][q];
+               traceJ = traceGJ[p][q];
+           }
+           
+           VM[i][j]      = max;
+           traceMI[i][j] = traceI;
+           traceMJ[i][j] = traceJ;
+           
+           max = VM[i][j-1];
+           traceI   = i;
+           traceJ   = j-1;
+
+           tmpScore = VM[i-1][j];
+           if(max <= tmpScore) {
+               max    = tmpScore;
+               traceI = i-1;
+               traceJ = j;
+           }
+
+           tmpScore = VG[i-1][j];
+           if(max <= tmpScore) {
+               max    = tmpScore;
+               traceI = traceGI[i-1][j];
+               traceJ = traceGJ[i-1][j];
+           }
+           
+           tmpScore = VG[i][j-1];
+           if(max <= tmpScore) {
+               max = tmpScore;
+               traceI = traceGI[i][j-1];
+               traceJ = traceGJ[i][j-1];
+           }
+
+           VG[i][j]      = max;
+           traceGI[i][j] = traceI;
+           traceGJ[i][j] = traceJ;
+       }
+    }
+}
+
+float
+Globaldp::
+traceBack()
+{
+    int nPscs1 = pscs1->size();
+    int nPscs2 = pscs2->size();
+    
+    float max = IMPOSSIBLE;
+    int traceI, traceJ;
+    for (int i = 1; i < nPscs1; i++) {
+       for (int j = 1; j < nPscs2; j++) {
+           if(max < VM[i][j]) {
+               max = VM[i][j];
+               traceI = i;
+               traceJ = j;
+           }
+       }
+    }
+
+    while ( (traceI != 0) &&  (traceJ != 0) ) {
+       matchPSCS1->push_back(traceI); matchPSCS2->push_back(traceJ);
+       int tmpI = traceMI[traceI][traceJ];
+       int tmpJ = traceMJ[traceI][traceJ];
+       traceI = tmpI; traceJ = tmpJ;
+    }
+    
+    if(traceI != 0 && traceJ != 0) {
+       std::cout << "error in trace back of pscs:" << traceI << " " << traceJ << endl;
+    }
+
+    return max;
+}
+
+void
+Globaldp::
+printMatch()
+{
+    int size = matchPSCS1->size();
+    for(int iter = 0; iter < size; iter++) {
+       int i = matchPSCS1->at(iter);
+       int j = matchPSCS2->at(iter);
+       
+       const StemCandidate &sc1 = pscs1->at(i);
+       const StemCandidate &sc2 = pscs2->at(j);
+
+       std::cout << iter << "\t" << sc1.GetPosition()  << "\t" << sc1.GetRvposition() << "\t" << sc2.GetPosition() << "\t" << sc2.GetRvposition() << endl;
+    }
+
+}
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Globaldp.hpp b/binaries/src/mafft/extensions/mxscarna_src/Globaldp.hpp
new file mode 100644 (file)
index 0000000..ba3e06f
--- /dev/null
@@ -0,0 +1,109 @@
+////////////////////////////////////////////////////////////////
+// Globaldp.hpp
+// Global Alignment of two profile computed by SCARNA algorithm
+////////////////////////////////////////////////////////////////
+
+
+#ifndef __GLOBALDP_HPP__
+#define  __GLOBALDP_HPP__
+
+#include <string>
+#include <iostream>
+#include "nrutil.h"
+#include "Util.hpp"
+#include "Beta.hpp"
+#include "scarna.hpp"
+#include "StemCandidate.hpp"
+#include "MultiSequence.h"
+#include "Sequence.h"
+#include "BPPMatrix.hpp"
+
+using namespace ProbCons;
+using namespace std;
+namespace MXSCARNA {
+
+typedef std::vector<StemCandidate> stemcandidate;
+class Globaldp {
+private:
+    static double ribosum_matrix[16][16];
+
+    NRMat<float> VM, VG;
+    NRMat<int>   traceMI, traceMJ, traceGI, traceGJ;
+
+    const stemcandidate *pscs1, *pscs2;
+    const MultiSequence *seqs1, *seqs2;
+    std::vector<int> *matchPSCS1, *matchPSCS2;
+    SafeVector<BPPMatrix*> &BPPMatrices;
+    NRMat<float> posterior;
+    NRMat3d<int> countConp1, countConp2;
+    NRMat<int> countContConp1, countContConp2;
+    Trimat<float> *profileBPPMat1;
+    Trimat<float> *profileBPPMat2;
+    float multiDeltaScore;
+    float multiDeltaStacking;
+    float multiScore;
+    float multiStacking;
+    float multiPenalty;
+    
+    float scorePSCPair(const StemCandidate &sc1, const StemCandidate &sc2);
+    float wordSimilarity(const StemCandidate &sc1, const StemCandidate &sc2, int i, int j);
+    int   returnBasePairType(char s, char r);
+    float probabilityScore(const StemCandidate &sc1, const StemCandidate &sc2);
+    float stackingScore(const StemCandidate &sc1, const StemCandidate &sc2);
+    float distancePenalty(const StemCandidate &sc1, const StemCandidate &sc2);
+    float incrementalScorePSCPair(const StemCandidate &sc1, const StemCandidate &sc2);
+    float incrementalProbabilityScore(const StemCandidate &sc1, const StemCandidate &sc2);
+    float incrementalStackingScore(const StemCandidate &sc1, const StemCandidate &sc2);
+    float incrementalWordSimilarity(const StemCandidate &sc1, const StemCandidate &sc2, int i, int j);
+    Trimat<float>* makeProfileBPPMatrix(const MultiSequence *Sequences);
+
+    void Initialize();
+    void DP();
+    float traceBack();
+    void printMatch();
+public:
+
+    Globaldp(const stemcandidate *mypscs1, const stemcandidate *mypscs2, 
+            const MultiSequence *myseqs1, const MultiSequence *myseqs2,
+            std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2,
+            VF *myPosterior, SafeVector<BPPMatrix*> &myBPPMatrices,
+            float myMultiDeltaScore = MULTIDELTASCORE, float myMultiDeltaStacking = MULTIDELTASTACKING,
+            float myMultiScore = MULTISCORE, float myMultiStacking = MULTISTACKING,
+            float myMultiPenalty = MULTIPENALTY) 
+       : VM(mypscs1->size(), mypscs2->size()), 
+         VG(mypscs1->size(), mypscs2->size()),
+         traceMI(mypscs1->size(), mypscs2->size()),
+         traceMJ(mypscs1->size(), mypscs2->size()),
+         traceGI(mypscs1->size(), mypscs2->size()),
+         traceGJ(mypscs1->size(), mypscs2->size()),
+         pscs1(mypscs1), pscs2(mypscs2), 
+         seqs1(myseqs1), seqs2(myseqs2),
+         matchPSCS1(matchPSCS1), matchPSCS2(matchPSCS2), 
+         BPPMatrices(myBPPMatrices), posterior(myseqs1->GetSequence(0)->GetLength() + 1, myseqs2->GetSequence(0)->GetLength() + 1),
+         countConp1(WORDLENGTH, 17, mypscs1->size()+1), countConp2(WORDLENGTH, 17, mypscs2->size()+1),
+         countContConp1(0, 17, mypscs1->size()+1), countContConp2(0, 17, mypscs2->size()+1), 
+         multiDeltaScore(myMultiDeltaScore), multiDeltaStacking(myMultiDeltaStacking),
+         multiScore(myMultiScore), multiStacking(myMultiStacking), 
+         multiPenalty(myMultiPenalty) {
+       
+       VF::iterator myPosteriorPtr = myPosterior->begin();
+       for (int i = 0; i <= seqs1->GetSequence(0)->GetLength(); i++) {
+           for (int j = 0; j <= seqs2->GetSequence(0)->GetLength(); j++) {
+               posterior[i][j] = (*myPosteriorPtr)/(seqs1->GetSequence(0)->GetLength()*seqs2->GetSequence(0)->GetLength());
+               myPosteriorPtr++;
+           }
+       }
+    }
+
+
+                                                        
+    float Run();
+
+    void setMultiDeltaScore(float score) { multiDeltaScore = score; }
+    void setMultiDeltaStacking(float score) { multiDeltaStacking = score; }
+    void setMultiScore(float score) { multiScore = score; }
+    void setMultiStacking(float score) { multiStacking = score; }
+    void setMultiPenalty(float score) { multiPenalty = score; }
+};
+}
+#endif // __GLOBALDP_HPP__
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Main.cc b/binaries/src/mafft/extensions/mxscarna_src/Main.cc
new file mode 100644 (file)
index 0000000..75bc632
--- /dev/null
@@ -0,0 +1,1872 @@
+/////////////////////////////////////////////////////////////////
+// Main.cc
+//
+// Main routines for MXSCARNA program.
+/////////////////////////////////////////////////////////////////
+
+#include "scarna.hpp"
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include "Defaults.h"
+#include "ScoreType.h"
+#include "ProbabilisticModel.h"
+#include "EvolutionaryTree.h"
+#include "SparseMatrix.h"
+#include "BPPMatrix.hpp"
+#include "StemCandidate.hpp"
+#include "Globaldp.hpp"
+#include "nrutil.h"
+#include "AlifoldMEA.h"
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <set>
+#include <algorithm>
+#include <cstdio>
+#include <cstdlib>
+#include <cerrno>
+#include <iomanip>
+#include <fstream>
+
+//#include "RfoldWrapper.hpp"
+//static RFOLD::Rfold folder;
+
+using namespace::MXSCARNA;
+
+string parametersInputFilename = "";
+string parametersOutputFilename = "no training";
+string annotationFilename = "";
+string weboutputFileName = "";
+
+ofstream *outputFile;
+
+bool enableTraining = false;
+bool enableVerbose = false;
+bool enableAllPairs = false;
+bool enableAnnotation = false;
+bool enableViterbi = false;
+bool enableClustalWOutput = false;
+bool enableTrainEmissions = false;
+bool enableAlignOrder = false;
+bool enableWebOutput  = false;
+bool enableStockholmOutput = false;
+bool enableMXSCARNAOutput = false;
+bool enableMcCaskillMEAMode = false;
+char bppmode = 's'; // by katoh
+int numConsistencyReps = 2;
+int numPreTrainingReps = 0;
+int numIterativeRefinementReps = 100;
+int scsLength = SCSLENGTH;
+float cutoff = 0;
+float gapOpenPenalty = 0;
+float gapContinuePenalty = 0;
+float threshhold = 1.0;
+float BaseProbThreshold = BASEPROBTHRESHOLD;
+float BasePairConst = BASEPAIRCONST;
+int   BandWidth = BANDWIDTH;
+
+SafeVector<string> sequenceNames;
+
+VF initDistrib (NumMatrixTypes);
+VF gapOpen (2*NumInsertStates);
+VF gapExtend (2*NumInsertStates);
+VVF emitPairs (256, VF (256, 1e-10));
+VF emitSingle (256, 1e-5);
+
+string alphabet = alphabetDefault;
+
+string *ssCons = NULL;
+
+const int MIN_PRETRAINING_REPS = 0;
+const int MAX_PRETRAINING_REPS = 20;
+const int MIN_CONSISTENCY_REPS = 0;
+const int MAX_CONSISTENCY_REPS = 5;
+const int MIN_ITERATIVE_REFINEMENT_REPS = 0;
+const int MAX_ITERATIVE_REFINEMENT_REPS = 1000;
+
+/////////////////////////////////////////////////////////////////
+// Function prototypes
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading();
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const VVF &emitPairs, const VF &emitSingle, const char *filename);
+MultiSequence *DoAlign (MultiSequence *sequence, const ProbabilisticModel &model, VF &initDistrib, VF &gapOpen, VF &gapExtend, VVF &emitPairs, VF &emitSingle);
+SafeVector<string> ParseParams (int argc, char **argv);
+void ReadParameters ();
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model,
+                                     SafeVector<BPPMatrix*> &BPPMatrices);
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model, SafeVector<BPPMatrix*> &BPPMatrices, float identity);
+SafeVector<SafeVector<SparseMatrix *> > DoRelaxation (MultiSequence *sequences, 
+                                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior);
+void Relax1 (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior);
+void DoBasePairProbabilityRelaxation (MultiSequence *sequences, 
+                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                     SafeVector<BPPMatrix*> &BPPMatrices);
+set<int> GetSubtree (const TreeNode *tree);
+void TreeBasedBiPartitioning (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                              const ProbabilisticModel &model, MultiSequence* &alignment,
+                              const TreeNode *tree, SafeVector<BPPMatrix*> &BPPMatrices);
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment);
+void WriteAnnotation (MultiSequence *alignment,
+                     const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+int ComputeScore (const SafeVector<pair<int, int> > &active, 
+                 const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+std::vector<StemCandidate>* seq2scs(MultiSequence *Sequences, SafeVector<BPPMatrix*> &BPPMatrices, int BandWidth);
+void removeConflicts(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2, std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2);
+
+struct prob {
+    int i;
+    int j;
+    float p;
+};
+
+/////////////////////////////////////////////////////////////////
+// main()
+//
+// Calls all initialization routines and runs the MXSCARNA
+// aligner.
+/////////////////////////////////////////////////////////////////
+
+
+int main (int argc, char **argv){
+
+    // print MXSCARNA heading
+    PrintHeading();
+  
+    // parse program parameters
+    sequenceNames = ParseParams (argc, argv);
+    ReadParameters();
+    PrintParameters ("Using parameter set:", initDistrib, gapOpen, gapExtend, emitPairs, emitSingle, NULL);
+  
+  // now, we'll process all the files given as input.  If we are given
+  // several filenames as input, then we'll load all of those sequences
+  // simultaneously, as long as we're not training.  On the other hand,
+  // if we are training, then we'll treat each file as a separate
+  // training instance
+
+    if (enableMcCaskillMEAMode) {
+      MultiSequence *sequences = new MultiSequence(); assert (sequences);
+      for (int i = 0; i < (int) sequenceNames.size(); i++){
+         cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+         sequences->LoadMFA (sequenceNames[i], true);
+      }
+
+      const int numSeqs = sequences->GetNumSequences();
+      SafeVector<BPPMatrix*> BPPMatrices;
+
+      // compute the base pairing matrices for each sequences
+      for(int i = 0; i < numSeqs; i++) {
+         Sequence *tmpSeq = sequences->GetSequence(i);
+         string   seq = tmpSeq->GetString();
+         int    n_seq = tmpSeq->GetLength();
+         BPPMatrix *bppmat = new BPPMatrix(bppmode, seq, n_seq); // modified by katoh
+         BPPMatrices.push_back(bppmat);
+      }
+      if (bppmode=='w') exit( 0 );
+
+      AlifoldMEA alifold(sequences, BPPMatrices, BasePairConst);
+      alifold.Run();
+      ssCons = alifold.getSScons();
+
+      if (enableStockholmOutput) {
+         sequences->WriteSTOCKHOLM (cout, ssCons);
+      }
+      else if (enableMXSCARNAOutput){
+         sequences->WriteMXSCARNA (cout, ssCons);
+      }
+      else {
+         sequences->WriteMFA (cout, ssCons);
+      }
+
+      delete sequences;
+  }
+  // if we are training
+  else if (enableTraining){
+
+    // build new model for aligning
+    ProbabilisticModel model (initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+
+    // prepare to average parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] = 0;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] = 0;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] = 0;
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] = 0;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] = 0;
+    }
+   
+    // align each file individually
+    for (int i = 0; i < (int) sequenceNames.size(); i++){
+
+      VF thisInitDistrib (NumMatrixTypes);
+      VF thisGapOpen (2*NumInsertStates);
+      VF thisGapExtend (2*NumInsertStates);
+      VVF thisEmitPairs (256, VF (256, 1e-10));
+      VF thisEmitSingle (256, 1e-5);
+      
+      // load sequence file
+      MultiSequence *sequences = new MultiSequence(); assert (sequences);
+      cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+      sequences->LoadMFA (sequenceNames[i], true);
+
+      // align sequences
+      DoAlign (sequences, model, thisInitDistrib, thisGapOpen, thisGapExtend, thisEmitPairs, thisEmitSingle);
+
+      // add in contribution of the derived parameters
+      for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] += thisInitDistrib[i];
+      for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] += thisGapOpen[i];
+      for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] += thisGapExtend[i];
+      if (enableTrainEmissions){
+       for (int i = 0; i < (int) emitPairs.size(); i++) 
+         for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] += thisEmitPairs[i][j];
+       for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] += thisEmitSingle[i];
+      }
+
+      delete sequences;
+    }
+
+    // compute new parameters and print them out
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] /= (int) sequenceNames.size();
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] /= (int) sequenceNames.size();
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] /= (int) sequenceNames.size();
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++) 
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] /= (int) sequenceNames.size();
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] /= sequenceNames.size();
+    }
+    
+    PrintParameters ("Trained parameter set:",
+                     initDistrib, gapOpen, gapExtend, emitPairs, emitSingle,
+                     parametersOutputFilename.c_str());
+  }
+  // pass
+  // if we are not training, we must simply want to align some sequences
+  else {
+    // load all files together
+    MultiSequence *sequences = new MultiSequence(); assert (sequences);
+    for (int i = 0; i < (int) sequenceNames.size(); i++){
+      cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+
+      sequences->LoadMFA (sequenceNames[i], true);
+    }
+
+    // do all "pre-training" repetitions first
+    // NOT execute 
+    for (int ct = 0; ct < numPreTrainingReps; ct++){
+      enableTraining = true;
+
+      // build new model for aligning
+      ProbabilisticModel model (initDistrib, gapOpen, gapExtend, 
+                                emitPairs, emitSingle);
+
+      // do initial alignments
+      DoAlign (sequences, model, initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+
+      // print new parameters
+      PrintParameters ("Recomputed parameter set:", initDistrib, gapOpen, gapExtend, emitPairs, emitSingle, NULL);
+
+      enableTraining = false;
+    }
+
+    // now, we can perform the alignments and write them out
+    if (enableWebOutput) {
+       outputFile = new ofstream(weboutputFileName.c_str());
+       if (!outputFile) {
+           cerr << "cannot open output file." << weboutputFileName << endl;
+           exit(1);
+       }
+        *outputFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
+       *outputFile << "<result>" << endl;
+    }
+       MultiSequence *alignment = DoAlign (sequences,
+                                           ProbabilisticModel (initDistrib, gapOpen, gapExtend,  emitPairs, emitSingle),
+                                           initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+    
+
+    if (!enableAllPairs){
+       if (enableClustalWOutput) {
+           alignment->WriteALN (cout);
+       }
+       else if (enableWebOutput) {
+           alignment->WriteWEB (*outputFile, ssCons);
+//         computeStructureWithAlifold ();
+       }
+       else if (enableStockholmOutput) {
+           alignment->WriteSTOCKHOLM (cout, ssCons);
+       }
+       else if (enableMXSCARNAOutput) {
+           alignment->WriteMXSCARNA (cout, ssCons);
+       }
+       else {
+           alignment->WriteMFA (cout, ssCons);
+       }
+    }
+
+    if (enableWebOutput) {
+       *outputFile << "</result>" << endl;
+       delete outputFile;
+    }
+    
+    delete ssCons;
+    delete alignment;
+    delete sequences;
+   
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintHeading()
+//
+// Prints heading for PROBCONS program.
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading (){
+  cerr << endl
+       << "Multiplex SCARNA"<< endl
+       << "version " << VERSION << " - align multiple RNA sequences and print to standard output" << endl
+       << "Written by Yasuo Tabei" << endl
+       << endl;
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintParameters()
+//
+// Prints PROBCONS parameters to STDERR.  If a filename is
+// specified, then the parameters are also written to the file.
+/////////////////////////////////////////////////////////////////
+
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const VVF &emitPairs, const VF &emitSingle, const char *filename){
+
+  // print parameters to the screen
+  cerr << message << endl
+       << "    initDistrib[] = { ";
+  for (int i = 0; i < NumMatrixTypes; i++) cerr << setprecision (10) << initDistrib[i] << " ";
+  cerr << "}" << endl
+       << "        gapOpen[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapOpen[i] << " ";
+  cerr << "}" << endl
+       << "      gapExtend[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapExtend[i] << " ";
+  cerr << "}" << endl
+       << endl;
+
+  /*
+  for (int i = 0; i < 5; i++){
+    for (int j = 0; j <= i; j++){
+      cerr << emitPairs[(unsigned char) alphabet[i]][(unsigned char) alphabet[j]] << " ";
+    }
+    cerr << endl;
+    }*/
+
+  // if a file name is specified
+  if (filename){
+
+    // attempt to open the file for writing
+    FILE *file = fopen (filename, "w");
+    if (!file){
+      cerr << "ERROR: Unable to write parameter file: " << filename << endl;
+      exit (1);
+    }
+
+    // if successful, then write the parameters to the file
+    for (int i = 0; i < NumMatrixTypes; i++) fprintf (file, "%.10f ", initDistrib[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapOpen[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapExtend[i]); fprintf (file, "\n");
+    fprintf (file, "%s\n", alphabet.c_str());
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      for (int j = 0; j <= i; j++)
+       fprintf (file, "%.10f ", emitPairs[(unsigned char) alphabet[i]][(unsigned char) alphabet[j]]);
+      fprintf (file, "\n");
+    }
+    for (int i = 0; i < (int) alphabet.size(); i++)
+      fprintf (file, "%.10f ", emitSingle[(unsigned char) alphabet[i]]);
+    fprintf (file, "\n");
+    fclose (file);
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoAlign()
+//
+// First computes all pairwise posterior probability matrices.
+// Then, computes new parameters if training, or a final
+// alignment, otherwise.
+/////////////////////////////////////////////////////////////////
+MultiSequence *DoAlign (MultiSequence *sequences, const ProbabilisticModel &model, VF &initDistrib, VF &gapOpen, VF &gapExtend, VVF &emitPairs, VF &emitSingle){
+
+
+  assert (sequences);
+
+  const int numSeqs = sequences->GetNumSequences();
+  VVF distances (numSeqs, VF (numSeqs, 0));
+  VVF identities (numSeqs, VF (numSeqs, 0));
+  SafeVector<SafeVector<SparseMatrix *> > sparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+  
+  SafeVector<BPPMatrix*> BPPMatrices;
+  
+  for(int i = 0; i < numSeqs; i++) {
+    Sequence *tmpSeq = sequences->GetSequence(i);
+    string   seq = tmpSeq->GetString();
+    int    n_seq = tmpSeq->GetLength();
+    BPPMatrix *bppmat = new BPPMatrix(bppmode, seq, n_seq, BASEPROBTHRESHOLD); // modified by katoh
+    BPPMatrices.push_back(bppmat);
+  }
+    
+  if (enableTraining){
+    // prepare to average parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] = 0;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] = 0;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] = 0;
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] = 0;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] = 0;
+    }
+  }
+
+  // skip posterior calculations if we just want to do Viterbi alignments
+  if (!enableViterbi){
+
+    // do all pairwise alignments for posterior probability matrices
+    for (int a = 0; a < numSeqs-1; a++){
+      for (int b = a+1; b < numSeqs; b++){
+       Sequence *seq1 = sequences->GetSequence (a); 
+       Sequence *seq2 = sequences->GetSequence (b);
+       
+       // verbose output
+       if (enableVerbose)
+         cerr << "Computing posterior matrix: (" << a+1 << ") " << seq1->GetHeader() << " vs. "
+              << "(" << b+1 << ") " << seq2->GetHeader() << " -- ";
+       
+       // compute forward and backward probabilities
+       VF *forward = model.ComputeForwardMatrix (seq1, seq2); assert (forward);
+       VF *backward = model.ComputeBackwardMatrix (seq1, seq2); assert (backward);
+       
+       // if we are training, then we'll simply want to compute the
+       // expected counts for each region within the matrix separately;
+       // otherwise, we'll need to put all of the regions together and
+       // assemble a posterior probability match matrix
+       
+       // so, if we're training
+       if (enableTraining){
+         
+         // compute new parameters
+         VF thisInitDistrib (NumMatrixTypes);
+         VF thisGapOpen (2*NumInsertStates);
+         VF thisGapExtend (2*NumInsertStates);
+         VVF thisEmitPairs (256, VF (256, 1e-10));
+         VF thisEmitSingle (256, 1e-5);
+         
+         model.ComputeNewParameters (seq1, seq2, *forward, *backward, thisInitDistrib, thisGapOpen, thisGapExtend, thisEmitPairs, thisEmitSingle, enableTrainEmissions);
+
+         // add in contribution of the derived parameters
+         for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] += thisInitDistrib[i];
+         for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] += thisGapOpen[i];
+         for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] += thisGapExtend[i];
+         if (enableTrainEmissions){
+           for (int i = 0; i < (int) emitPairs.size(); i++) 
+             for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] += thisEmitPairs[i][j];
+           for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] += thisEmitSingle[i];
+         }
+
+         // let us know that we're done.
+         if (enableVerbose) cerr << "done." << endl;
+       }
+       // pass
+       else {
+
+         // compute posterior probability matrix
+         VF *posterior = model.ComputePosteriorMatrix (seq1, seq2, *forward, *backward); assert (posterior);
+
+         // compute sparse representations
+         sparseMatrices[a][b] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), *posterior);
+         sparseMatrices[b][a] = NULL; 
+         
+         if (!enableAllPairs){
+           // perform the pairwise sequence alignment
+           pair<SafeVector<char> *, float> alignment = model.ComputeAlignment (seq1->GetLength(),
+                                                                               seq2->GetLength(),
+                                                                               *posterior);
+           
+           Sequence *tmpSeq1 = seq1->AddGaps (alignment.first, 'X');
+           Sequence *tmpSeq2 = seq2->AddGaps (alignment.first, 'Y');
+
+           // compute sequence identity for each pair of sequenceses
+           int length = tmpSeq1->GetLength();
+           int matchCount = 0;
+           int misMatchCount = 0;
+           for (int k = 1; k <= length; k++) {
+               int ch1 = tmpSeq1->GetPosition(k);
+               int ch2 = tmpSeq2->GetPosition(k);
+               if (ch1 == ch2 && ch1 != '-' && ch2 != '-') { ++matchCount; }
+               else if (ch1 != ch2 && ch1 != '-' && ch2 != '-') { ++misMatchCount; }
+           }
+
+           identities[a][b] = identities[b][a] = (float)matchCount/(float)(matchCount + misMatchCount);
+
+           // compute "expected accuracy" distance for evolutionary tree computation
+           float distance = alignment.second / min (seq1->GetLength(), seq2->GetLength());
+           distances[a][b] = distances[b][a] = distance;
+           
+           if (enableVerbose)
+             cerr << setprecision (10) << distance << endl;
+           
+             delete alignment.first;
+         }
+         else {
+           // let us know that we're done.
+           if (enableVerbose) cerr << "done." << endl;
+         }
+         
+         delete posterior;
+       }
+       
+       delete forward;
+       delete backward;
+      }
+    }
+  }
+
+
+  // now average out parameters derived
+  if (enableTraining){
+    // compute new parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] /= numSeqs * (numSeqs - 1) / 2;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] /= numSeqs * (numSeqs - 1) / 2;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] /= numSeqs * (numSeqs - 1) / 2;
+
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] /= numSeqs * (numSeqs - 1) / 2;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] /= numSeqs * (numSeqs - 1) / 2;
+    }
+  }
+
+  // see if we still want to do some alignments
+  else {
+      // pass
+    if (!enableViterbi){
+
+      // perform the consistency transformation the desired number of times
+      for (int r = 0; r < numConsistencyReps; r++){
+       SafeVector<SafeVector<SparseMatrix *> > newSparseMatrices = DoRelaxation (sequences, sparseMatrices);
+
+       // now replace the old posterior matrices
+       for (int i = 0; i < numSeqs; i++){
+         for (int j = 0; j < numSeqs; j++){
+           delete sparseMatrices[i][j];
+           sparseMatrices[i][j] = newSparseMatrices[i][j];
+         }
+       }
+      }
+      //if (numSeqs > 8) {
+      //  for (int r = 0; r < 1; r++) 
+      //  DoBasePairProbabilityRelaxation(sequences, sparseMatrices, BPPMatrices);
+      //}
+    }
+
+    MultiSequence *finalAlignment = NULL;
+
+    if (enableAllPairs){
+      for (int a = 0; a < numSeqs-1; a++){
+       for (int b = a+1; b < numSeqs; b++){
+         Sequence *seq1 = sequences->GetSequence (a);
+         Sequence *seq2 = sequences->GetSequence (b);
+         
+         if (enableVerbose)
+           cerr << "Performing pairwise alignment: (" << a+1 << ") " << seq1->GetHeader() << " vs. "
+                << "(" << b+1 << ") " << seq2->GetHeader() << " -- ";
+
+         
+         // perform the pairwise sequence alignment
+         pair<SafeVector<char> *, float> alignment;
+         if (enableViterbi)
+           alignment = model.ComputeViterbiAlignment (seq1, seq2);
+         else {
+
+           // build posterior matrix
+           VF *posterior = sparseMatrices[a][b]->GetPosterior(); assert (posterior);
+           int length = (seq1->GetLength() + 1) * (seq2->GetLength() + 1);
+           for (int i = 0; i < length; i++) (*posterior)[i] -= cutoff;
+
+           alignment = model.ComputeAlignment (seq1->GetLength(), seq2->GetLength(), *posterior);
+           delete posterior;
+         }
+
+
+         // write pairwise alignments 
+         string name = seq1->GetHeader() + "-" + seq2->GetHeader() + (enableClustalWOutput ? ".aln" : ".fasta");
+         ofstream outfile (name.c_str());
+         
+         MultiSequence *result = new MultiSequence();
+         result->AddSequence (seq1->AddGaps(alignment.first, 'X'));
+         result->AddSequence (seq2->AddGaps(alignment.first, 'Y'));
+         result->WriteMFAseq (outfile); // by katoh
+         
+         outfile.close();
+         
+         delete alignment.first;
+       }
+      }
+       exit( 0 );
+    }
+    
+    // now if we still need to do a final multiple alignment
+    else {
+      
+      if (enableVerbose)
+       cerr << endl;
+      
+      // compute the evolutionary tree
+      TreeNode *tree = TreeNode::ComputeTree (distances, identities);
+      
+      if (enableWebOutput) {
+         *outputFile << "<tree>" << endl;
+         tree->Print (*outputFile, sequences);
+         *outputFile << "</tree>" << endl;
+      }
+      else {
+         tree->Print (cerr, sequences);
+         cerr << endl;
+      }
+      // make the final alignment
+      finalAlignment = ComputeFinalAlignment (tree, sequences, sparseMatrices, model, BPPMatrices);
+      
+      // build annotation
+      if (enableAnnotation){
+       WriteAnnotation (finalAlignment, sparseMatrices);
+      }
+
+      delete tree;
+    }
+
+    if (!enableViterbi){
+      // delete sparse matrices
+      for (int a = 0; a < numSeqs-1; a++){
+       for (int b = a+1; b < numSeqs; b++){
+         delete sparseMatrices[a][b];
+         delete sparseMatrices[b][a];
+       }
+      }
+    }
+
+    //AlifoldMEA alifold(finalAlignment, BPPMatrices, BasePairConst);
+    //alifold.Run();
+    //ssCons = alifold.getSScons();
+
+    return finalAlignment;
+
+  }
+
+  return NULL;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetInteger()
+//
+// Attempts to parse an integer from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetInteger (char *data, int *val){
+  char *endPtr;
+  long int retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtol (data, &endPtr, 0);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal == LONG_MAX || retVal == LONG_MIN)) return false;
+  if (retVal < (long) INT_MIN || retVal > (long) INT_MAX) return false;
+  *val = (int) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetFloat()
+//
+// Attempts to parse a float from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetFloat (char *data, float *val){
+  char *endPtr;
+  double retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtod (data, &endPtr);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal >= 1000000.0 || retVal <= -1000000.0)) return false;
+  *val = (float) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// ParseParams()
+//
+// Parse all command-line options.
+/////////////////////////////////////////////////////////////////
+
+SafeVector<string> ParseParams (int argc, char **argv){
+
+  if (argc < 2){
+
+    cerr << "MXSCARNA comes with ABSOLUTELY NO WARRANTY.  This is free software, and" << endl
+         << "you are welcome to redistribute it under certain conditions.  See the" << endl
+         << "file COPYING.txt for details." << endl
+         << endl
+         << "Usage:" << endl
+         << "       mxscarna [OPTION]... [MFAFILE]..." << endl
+         << endl
+         << "Description:" << endl
+         << "       Align sequences in MFAFILE(s) and print result to standard output" << endl
+         << endl
+         << "       -clustalw" << endl
+         << "              use CLUSTALW output format instead of MFA" << endl
+        << endl
+        << "       -stockholm" << endl
+         << "              use STOCKHOLM output format instead of MFA" << endl
+        << endl
+        << "       -mxscarna" << endl
+         << "              use MXSCARNA output format instead of MFA" << endl
+        << endl
+        << "       -weboutput /<output_path>/<outputfilename>" << endl
+        << "        use web output format" << endl
+        << endl
+         << "       -c, --consistency REPS" << endl
+         << "              use " << MIN_CONSISTENCY_REPS << " <= REPS <= " << MAX_CONSISTENCY_REPS
+         << " (default: " << numConsistencyReps << ") passes of consistency transformation" << endl
+         << endl
+         << "       -ir, --iterative-refinement REPS" << endl
+         << "              use " << MIN_ITERATIVE_REFINEMENT_REPS << " <= REPS <= " << MAX_ITERATIVE_REFINEMENT_REPS
+         << " (default: " << numIterativeRefinementReps << ") passes of iterative-refinement" << endl
+         << endl
+        << "       -pre, --pre-training REPS" << endl
+        << "              use " << MIN_PRETRAINING_REPS << " <= REPS <= " << MAX_PRETRAINING_REPS
+        << " (default: " << numPreTrainingReps << ") rounds of pretraining" << endl
+        << endl
+        << "       -pairs" << endl
+         << "              generate all-pairs pairwise alignments" << endl
+         << endl
+        << "       -viterbi" << endl
+        << "              use Viterbi algorithm to generate all pairs (automatically enables -pairs)" << endl
+        << endl
+         << "       -v, --verbose" << endl
+         << "              report progress while aligning (default: " << (enableVerbose ? "on" : "off") << ")" << endl
+         << endl
+         << "       -annot FILENAME" << endl
+         << "              write annotation for multiple alignment to FILENAME" << endl
+         << endl
+         << "       -t, --train FILENAME" << endl
+         << "              compute EM transition probabilities, store in FILENAME (default: "
+         << parametersOutputFilename << ")" << endl
+         << endl
+         << "       -e, --emissions" << endl
+         << "              also reestimate emission probabilities (default: "
+         << (enableTrainEmissions ? "on" : "off") << ")" << endl
+         << endl
+        << "       -p, --paramfile FILENAME" << endl
+        << "              read parameters from FILENAME (default: "
+        << parametersInputFilename << ")" << endl
+        << endl
+        << "       -a, --alignment-order" << endl
+        << "              print sequences in alignment order rather than input order (default: "
+        << (enableAlignOrder ? "on" : "off") << ")" << endl
+        << endl
+        << "       -s THRESHOLD" << endl
+        << "               the threshold of SCS alignment" << endl
+        << endl
+        << "               In default, for less than " << threshhold << ", the SCS aligment is applied. " << endl
+        << "       -l SCSLENGTH" << endl
+        << "               the length of stem candidates " << SCSLENGTH << endl
+        << endl
+        << "       -b BASEPROBTRHESHHOLD" << endl
+        << "               the threshold of base pairing probability " << BASEPROBTHRESHOLD << endl
+        << endl
+        << "       -m, --mccaskillmea" << endl
+        << "               McCaskill MEA MODE: input the clustalw format file and output the secondary structure predicted by McCaskill MEA" << endl
+        << endl
+        << "       -g BASEPAIRSCORECONST" << endl
+        << "               the control parameter of the prediction of base pairs, default:" << BasePairConst << endl
+         << endl
+        << "       -w BANDWIDTH" << endl
+        << "               the control parameter of the distance of stem candidates, default:" << BANDWIDTH << endl
+        << endl; 
+
+
+    //          << "       -go, --gap-open VALUE" << endl
+    //          << "              gap opening penalty of VALUE <= 0 (default: " << gapOpenPenalty << ")" << endl
+    //  << endl
+    //  << "       -ge, --gap-extension VALUE" << endl
+    //  << "              gap extension penalty of VALUE <= 0 (default: " << gapContinuePenalty << ")" << endl
+    //  << endl
+    //         << "       -co, --cutoff CUTOFF" << endl
+    //         << "              subtract 0 <= CUTOFF <= 1 (default: " << cutoff << ") from all posterior values before final alignment" << endl
+    //         << endl
+    
+    exit (1);
+  }
+
+  SafeVector<string> sequenceNames;
+  int tempInt;
+  float tempFloat;
+
+  for (int i = 1; i < argc; i++){
+    if (argv[i][0] == '-'){
+
+      // training
+      if (!strcmp (argv[i], "-t") || !strcmp (argv[i], "--train")){
+        enableTraining = true;
+        if (i < argc - 1)
+          parametersOutputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      
+      // emission training
+      else if (!strcmp (argv[i], "-e") || !strcmp (argv[i], "--emissions")){
+        enableTrainEmissions = true;
+      }
+
+      // parameter file
+      else if (!strcmp (argv[i], "-p") || !strcmp (argv[i], "--paramfile")){
+        if (i < argc - 1)
+          parametersInputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      else if (! strcmp (argv[i], "-s")) {
+       if (i < argc - 1){
+         if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat < 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+              exit (1);
+            }
+            else
+              threshhold = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      
+      else if (! strcmp (argv[i], "-l")) {
+         if (i < argc - 1) {
+             if (!GetInteger (argv[++i], &tempInt)){
+                 cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempInt <= 0 || 6 <= tempInt) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                          << "1 and 6" << "." << endl;
+                     exit (1);
+                 }
+                 else
+                     scsLength = tempInt;
+             }
+         }
+      }
+      else if (! strcmp (argv[i], "-b")) {
+         if (i < argc - 1) {
+             if (!GetFloat (argv[++i], &tempFloat)){
+                 cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempFloat < 0 && 1 < tempFloat) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+                     exit (1);
+                 }
+                 else
+                     BaseProbThreshold = tempFloat;
+             }
+         }
+      }
+      else if (! strcmp (argv[i], "-g")) {
+         if (i < argc - 1) {
+             if (!GetFloat (argv[++i], &tempFloat)){
+                 cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempFloat < 0 && 1 < tempFloat) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+                     exit (1);
+                 }
+                 else
+                     BasePairConst = tempFloat;
+             }
+         }
+      }
+      
+      // number of consistency transformations
+      else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--consistency")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_CONSISTENCY_REPS || tempInt > MAX_CONSISTENCY_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_CONSISTENCY_REPS << " and " << MAX_CONSISTENCY_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numConsistencyReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // number of randomized partitioning iterative refinement passes
+      else if (!strcmp (argv[i], "-ir") || !strcmp (argv[i], "--iterative-refinement")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_ITERATIVE_REFINEMENT_REPS || tempInt > MAX_ITERATIVE_REFINEMENT_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_ITERATIVE_REFINEMENT_REPS << " and " << MAX_ITERATIVE_REFINEMENT_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numIterativeRefinementReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      // number of EM pre-training rounds
+      else if (!strcmp (argv[i], "-pre") || !strcmp (argv[i], "--pre-training")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_PRETRAINING_REPS || tempInt > MAX_PRETRAINING_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_PRETRAINING_REPS << " and " << MAX_PRETRAINING_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numPreTrainingReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // the distance of stem candidate
+      else if (!strcmp (argv[i], "-w")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+              BandWidth = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap open penalty
+      else if (!strcmp (argv[i], "-go") || !strcmp (argv[i], "--gap-open")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapOpenPenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap extension penalty
+      else if (!strcmp (argv[i], "-ge") || !strcmp (argv[i], "--gap-extension")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapContinuePenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // all-pairs pairwise alignments
+      else if (!strcmp (argv[i], "-pairs")){
+        enableAllPairs = true;
+      }
+
+      // all-pairs pairwise Viterbi alignments
+      else if (!strcmp (argv[i], "-viterbi")){
+        enableAllPairs = true;
+       enableViterbi = true;
+      }
+
+      // read base-pairing probability from the '_bpp' file, by katoh
+      else if (!strcmp (argv[i], "-readbpp")){
+        bppmode = 'r';
+      }
+
+      // write base-pairing probability to stdout, by katoh
+      else if (!strcmp (argv[i], "-writebpp")){
+        bppmode = 'w';
+      }
+
+      // annotation files
+      else if (!strcmp (argv[i], "-annot")){
+        enableAnnotation = true;
+        if (i < argc - 1)
+         annotationFilename = argv[++i];
+        else {
+          cerr << "ERROR: FILENAME expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // clustalw output format
+      else if (!strcmp (argv[i], "-clustalw")){
+       enableClustalWOutput = true;
+      }
+      // mxscarna output format
+      else if (!strcmp (argv[i], "-mxscarna")) {
+         enableMXSCARNAOutput = true;
+      }
+      // stockholm output format
+      else if (!strcmp (argv[i], "-stockholm")) {
+         enableStockholmOutput = true;
+      }
+      // web output format
+      else if (!strcmp (argv[i], "-weboutput")) {
+         if (i < argc - 1) {
+             weboutputFileName = string(argv[++i]);
+         }
+         else {
+             cerr << "ERROR: Invalid following option " << argv[i-1] << ": " << argv[i] << endl;
+             exit (1);
+         }
+
+         enableWebOutput = true;
+      }
+
+      // cutoff
+      else if (!strcmp (argv[i], "-co") || !strcmp (argv[i], "--cutoff")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat < 0 || tempFloat > 1){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must be between 0 and 1." << endl;
+              exit (1);
+            }
+            else
+              cutoff = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // verbose reporting
+      else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--verbose")){
+        enableVerbose = true;
+      }
+
+      // alignment order
+      else if (!strcmp (argv[i], "-a") || !strcmp (argv[i], "--alignment-order")){
+       enableAlignOrder = true;
+      }
+      // McCaskill MEA MODE
+      else if (!strcmp (argv[i], "-m") || !strcmp (argv[i], "--mccaskillmea")){
+        enableMcCaskillMEAMode = true;
+      }
+      // bad arguments
+      else {
+        cerr << "ERROR: Unrecognized option: " << argv[i] << endl;
+        exit (1);
+      }
+    }
+    else {
+      sequenceNames.push_back (string (argv[i]));
+    }
+  }
+
+  if (enableTrainEmissions && !enableTraining){
+    cerr << "ERROR: Training emissions (-e) requires training (-t)" << endl;
+    exit (1);
+  }
+
+  return sequenceNames;
+}
+
+/////////////////////////////////////////////////////////////////
+// ReadParameters()
+//
+// Read initial distribution, transition, and emission
+// parameters from a file.
+/////////////////////////////////////////////////////////////////
+
+void ReadParameters (){
+
+  ifstream data;
+
+  emitPairs = VVF (256, VF (256, 1e-10));
+  emitSingle = VF (256, 1e-5);
+
+  // read initial state distribution and transition parameters
+  // pass
+  if (parametersInputFilename == string ("")){
+    if (NumInsertStates == 1){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend1Default[i];
+    }
+    else if (NumInsertStates == 2){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend2Default[i];
+    }
+    else {
+      cerr << "ERROR: No default initial distribution/parameter settings exist" << endl
+           << "       for " << NumInsertStates << " pairs of insert states.  Use --paramfile." << endl;
+      exit (1);
+    }
+
+    alphabet = alphabetDefault;
+
+    for (int i = 0; i < (int) alphabet.length(); i++){
+      emitSingle[(unsigned char) tolower(alphabet[i])] = emitSingleDefault[i];
+      emitSingle[(unsigned char) toupper(alphabet[i])] = emitSingleDefault[i];
+      for (int j = 0; j <= i; j++){
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) tolower(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) toupper(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) tolower(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) toupper(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) tolower(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) toupper(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) tolower(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) toupper(alphabet[i])] = emitPairsDefault[i][j];
+      }
+    }
+  }
+  else {
+    data.open (parametersInputFilename.c_str());
+    if (data.fail()){
+      cerr << "ERROR: Unable to read parameter file: " << parametersInputFilename << endl;
+      exit (1);
+    }
+    
+    string line[3];
+    for (int i = 0; i < 3; i++){
+      if (!getline (data, line[i])){
+       cerr << "ERROR: Unable to read transition parameters from parameter file: " << parametersInputFilename << endl;
+       exit (1);
+      }
+    }
+    istringstream data2;
+    data2.clear(); data2.str (line[0]); for (int i = 0; i < NumMatrixTypes; i++) data2 >> initDistrib[i];
+    data2.clear(); data2.str (line[1]); for (int i = 0; i < 2*NumInsertStates; i++) data2 >> gapOpen[i];
+    data2.clear(); data2.str (line[2]); for (int i = 0; i < 2*NumInsertStates; i++) data2 >> gapExtend[i];
+
+    if (!getline (data, line[0])){
+      cerr << "ERROR: Unable to read alphabet from scoring matrix file: " << parametersInputFilename << endl;
+      exit (1);
+    }
+    
+    // read alphabet as concatenation of all characters on alphabet line
+    alphabet = "";
+    string token;
+    data2.clear(); data2.str (line[0]); while (data2 >> token) alphabet += token;
+
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      for (int j = 0; j <= i; j++){
+       float val;
+        data >> val;
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) tolower(alphabet[j])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) toupper(alphabet[j])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) tolower(alphabet[j])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) toupper(alphabet[j])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) tolower(alphabet[i])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) toupper(alphabet[i])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) tolower(alphabet[i])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) toupper(alphabet[i])] = val;
+      }
+    }
+
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      float val;
+      data >> val;
+      emitSingle[(unsigned char) tolower(alphabet[i])] = val;
+      emitSingle[(unsigned char) toupper(alphabet[i])] = val;
+    }
+    data.close();
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// ProcessTree()
+//
+// Process the tree recursively.  Returns the aligned sequences
+// corresponding to a node or leaf of the tree.
+/////////////////////////////////////////////////////////////////
+float ide;
+MultiSequence *ProcessTree (const TreeNode *tree, MultiSequence *sequences,
+                            const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, SafeVector<BPPMatrix*> &BPPMatrices) {
+  MultiSequence *result;
+
+  // check if this is a node of the alignment tree
+  if (tree->GetSequenceLabel() == -1){
+    MultiSequence *alignLeft = ProcessTree (tree->GetLeftChild(), sequences, sparseMatrices, model, BPPMatrices);
+    MultiSequence *alignRight = ProcessTree (tree->GetRightChild(), sequences, sparseMatrices, model, BPPMatrices);
+
+    assert (alignLeft);
+    assert (alignRight);
+    
+    result = AlignAlignments (alignLeft, alignRight, sparseMatrices, model, BPPMatrices, tree->GetIdentity());
+    assert (result);
+
+    delete alignLeft;
+    delete alignRight;
+  }
+
+  // otherwise, this is a leaf of the alignment tree
+  else {
+    result = new MultiSequence(); assert (result);
+    result->AddSequence (sequences->GetSequence(tree->GetSequenceLabel())->Clone());
+  }
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeFinalAlignment()
+//
+// Compute the final alignment by calling ProcessTree(), then
+// performing iterative refinement as needed.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model, 
+                                     SafeVector<BPPMatrix*> &BPPMatrices) { 
+
+  MultiSequence *alignment = ProcessTree (tree, sequences, sparseMatrices, model, BPPMatrices);
+
+  if (enableAlignOrder){
+    alignment->SaveOrdering();
+    enableAlignOrder = false;
+  }
+
+  // tree-based refinement 
+  // if you use the function, you can degrade the quality of the software.
+  // TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree, BPPMatrices);
+
+  // iterative refinement
+/*
+  for (int i = 0; i < numIterativeRefinementReps; i++)
+      DoIterativeRefinement (sparseMatrices, model, alignment);
+
+      cerr << endl;
+*/
+  // return final alignment
+  return alignment;
+}
+
+/////////////////////////////////////////////////////////////////
+// AlignAlignments()
+//
+// Returns the alignment of two MultiSequence objects.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model, 
+                               SafeVector<BPPMatrix*> &BPPMatrices, float identity){
+
+  // print some info about the alignment
+  if (enableVerbose){
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align1->GetSequence(i)->GetLabel();
+    cerr << "] vs. ";
+    for (int i = 0; i < align2->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align2->GetSequence(i)->GetLabel();
+    cerr << "]: ";
+  }
+
+  VF *posterior = model.BuildPosterior (align1, align2, sparseMatrices, cutoff);
+
+  pair<SafeVector<char> *, float> alignment;
+  // choose the alignment routine depending on the "cosmetic" gap penalties used
+  if (gapOpenPenalty == 0 && gapContinuePenalty == 0) {
+
+    if(identity <= threshhold) {
+       std::vector<StemCandidate> *pscs1, *pscs2;
+       pscs1 = seq2scs(align1, BPPMatrices, BandWidth);
+       pscs2 = seq2scs(align2, BPPMatrices, BandWidth);
+       std::vector<int> *matchPSCS1 = new std::vector<int>;
+       std::vector<int> *matchPSCS2 = new std::vector<int>;
+
+       Globaldp globaldp(pscs1, pscs2, align1, align2, matchPSCS1, matchPSCS2, posterior, BPPMatrices);
+       //float scsScore = globaldp.Run();
+
+       globaldp.Run();
+
+       removeConflicts(pscs1, pscs2, matchPSCS1, matchPSCS2);
+
+       alignment = model.ComputeAlignment2 (align1->GetSequence(0)->GetLength(), align2->GetSequence(0)->GetLength(), *posterior, pscs1, pscs2, matchPSCS1, matchPSCS2);
+       delete matchPSCS1;
+       delete matchPSCS2;
+    } else {
+       alignment = model.ComputeAlignment (align1->GetSequence(0)->GetLength(), align2->GetSequence(0)->GetLength(), *posterior);
+    }
+  }
+  else {
+    alignment = model.ComputeAlignmentWithGapPenalties (align1, align2,
+                                                        *posterior, align1->GetNumSequences(), align2->GetNumSequences(),
+                                                        gapOpenPenalty, gapContinuePenalty);
+  }
+
+  delete posterior;
+
+  if (enableVerbose){
+
+    // compute total length of sequences
+    int totLength = 0;
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      for (int j = 0; j < align2->GetNumSequences(); j++)
+        totLength += min (align1->GetSequence(i)->GetLength(), align2->GetSequence(j)->GetLength());
+
+    // give an "accuracy" measure for the alignment
+    cerr << alignment.second / totLength << endl;
+  }
+
+  // now build final alignment
+  MultiSequence *result = new MultiSequence();
+  for (int i = 0; i < align1->GetNumSequences(); i++)
+    result->AddSequence (align1->GetSequence(i)->AddGaps(alignment.first, 'X'));
+  for (int i = 0; i < align2->GetNumSequences(); i++)
+    result->AddSequence (align2->GetSequence(i)->AddGaps(alignment.first, 'Y'));
+  if (!enableAlignOrder)
+    result->SortByLabel();
+
+  // free temporary alignment
+  delete alignment.first;
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// DoRelaxation()
+//
+// Performs one round of the consistency transformation.  The
+// formula used is:
+//                     1
+//    P'(x[i]-y[j]) = ---  sum   sum P(x[i]-z[k]) P(z[k]-y[j])
+//                    |S| z in S  k
+//
+// where S = {x, y, all other sequences...}
+//
+/////////////////////////////////////////////////////////////////
+
+SafeVector<SafeVector<SparseMatrix *> > DoRelaxation (MultiSequence *sequences, 
+                                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+  const int numSeqs = sequences->GetNumSequences();
+
+  SafeVector<SafeVector<SparseMatrix *> > newSparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+
+  // for every pair of sequences
+  for (int i = 0; i < numSeqs; i++){
+    for (int j = i+1; j < numSeqs; j++){
+      Sequence *seq1 = sequences->GetSequence (i);
+      Sequence *seq2 = sequences->GetSequence (j);
+      
+      if (enableVerbose)
+        cerr << "Relaxing (" << i+1 << ") " << seq1->GetHeader() << " vs. "
+             << "(" << j+1 << ") " << seq2->GetHeader() << ": ";
+
+      // get the original posterior matrix
+      VF *posteriorPtr = sparseMatrices[i][j]->GetPosterior(); assert (posteriorPtr);
+      VF &posterior = *posteriorPtr;
+
+      const int seq1Length = seq1->GetLength();
+      const int seq2Length = seq2->GetLength();
+
+      // contribution from the summation where z = x and z = y
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] += posterior[k];
+
+      if (enableVerbose)
+        cerr << sparseMatrices[i][j]->GetNumCells() << " --> ";
+
+      // contribution from all other sequences
+      for (int k = 0; k < numSeqs; k++) if (k != i && k != j){
+       if (k < i)
+         Relax1 (sparseMatrices[k][i], sparseMatrices[k][j], posterior);
+       else if (k > i && k < j)
+         Relax (sparseMatrices[i][k], sparseMatrices[k][j], posterior);
+       else {
+         SparseMatrix *temp = sparseMatrices[j][k]->ComputeTranspose();
+         Relax (sparseMatrices[i][k], temp, posterior);
+         delete temp;
+       }
+      }
+
+      // now renormalization
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] /= numSeqs;
+
+      // mask out positions not originally in the posterior matrix
+      SparseMatrix *matXY = sparseMatrices[i][j];
+      for (int y = 0; y <= seq2Length; y++) posterior[y] = 0;
+      for (int x = 1; x <= seq1Length; x++){
+       SafeVector<PIF>::iterator XYptr = matXY->GetRowPtr(x);
+       SafeVector<PIF>::iterator XYend = XYptr + matXY->GetRowSize(x);
+       VF::iterator base = posterior.begin() + x * (seq2Length + 1);
+       int curr = 0;
+       while (XYptr != XYend){
+
+         // zero out all cells until the first filled column
+         while (curr < XYptr->first){
+           base[curr] = 0;
+           curr++;
+         }
+
+         // now, skip over this column
+         curr++;
+         ++XYptr;
+       }
+       
+       // zero out cells after last column
+       while (curr <= seq2Length){
+         base[curr] = 0;
+         curr++;
+       }
+      }
+
+      // save the new posterior matrix
+      newSparseMatrices[i][j] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), posterior);
+      newSparseMatrices[j][i] = NULL;
+
+      if (enableVerbose)
+        cerr << newSparseMatrices[i][j]->GetNumCells() << " -- ";
+
+      delete posteriorPtr;
+
+      if (enableVerbose)
+        cerr << "done." << endl;
+    }
+  }
+  
+  return newSparseMatrices;
+}
+
+/////////////////////////////////////////////////////////////////
+// Relax()
+//
+// Computes the consistency transformation for a single sequence
+// z, and adds the transformed matrix to "posterior".
+/////////////////////////////////////////////////////////////////
+
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior){
+
+  assert (matXZ);
+  assert (matZY);
+
+  int lengthX = matXZ->GetSeq1Length();
+  int lengthY = matZY->GetSeq2Length();
+  assert (matXZ->GetSeq2Length() == matZY->GetSeq1Length());
+
+  // for every x[i]
+  for (int i = 1; i <= lengthX; i++){
+    SafeVector<PIF>::iterator XZptr = matXZ->GetRowPtr(i);
+    SafeVector<PIF>::iterator XZend = XZptr + matXZ->GetRowSize(i);
+
+    VF::iterator base = posterior.begin() + i * (lengthY + 1);
+
+    // iterate through all x[i]-z[k]
+    while (XZptr != XZend){
+      SafeVector<PIF>::iterator ZYptr = matZY->GetRowPtr(XZptr->first);
+      SafeVector<PIF>::iterator ZYend = ZYptr + matZY->GetRowSize(XZptr->first);
+      const float XZval = XZptr->second;
+
+      // iterate through all z[k]-y[j]
+      while (ZYptr != ZYend){
+        base[ZYptr->first] += XZval * ZYptr->second;
+       ZYptr++;
+      }
+      XZptr++;
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// Relax1()
+//
+// Computes the consistency transformation for a single sequence
+// z, and adds the transformed matrix to "posterior".
+/////////////////////////////////////////////////////////////////
+
+void Relax1 (SparseMatrix *matZX, SparseMatrix *matZY, VF &posterior){
+
+  assert (matZX);
+  assert (matZY);
+
+  int lengthZ = matZX->GetSeq1Length();
+  int lengthY = matZY->GetSeq2Length();
+
+  // for every z[k]
+  for (int k = 1; k <= lengthZ; k++){
+    SafeVector<PIF>::iterator ZXptr = matZX->GetRowPtr(k);
+    SafeVector<PIF>::iterator ZXend = ZXptr + matZX->GetRowSize(k);
+
+    // iterate through all z[k]-x[i]
+    while (ZXptr != ZXend){
+      SafeVector<PIF>::iterator ZYptr = matZY->GetRowPtr(k);
+      SafeVector<PIF>::iterator ZYend = ZYptr + matZY->GetRowSize(k);
+      const float ZXval = ZXptr->second;
+      VF::iterator base = posterior.begin() + ZXptr->first * (lengthY + 1);
+
+      // iterate through all z[k]-y[j]
+      while (ZYptr != ZYend){
+        base[ZYptr->first] += ZXval * ZYptr->second;
+        ZYptr++;
+      }
+      ZXptr++;
+    }
+  }
+}
+
+void DoBasePairProbabilityRelaxation (MultiSequence *sequences, 
+                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                     SafeVector<BPPMatrix*> &BPPMatrices) {
+    const int numSeqs = sequences->GetNumSequences();
+
+    for (int i = 0; i < numSeqs; i++) {
+       Sequence *seq1 = sequences->GetSequence (i);
+       BPPMatrix *seq1BppMatrix = BPPMatrices[seq1->GetLabel()];
+       Trimat<float> consBppMat(seq1->GetLength() + 1);
+       int seq1Length = seq1->GetLength();
+
+       for (int k = 1; k <= seq1Length; k++) {
+           for (int l = k; l <= seq1Length; l++) {
+               consBppMat.ref(k, l) = seq1BppMatrix->GetProb(k, l);
+           }
+       }
+
+       for (int j = i + 1; j < numSeqs; j++) {
+
+   //          VF *posteriorPtr = sparseMatrices[i][j]->GetPosterior()
+         Sequence *seq2 = sequences->GetSequence (j);
+         BPPMatrix *seq2BppMatrix = BPPMatrices[seq2->GetLabel()];
+//       int seq2Length = seq2->GetLength();
+         SparseMatrix *matchProb = sparseMatrices[i][j];
+
+//       vector<PIF2> &probs1 = seq1BppMatrix->bppMat.data2;
+         for(int k = 1; k <= seq1Length; k++) {
+             for(int m = k, n = k; n <= k + 200 && m >= 1 && n <= seq1Length; m--, n++) {
+                 
+//       for (int k = 0; k < (int)probs1.size(); k++) {
+//           float tmpProb1 = probs1[k].prob;
+//           int   tmp1I    = probs1[k].i;
+//           int   tmp1J    = probs1[k].j;
+
+                 float sumProb = 0;
+                 vector<PIF2> &probs2 = seq2BppMatrix->bppMat.data2;
+                 for(int l = 0; l < (int)probs2.size(); l++) {
+                     float tmpProb2 = probs2[l].prob;
+                     int   tmp2I    = probs2[l].i;
+                     int   tmp2J    = probs2[l].j;
+                     sumProb += matchProb->GetValue(m, tmp2I)*matchProb->GetValue(n, tmp2J)*tmpProb2;
+                 }
+
+                 consBppMat.ref(m, n) += sumProb;
+             }
+
+             for(int m = k, n = k + 1; n <= k + 200 && m >= 1 && n <= seq1Length; m--, n++) {
+                 
+//       for (int k = 0; k < (int)probs1.size(); k++) {
+//           float tmpProb1 = probs1[k].prob;
+//           int   tmp1I    = probs1[k].i;
+//           int   tmp1J    = probs1[k].j;
+
+                 float sumProb = 0;
+                 vector<PIF2> &probs2 = seq2BppMatrix->bppMat.data2;
+                 for(int l = 0; l < (int)probs2.size(); l++) {
+                     float tmpProb2 = probs2[l].prob;
+                     int   tmp2I    = probs2[l].i;
+                     int   tmp2J    = probs2[l].j;
+                     sumProb += matchProb->GetValue(m, tmp2I)*matchProb->GetValue(n, tmp2J)*tmpProb2;
+                 }
+
+                 consBppMat.ref(m, n) += sumProb;
+             }
+         }
+       }
+
+/*
+         for(int k = 1; k <= seq1Length; k++) {
+             for(int m = k, n = k; n <= k + 30 && m >= 1 && n <= seq1Length; m--, n++) {
+                 float tmpProb = seq1BppMatrix->GetProb(m, n);
+                 for(int l = 1; l <= seq2Length; l++) {
+                     for(int s = l, t = l; t <= l + 30 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                     for(int s = l, t = l + 1; t <= l + 31 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                 }
+                 consBppMat.ref(m, n) += tmpProb;
+             }
+    
+             for(int m = k, n = k + 1; n <= k + 31 && m >= 1 && n <= seq1Length; m--, n++) {
+                 float tmpProb = seq1BppMatrix->GetProb(m, n);
+                 for(int l = 1; l <= seq2Length; l++) {
+                     for(int s = l, t = l; t <= l + 30 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                     for(int s = l, t = l + 1; t <= l + 31 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                 }
+                 consBppMat.ref(m,n) += tmpProb;
+             }
+         }
+       }
+*/
+       for (int m = 1; m <= seq1Length; m++) {
+           for (int n = m + 4; n <= seq1Length; n++) {
+               consBppMat.ref(m,n) = consBppMat.ref(m,n)/(float)numSeqs;
+           }
+       }
+       seq1BppMatrix->updateBPPMatrix(consBppMat);
+    }
+}
+
+/////////////////////////////////////////////////////////////////
+// GetSubtree
+//
+// Returns set containing all leaf labels of the current subtree.
+/////////////////////////////////////////////////////////////////
+
+set<int> GetSubtree (const TreeNode *tree){
+  set<int> s;
+
+  if (tree->GetSequenceLabel() == -1){
+    s = GetSubtree (tree->GetLeftChild());
+    set<int> t = GetSubtree (tree->GetRightChild());
+
+    for (set<int>::iterator iter = t.begin(); iter != t.end(); ++iter)
+      s.insert (*iter);
+  }
+  else {
+    s.insert (tree->GetSequenceLabel());
+  }
+
+  return s;
+}
+
+/////////////////////////////////////////////////////////////////
+// TreeBasedBiPartitioning
+//
+// Uses the iterative refinement scheme from MUSCLE.
+/////////////////////////////////////////////////////////////////
+
+void TreeBasedBiPartitioning (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                              const ProbabilisticModel &model, MultiSequence* &alignment,
+                              const TreeNode *tree, SafeVector<BPPMatrix*> &BPPMatrices){
+  // check if this is a node of the alignment tree
+  if (tree->GetSequenceLabel() == -1){
+    TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree->GetLeftChild(), BPPMatrices);
+    TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree->GetRightChild(), BPPMatrices);
+
+    set<int> leftSubtree = GetSubtree (tree->GetLeftChild());
+    set<int> rightSubtree = GetSubtree (tree->GetRightChild());
+    set<int> leftSubtreeComplement, rightSubtreeComplement;
+
+    // calculate complement of each subtree
+    for (int i = 0; i < alignment->GetNumSequences(); i++){
+      if (leftSubtree.find(i) == leftSubtree.end()) leftSubtreeComplement.insert (i);
+      if (rightSubtree.find(i) == rightSubtree.end()) rightSubtreeComplement.insert (i);
+    }
+
+    // perform realignments for edge to left child
+    if (!leftSubtree.empty() && !leftSubtreeComplement.empty()){
+      MultiSequence *groupOneSeqs = alignment->Project (leftSubtree); assert (groupOneSeqs);
+      MultiSequence *groupTwoSeqs = alignment->Project (leftSubtreeComplement); assert (groupTwoSeqs);
+      delete alignment;
+      alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model, BPPMatrices, tree->GetLeftChild()->GetIdentity());
+    }
+
+    // perform realignments for edge to right child
+    if (!rightSubtree.empty() && !rightSubtreeComplement.empty()){
+      MultiSequence *groupOneSeqs = alignment->Project (rightSubtree); assert (groupOneSeqs);
+      MultiSequence *groupTwoSeqs = alignment->Project (rightSubtreeComplement); assert (groupTwoSeqs);
+      delete alignment;
+      alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model, BPPMatrices, tree->GetRightChild()->GetIdentity());
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoterativeRefinement()
+//
+// Performs a single round of randomized partionining iterative
+// refinement.
+/////////////////////////////////////////////////////////////////
+/*
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment){
+  set<int> groupOne, groupTwo;
+
+  // create two separate groups
+  for (int i = 0; i < alignment->GetNumSequences(); i++){
+    if (rand() % 2)
+      groupOne.insert (i);
+    else
+      groupTwo.insert (i);
+  }
+
+  if (groupOne.empty() || groupTwo.empty()) return;
+
+  // project into the two groups
+  MultiSequence *groupOneSeqs = alignment->Project (groupOne); assert (groupOneSeqs);
+  MultiSequence *groupTwoSeqs = alignment->Project (groupTwo); assert (groupTwoSeqs);
+  delete alignment;
+
+  // realign
+  alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model);
+
+  delete groupOneSeqs;
+  delete groupTwoSeqs;
+}
+*/
+
+/////////////////////////////////////////////////////////////////
+// WriteAnnotation()
+//
+// Computes annotation for multiple alignment and write values
+// to a file.
+/////////////////////////////////////////////////////////////////
+
+void WriteAnnotation (MultiSequence *alignment, 
+                     const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+  ofstream outfile (annotationFilename.c_str());
+  
+  if (outfile.fail()){
+    cerr << "ERROR: Unable to write annotation file." << endl;
+    exit (1);
+  }
+
+  const int alignLength = alignment->GetSequence(0)->GetLength();
+  const int numSeqs = alignment->GetNumSequences();
+  
+  SafeVector<int> position (numSeqs, 0);
+  SafeVector<SafeVector<char>::iterator> seqs (numSeqs);
+  for (int i = 0; i < numSeqs; i++) seqs[i] = alignment->GetSequence(i)->GetDataPtr();
+  SafeVector<pair<int,int> > active;
+  active.reserve (numSeqs);
+  
+  // for every column
+  for (int i = 1; i <= alignLength; i++){
+    
+    // find all aligned residues in this particular column
+    active.clear();
+    for (int j = 0; j < numSeqs; j++){
+      if (seqs[j][i] != '-'){
+       active.push_back (make_pair(j, ++position[j]));
+      }
+    }
+    
+    outfile << setw(4) << ComputeScore (active, sparseMatrices) << endl;
+  }
+  
+  outfile.close();
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeScore()
+//
+// Computes the annotation score for a particular column.
+/////////////////////////////////////////////////////////////////
+
+int ComputeScore (const SafeVector<pair<int, int> > &active, 
+                 const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+
+  if (active.size() <= 1) return 0;
+  
+  // ALTERNATIVE #1: Compute the average alignment score.
+
+  float val = 0;
+  for (int i = 0; i < (int) active.size(); i++){
+    for (int j = i+1; j < (int) active.size(); j++){
+      val += sparseMatrices[active[i].first][active[j].first]->GetValue(active[i].second, active[j].second);
+    }
+  }
+
+  return (int) (200 * val / ((int) active.size() * ((int) active.size() - 1)));
+  
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Makefile b/binaries/src/mafft/extensions/mxscarna_src/Makefile
new file mode 100644 (file)
index 0000000..359e15b
--- /dev/null
@@ -0,0 +1,76 @@
+################################################################################
+# Makefile for probcons
+################################################################################
+
+################################################################################
+# 1) Choose C++ compiler.
+################################################################################
+
+CXX = g++
+
+################################################################################
+# 2) Set C++ flags.
+#    a) DEBUG mode -- no optimizations, enable SafeVector checking, no inlining
+#    b) PROFILE mode -- for gprof
+#    c) RELEASE mode
+################################################################################
+BIG_INLINE_LIMIT = 20000
+
+PROBCONS = ./probconsRNA
+VIENNA   = ./vienna
+
+# no -Wall option for warning
+CXXFLAGS = -O3 -funroll-loops -finline-limit=$(BIG_INLINE_LIMIT)
+OFLAGS = -DNDEBUG -DNumInsertStates=1 -DVERSION="2.0" $(CXXFLAGS) $(CFLAGS1)
+LIBS = -L$(PROBCONS)  -L./
+INCL = -I$(PROBCONS) -I$(VIENNA) -I./
+
+################################################################################
+# 3) Dependencies
+################################################################################
+
+TARGETS = mxscarna 
+
+OBJS = Main.o McCaskill.o vienna/energy_param.o seq2scs.o Globaldp.o postProcessings.o AlifoldMEA.o
+
+.PHONY : all
+all : $(TARGETS) 
+
+mxscarna : $(OBJS)
+       $(CXX) $(LIBS) $(OFLAGS) -lm -o $@ $(OBJS)
+
+rfold:  
+       cd $(RFOLD); \
+       make; \
+       cd .. \
+       cd ..
+probcons:
+       cd $(PROBCONS); \
+       make; \
+       cd .. 
+
+#probcons : MultiSequence.h ProbabilisticModel.h ScoreType.h Sequence.h FileBuffer.h SparseMatrix.h EvolutionaryTree.h Defaults.h SafeVector.h Main.cc
+#      $(CXX) -lm -o probcons $(OBJS)
+#Main.cc 
+
+Main.o :  $(PROBCONS)/SafeVector.h $(PROBCONS)/FileBuffer.h $(PROBCONS)/Sequence.h $(PROBCONS)/MultiSequence.h $(PROBCONS)/EvolutionaryTree.h scarna.hpp BPPMatrix.hpp StemCandidate.hpp Globaldp.hpp AlifoldMEA.h Main.cc
+       $(CXX) $(INCL) $(OFLAGS) -c Main.cc -o Main.o
+McCaskill.o: McCaskill.hpp $(VIENNA)/energy_param.hpp Util.hpp Beta.hpp ScoreType.hpp McCaskill.cpp
+       $(CXX) $(INCL) $(OFLAGS) -c McCaskill.cpp -o McCaskill.o
+$(VIENNA)/energy_param.o: $(VIENNA)/energy_param.hpp $(VIENNA)/energy_param.cpp
+       $(CXX) $(INCL) $(OFLAGS) -c $(VIENNA)/energy_param.cpp -o $(VIENNA)/energy_param.o
+seq2scs.o: $(PROBCONS)/SafeVector.h StemCandidate.hpp $(PROBCONS)/Sequence.h $(PROBCONS)/MultiSequence.h BPPMatrix.hpp nrutil.h seq2scs.cpp
+       $(CXX) $(INCL) $(OFLAGS) -c seq2scs.cpp -o seq2scs.o
+Globaldp.o: Globaldp.hpp nrutil.h Util.hpp Beta.hpp scarna.hpp StemCandidate.hpp $(PROBCONS)/MultiSequence.h $(PROBCONS)/Sequence.h BPPMatrix.hpp
+       $(CXX) $(INCL) $(OFLAGS) -c Globaldp.cpp -o Globaldp.o
+GlobalParameters.o: scarna.hpp
+       $(CXX) $(INCL) $(OFLAGS) -c GlobalParameters.cpp -o GlobalParameters.o
+postProcessings.o: StemCandidate.hpp scarna.hpp
+       $(CXX) $(INCL) $(OFLAGS) -c postProcessings.cpp -o postProcessings.o
+AlifoldMEA.o: nrutil.h Util.hpp Beta.hpp BPPMatrix.hpp $(PROBCONS)/MultiSequence.h $(PROBCONS)/Sequence.h $(PROBCONS)/SafeVector.h
+       $(CXX) $(INCL) $(OFLAGS) -c AlifoldMEA.cpp -o AlifoldMEA.o
+
+.PHONY : clean
+clean:
+       rm -f $(TARGETS) *.o *.h~ *.hpp~ *.cpp~ *.cc~ $(VIENNA)/*.o 
+       $(MAKE) -C $(PROBCONS) clean
diff --git a/binaries/src/mafft/extensions/mxscarna_src/McCaskill.cpp b/binaries/src/mafft/extensions/mxscarna_src/McCaskill.cpp
new file mode 100644 (file)
index 0000000..39497fb
--- /dev/null
@@ -0,0 +1,839 @@
+#include <iostream>
+#include "McCaskill.hpp"
+//#include "energy_param3.hpp"
+#include "Util.hpp"
+#include <cstring>
+
+namespace MXSCARNA {
+energy_param  McCaskill::energyParam;
+
+float *McCaskill::exphairpin;
+float McCaskill::expninio[5][32];
+float McCaskill::expdangle5[6][4];
+float McCaskill::expdangle3[6][4];
+float McCaskill::expinternalLoop[31];
+float McCaskill::expbulge[31];
+char   McCaskill::exptriLoop[2][6];
+float McCaskill::exptriLoopEnergy[2];
+char   McCaskill::exptetraLoop[30][7];
+float McCaskill::exptetraLoopEnergy[30];
+float McCaskill::expStack[6][6];
+float McCaskill::expTstackH[6][16];
+float McCaskill::expTstackI[6][16];
+float McCaskill::expint11[6][6][16];
+float McCaskill::expint21[6][6][16][4];
+float McCaskill::expint22[6][6][16][16];
+float McCaskill::expMLclosing;
+float McCaskill::expMLintern[8];
+float McCaskill::expTermAU;
+float McCaskill::expMLbase[31];
+
+const int McCaskill::TURN         = 3;
+const float McCaskill::GASCONST   = 1.98717;
+const float McCaskill::T          = 37 + 273.15;
+const int McCaskill::MAXLOOP      = 30;
+const int McCaskill::TETRA_ENTH37 = -400;
+const int McCaskill::NBPAIRS      = 7;
+const int McCaskill::SCALE        = 10;
+
+
+void 
+McCaskill::
+calcPartitionFunction()
+{ 
+    initParameter();
+    Inside();
+    Outside();
+    convertProbability();
+
+/*
+    for(int i = 0; i < n_seq; i++) {
+       for(int j = i; j < n_seq; j++) {
+           cout << getProb(i, j) << " ";
+       }
+       cout << endl;
+    }
+*/
+}
+
+void
+McCaskill::
+convertProbability()
+{
+    float *pPointer  = p.getPointer(0, 0);
+    float *abPointer = ab.getPointer(0,0);
+    for(int i = 0; i < n_seq; i++) {
+       for(int j = i; j < n_seq; j++) {
+           *pPointer += *abPointer++;
+           *pPointer++ = EXP(*pPointer);
+       }
+    }
+}
+
+void 
+McCaskill::
+Inside()
+{
+
+    for (int i = n_seq - TURN - 2; i >= 0; i--) {
+       float *abPointer   = ab.getPointer(i, i + TURN + 1);
+       float *am1Pointer  = am1.getPointer(i, i + TURN + 1);
+       float *amPointer   = am.getPointer(i, i + TURN + 1);
+       float *q1Pointer   = q1.getPointer(i, i + TURN + 1);
+       float *aPointer    = a.getPointer(i, i + TURN + 1);
+       int   *typePointer = typeMat.getPointer(i, i+TURN+1);
+       for (int j = i + TURN + 1; j < n_seq; j++) {
+           int tmpType   = *typePointer++;
+                           *abPointer++  = compQb(i, j, tmpType);
+           am1v.ref(i,j) = *am1Pointer++ = compQm1(i,j, tmpType);
+           amv.ref(i,j)  = *amPointer++  = compQm(i,j);
+           q1v.ref(i,j)  = *q1Pointer++  = compQ1(i,j, tmpType);
+                           *aPointer++   = compQ(i,j);   
+       }
+    }
+}
+
+inline float
+McCaskill::
+compQb(int i, int j, int tmpType) 
+{
+
+    float tmpAb;
+    int type  = tmpType;
+    int u     = j - i - 1;
+    if(Beta::isCanonicalReducedPairCode(type)) {
+       // hairpin energy 
+       assert(u >= 3);
+       tmpAb = expHairpinEnergy(type, u, i + 1, j - 1);
+               
+       // base pair, bulge, interior loop energy
+       for(int h = i + 1; h <= MIN(i + MAXLOOP + 1, j - TURN - 2); h++) {
+           int u1 = h-i-1;
+           int max = MAX(h + TURN + 1, j-1-MAXLOOP+u1);
+           float *abPointer     = ab.getPointer(h, max - 1);
+           const int *typeMatPointer = typeMat.getPointer(h, max);
+
+           for(int l = max; l < j; l++) {
+               int type2 = *typeMatPointer++;
+               abPointer++;
+               if(!Beta::isCanonicalReducedPairCode(type2)) continue;
+               
+               assert(h >= 0 && h < n_seq && l >= 0 && l < n_seq);
+               type2 = Beta::flipReducedPairCode(type2);
+               assert(h-i-1 >= 0); assert(j-l-1 >= 0);
+               float loopE = *abPointer;
+               loopE += expLoopEnergy(u1, j-l-1, tmpType, type2, i+1, j-1, h-1, l+1); 
+               tmpAb = LOG_ADD(tmpAb, loopE);
+           }
+       }
+
+       // multi loop
+       float tmpQm = IMPOSSIBLE;
+       float *amPointer  = am.getPointer(i + 1, j - TURN - 3);
+       float *am1Pointer = am1v.getPointer(j-TURN-2, j-1);
+       for(int h = j - TURN - 2; h >= i + TURN + 3; h--) {
+           assert(h >= 0 && h < n_seq);
+           float tmpScore = *amPointer--;
+           tmpScore += *am1Pointer--;
+           tmpQm = LOG_ADD(tmpQm, tmpScore);
+       }
+       tmpQm += expMLclosing + expMLintern[type];
+       tmpQm += endStemScore(i, j);
+       tmpAb = LOG_ADD(tmpAb, tmpQm);
+    }
+    else {
+       tmpAb = IMPOSSIBLE;
+    }
+    return tmpAb;
+}
+
+//F = a:ML_closing + b:ML_intern*k + c:ML_BASE*u
+
+inline float
+McCaskill::
+compQm1(int i, int j, int tmpType)
+{
+    float tmpQm1 = IMPOSSIBLE;
+
+    int l = j;
+    if (i + TURN + 1 <= l) {
+       int type = typeMat.ref(i,l);
+       if(Beta::isCanonicalReducedPairCode(type)) {
+           float tmpScore = ab.ref(i,l);
+           tmpScore += beginStemScore(i, l);
+           //tmpScore += expMLbase[1]*(j-l) + expMLintern[type];
+           tmpScore += expMLintern[tmpType];
+           tmpQm1 = LOG_ADD(tmpQm1, tmpScore);
+       }
+    }
+    if(i < j) {
+       tmpQm1 = LOG_ADD(tmpQm1, am1.ref(i,j-1));
+    }
+
+    return tmpQm1;
+}
+
+inline float
+McCaskill::
+compQm(int i, int j)
+{
+    float tmpQm = IMPOSSIBLE;
+    float *amPointer  = am.getPointer(i,j-TURN-2);
+    float *am1Pointer = am1v.getPointer(j-TURN-1, j);
+    for(int h = j - TURN - 1; h >= i ; h--) {
+       float tmpScore = 0;
+       float tmpAm1 = *am1Pointer--;
+       
+       tmpScore += tmpAm1;
+       tmpQm = LOG_ADD(tmpQm, tmpScore);
+       tmpScore = *amPointer--;
+       tmpScore += tmpAm1;
+       tmpQm = LOG_ADD(tmpQm, tmpScore);
+    }
+
+    return tmpQm;
+}
+
+inline float
+McCaskill::
+compQ1(int i, int j, int tmpType)
+{
+    float tmpQ1 = IMPOSSIBLE;
+
+    if(Beta::isCanonicalReducedPairCode(tmpType)) {
+       float tmpScore = ab.ref(i, j);
+       tmpScore += beginStemScore(i, j);
+       tmpQ1 = LOG_ADD(tmpQ1, tmpScore);
+    }
+    tmpQ1 = LOG_ADD(tmpQ1, q1.ref(i, j - 1));
+
+    return tmpQ1;
+}
+
+inline float
+McCaskill::
+compQ(int i, int j)
+{
+    float tmpQ = 0;
+    tmpQ = LOG_ADD(tmpQ, q1.ref(i,j));
+    
+    float *aPointer  = a.getPointer(i,j-TURN-2);
+    float *q1Pointer = q1v.getPointer(j-TURN-1, j);
+    for(int h = j - TURN - 1; h >= i + 1; h--) {
+       float tmpScore  = *aPointer--;
+       tmpScore       += *q1Pointer--;
+       tmpQ            = LOG_ADD(tmpQ, tmpScore);
+    }
+
+    return tmpQ;
+}
+
+inline float
+McCaskill::
+beginStemScore(const int i, const int j) const
+{
+    float temp = 0;
+    int type = typeMat.ref(i,j);
+
+    if(0 < i)                   { temp += expdangle5[type][numSeq[i-1]]; }
+    if(j < n_seq-1)             { temp += expdangle3[type][numSeq[j+1]]; }
+    if(type != Beta::REDUCED_CG_CODE && type != Beta::REDUCED_GC_CODE)  { temp += expTermAU; }
+    return temp;
+}
+
+inline float
+McCaskill::
+endStemScore(const int i, const int j) const
+{
+    float temp = 0;
+    int type = typeMat.ref(i,j);
+
+    type = Beta::flipReducedPairCode(type);
+
+    if(i < n_seq-1)             { temp += expdangle3[type][numSeq[i+1]]; }
+    if(j > 0)                   { temp += expdangle5[type][numSeq[j-1]]; }
+    if(type != Beta::REDUCED_CG_CODE && type != Beta::REDUCED_GC_CODE)  { temp += expTermAU; }
+    return temp;
+}
+
+inline float
+McCaskill::
+compP(int h, int l, int tmpType)
+{
+    float prob = IMPOSSIBLE;
+           
+    int type = tmpType;
+    if(Beta::isCanonicalReducedPairCode(type)) {
+               
+       /* exterior loop */
+       float tmp_p = 0;
+       tmp_p -= a.ref(0,n_seq-1);
+       if(0 < h) { 
+           tmp_p += a.ref(0,h-1);
+       }
+       if(l < n_seq-1) {
+           tmp_p += a.ref(l+1, n_seq-1);
+       }
+       tmp_p += beginStemScore(h, l);
+       prob = LOG_ADD(prob, tmp_p);
+
+       assert(IMPOSSIBLE <= prob && prob <= 0);
+
+       /* internal loop */
+       tmp_p = IMPOSSIBLE;
+       int tt = Beta::flipReducedPairCode(tmpType);
+       int max = MAX(0,h-MAXLOOP-1);
+       for(int i = max; i <= h - 1; i++) {
+           float min = MIN(l+MAXLOOP-h+i+2, n_seq-1);
+           int   *typeMatPointer = typeMat.getPointer(i,l+1);
+           float *pPointer       = p.getPointer(i,l);
+           for(int j = l + 1; j <= min; j++) {
+               int type2    = *typeMatPointer++;
+               pPointer++;
+               if(!Beta::isCanonicalReducedPairCode(type2)) continue;
+               assert(i >= 0 && i < n_seq && j >= 0 && j < n_seq);
+
+               float tmpScore  = *pPointer;
+               tmpScore       += expLoopEnergy(h-i-1, j-l-1, type2, tt, i+1, j-1, h-1, l+1);
+               tmp_p = LOG_ADD(tmp_p, tmpScore);
+           }
+       }
+       prob = LOG_ADD(prob, tmp_p); 
+       assert(IMPOSSIBLE <= prob && prob <= 0);
+
+       /* multi loop */
+       tmp_p = IMPOSSIBLE;
+       float tmp_begin   = beginStemScore(h, l);
+       float *q1Pointer  = q1v.getPointer(0, l);
+       float *am1Pointer = am1v.getPointer(0, l);
+       float *amPointer  = amv.getPointer(1,h-1);
+       for(int i = 0; i <= h-TURN-1; i++) {
+           float tmpq1    = *q1Pointer++;
+           float tmpam    = *amPointer++;
+           float tmpScore = *am1Pointer++;
+
+           tmpScore += tmpam;
+           tmpScore += tmp_begin;
+           tmpScore += expMLclosing + expMLintern[tt];
+           tmp_p = LOG_ADD(tmp_p, tmpScore);
+
+           tmpScore  = tmpq1;
+           tmpScore += tmpam;
+           tmpScore += tmp_begin;
+           tmpScore += expMLclosing + expMLintern[tt];
+           tmp_p = LOG_ADD(tmp_p, tmpScore);
+
+           tmpScore  = tmpq1;
+           tmpScore += tmp_begin;
+           tmpScore += expMLclosing + expMLintern[tt];
+           tmp_p = LOG_ADD(tmp_p, tmpScore);
+       }
+               
+       assert(IMPOSSIBLE <= tmp_p && tmp_p <= 0);
+       prob = LOG_ADD(prob, tmp_p); 
+       
+       tmp_p = IMPOSSIBLE;
+       for(int i = h-TURN; i <= h-1; i++) {
+           if(i >= 0) {
+               float tmpScore  = q1.ref(i,l);
+               tmpScore       += tmp_begin;
+               tmpScore       += expMLclosing + expMLintern[tt];
+               tmp_p           = LOG_ADD(tmp_p, tmpScore);
+           }
+       }
+       assert(IMPOSSIBLE <= tmp_p && tmp_p <= 0); 
+       prob = LOG_ADD(prob, tmp_p);
+    }
+    else {
+       prob = IMPOSSIBLE;
+    }
+
+    return prob;
+}
+
+inline float
+McCaskill::
+compPm(int i, int l)
+{
+  float tmpPm  = IMPOSSIBLE;
+
+  int *typeMatPointer   = typeMat.getPointer(i,n_seq-1);
+  float *pPointer       = p.getPointer(i,n_seq);
+  float *amPointer      = am.getPointer(l+1,n_seq-1);
+  float *abPointer      = ab.getPointer(i, n_seq);
+  for(int j = n_seq - 1; j >= l + TURN + 1; j--) {
+      int type = *typeMatPointer--;
+      pPointer--;
+      amPointer--;
+      abPointer--;
+      if(Beta::isCanonicalReducedPairCode(type)) {
+         float tmp  = *pPointer;
+         tmp       += *amPointer;
+         tmp       += endStemScore(i, j);
+         tmpPm = LOG_ADD(tmpPm, tmp);
+      }
+  }
+  tmpPm += expMLintern[1];
+
+  return tmpPm;
+}
+
+inline float
+McCaskill::
+compPm1(int i, int l)
+{
+  float tmpPm1 = IMPOSSIBLE;
+
+  int j =  l + 1;
+  if(j <= n_seq-1) {
+      int type = typeMat.ref(i,j);
+      if(Beta::isCanonicalReducedPairCode(type)) {
+         float tmp = p.ref(i,j);
+         tmp += endStemScore(i, j);
+         tmpPm1 = tmp;
+      }
+      tmpPm1 += expMLintern[1];
+  }
+  if(l+1 <= n_seq - 1) {
+      tmpPm1 = LOG_ADD(tmpPm1, am1.ref(i, l+1));
+  }
+
+  return tmpPm1;
+}
+
+void 
+McCaskill::
+Outside()
+{
+    for(int h = 0; h <= n_seq - TURN - 2; h++) {
+       float *pPointer    = p.getPointer(h, n_seq-1);
+       float *q1Pointer   = q1.getPointer(h, n_seq-1);
+       float *am1Pointer  = am1.getPointer(h, n_seq-1);
+       int   *typePointer = typeMat.getPointer(h, n_seq-1);
+       for(int l = n_seq-1; l >= h + TURN + 1; l--) {
+           int tmpType    = *typePointer--;
+           pv.ref(h,l)    = *pPointer--   = compP(h,l,tmpType);
+           q1v.ref(h,l)   = *q1Pointer--  = compPm(h,l);
+           am1v.ref(h,l)  = *am1Pointer-- = compPm1(h,l);
+
+           assert(p.ref(h,l) <= 0);
+       }
+    }
+}
+
+void
+McCaskill::
+printProbMat()
+{
+    int m = 0;
+    for(int i = 0; i < n_seq; i++) cout << " " << seq[i];
+    cout << endl;
+    for(int i = 0; i < n_seq; i++) {
+       if(m < n_seq) {
+           cout << seq[m];
+       }
+       for(int j = 0; j <= i-1; j++) {
+           if(j != i-1) cout << "  ";
+           else         cout << " ";
+       }
+       if(i != 0 && i != n_seq-1) {
+           cout << "\\";
+       }
+
+       for(int j = i; j < n_seq; j++) {
+           if(p.ref(i,j) > 0.01) {
+
+               int type = Beta::getReducedPairCode(numSeq[i], numSeq[j]);
+               
+               if(!Beta::isCanonicalReducedPairCode(type)) {
+                   cout << "\n" << seq[i] << " " << seq[j] << " " << exp(p.ref(i,j)) << endl;
+               }
+
+               if(j != n_seq-1) {
+                   cout << "* ";
+               }
+               else {
+                   cout << "*";
+               }
+
+           }
+           else {
+
+               if(j != n_seq-1) {
+                   cout << "  ";
+               }
+               else {
+                   cout << " ";
+               }
+
+           }
+
+       }
+       if(m < n_seq) {
+           cout << seq[m++] << endl;
+       }
+       if(i == n_seq - 1) cout << endl;
+    }
+    for(int i = 0; i < n_seq; i++) cout << " " << seq[i];
+    cout << endl;
+}
+
+void
+McCaskill::
+initParameter()
+{
+    float GT;
+    float RT_KCAL_MOL = McCaskill::T*McCaskill::GASCONST;
+    int len = 31;
+
+    for(int i = 0; i < len; i++) {
+       GT = energyParam.getHairpin(i);
+       exphairpin[i] = -GT*10/RT_KCAL_MOL;
+    }
+    
+    for (int i = 0; i < len; i++) {
+       GT = energyParam.getBulge(i);
+       expbulge[i] = -GT*10/RT_KCAL_MOL;
+       GT = energyParam.getInternalLoop(i);
+       expinternalLoop[i] = -GT*10/RT_KCAL_MOL;
+    }
+    expinternalLoop[2] = -80*10/RT_KCAL_MOL; /* special case of size 2 interior loops (single mismatch) */
+    
+    // float lxc = energy_param3::lxc37;
+    for (int i = 31; i < n_seq; i++) {
+       GT = energyParam.getHairpin(30) + (107.856*LOG((float)i/30));
+       exphairpin[i] = -GT*10/RT_KCAL_MOL;
+    }
+
+    for(int i = 0; i < 5; i++) {
+       GT = energyParam.getNinio(i);
+       for(int j = 0; j <= MAXLOOP; j++) {
+           expninio[i][j] = -MIN(energyParam.getMaxNinio(), j*GT)*10/RT_KCAL_MOL;
+       }
+    }
+
+    for(int i = 0; i < 30; i++) {
+      GT = energyParam.getTetraLoopEnergy(i);
+      exptetraLoopEnergy[i] = -GT*10/RT_KCAL_MOL;
+    }
+    
+    /*no parameters for Triloop*/
+    for(int i = 0; i < 2; i++) {
+       GT = 0;
+       exptriLoopEnergy[i] = -GT*10/RT_KCAL_MOL;
+    }
+
+    GT = energyParam.getMLclosing();
+    expMLclosing = -GT*10/RT_KCAL_MOL;
+
+    for(int i = 0; i <= NBPAIRS; i++) {
+      GT = energyParam.getMLintern();
+      expMLintern[i] = -GT*10/RT_KCAL_MOL;
+    }
+
+    expTermAU = -energyParam.getTerminalAU()*10/RT_KCAL_MOL;
+    
+    GT = energyParam.getMLBase();
+    for(int i = 0; i < len; i++) {
+       expMLbase[i] = -GT*10*(float)i/RT_KCAL_MOL;
+    }
+
+    /*
+       if danlges = 0 just set their energy to 0,
+       don't let dangle energyies become > 0 (at large temps)
+       but make sure go smoothly to 0
+    */
+    for(int i = 0; i < 6; i++) {
+       for(int j =0; j < 4; j++) {
+           GT = energyParam.getDangle5(i,j);
+           expdangle5[i][j] = -GT*10/RT_KCAL_MOL;
+           GT = energyParam.getDangle3(i,j);
+           expdangle3[i][j] = -GT*10/RT_KCAL_MOL;
+       }
+    }
+
+    /* stacking energies  */
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           GT = energyParam.getStack(i,j);
+           expStack[i][j] = -GT*10/RT_KCAL_MOL;
+       }
+    }
+
+    /* mismatch energies */
+    for (int i = 0; i < 6; i++) {
+       for (int j = 0; j < 16; j++) {
+         GT = energyParam.getTstackI(i, j);
+         //  cout << i << " " << " " << j << " " << GT << endl;
+         expTstackI[i][j] = -GT*10/RT_KCAL_MOL;
+         GT = energyParam.getTstackH(i, j);
+         expTstackH[i][j] = -GT*10/RT_KCAL_MOL;
+       }
+    }
+    
+    /* interior loops of length 2*/
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+             GT = energyParam.getInt11(i, j, k);
+             expint11[i][j][k] = -GT*10/RT_KCAL_MOL;
+           }
+       }
+    }
+
+    /* interior 2*1 loops */
+    for(int i = 0; i < 6; i++) {
+       for(int j =0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+               for(int l = 0; l < 4; l++) {
+                 GT = energyParam.getInt21(i,j,k,l);
+                 expint21[i][j][k][l] = -GT*10/RT_KCAL_MOL;
+               }
+           }
+       }
+    }
+
+    /* interior 2*2 loops */
+    for (int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+               for(int l = 0; l < 16; l++) {
+                 GT = energyParam.getInt22(i,j,k,l);
+                 expint22[i][j][k][l] = -GT*10/RT_KCAL_MOL;
+               }
+           }
+       }
+    }
+}
+
+
+inline float 
+McCaskill::
+expHairpinEnergy(const int type, const int l, const int i, const int j)
+{
+  float q;
+  int    k;
+  
+//  assert(l >= 0);
+  q = exphairpin[l];
+
+  if(l == 4) {
+      char temp_seq[7];
+
+      for(int iter = i - 1; iter < i + 5; iter++) {
+       temp_seq[iter - (i-1)] = seq[iter];
+      }
+      temp_seq[6] = '\0';
+
+      for(k = 0; k < 30; k++) {
+       if(strcmp(temp_seq, energyParam.getTetraLoop(k)) == 0) break;
+      }
+      if(k != 30) {
+       q += exptetraLoopEnergy[k];
+      }
+  }
+  if(l == 3) {
+
+      /* no triloop bonus
+    char temp_seq[6];
+    
+    for(int iter = i - 1; iter < i + 4; iter++) {
+       temp_seq[iter - (i-1)] = seq[iter];
+    }
+    temp_seq[6] = '\0';
+    for(k = 0; k < 2; k++) {
+      if(strcmp(temp_seq, energyParam.getTriLoop(k)) == 0) break;
+    }
+    if(k != 2) {
+      q *= exptriLoopEnergy[k];
+    }
+      */
+
+    if(type != Beta::REDUCED_CG_CODE && type != Beta::REDUCED_GC_CODE) q += expTermAU;
+  }
+  else {
+      int type2 = Beta::getPairCode(numSeq[i], numSeq[j]);
+      q += expTstackH[type][type2];
+  }
+
+  return q;
+}
+
+
+inline float 
+McCaskill::
+expLoopEnergy(int u1, int u2, int type, int type2, 
+             int si1, int sj1, int sp1, int sq1)
+{
+  float z = 0;
+
+  if((u1 == 0) && (u2 == 0)) { z = expStack[type][type2]; }
+  else {
+    if((u1 == 0) || (u2 == 0)) {
+      int u;
+      if(u1 == 0) { u = u2; }
+      else        { u = u1; }
+      z = expbulge[u];
+      if(u1 + u2 == 1) z += expStack[type][type2];
+      else {
+       if (type  != Beta::REDUCED_CG_CODE && type  != Beta::REDUCED_GC_CODE) z += expTermAU;
+       if (type2 != Beta::REDUCED_CG_CODE && type2 != Beta::REDUCED_GC_CODE) z += expTermAU;
+      }
+    }
+    else {
+      if(u1 + u2 == 2) {
+         z = expint11[type][type2][Beta::getPairCode(numSeq[si1], numSeq[sj1])];
+      }
+      else if((u1 == 1) && (u2 == 2)) {
+         z = expint21[type][type2][Beta::getPairCode(numSeq[si1], numSeq[sj1])][numSeq[sq1]];
+      }
+      else if((u1 == 2) && (u2 == 1)) {
+         z = expint21[type2][type][Beta::getPairCode(numSeq[sq1], numSeq[sp1])][numSeq[si1]];
+      }
+      else if((u1 == 2) && (u2 == 2)) {
+       z = expint22[type][type2][Beta::getPairCode(numSeq[si1], numSeq[sj1])][Beta::getPairCode(numSeq[sp1], numSeq[sq1])];
+      }
+      else {
+       z = expinternalLoop[u1 + u2] +
+           expTstackI[type][Beta::getPairCode(numSeq[si1], numSeq[sj1])]
+            + expTstackI[type2][Beta::getPairCode(numSeq[sq1], numSeq[sp1])];
+       z += expninio[2][abs(u1-u2)];
+      }
+    }
+  }
+
+  return z;
+}
+
+void
+McCaskill::
+printExpEnergy()
+{
+    cout << "exphairpin:" << endl;
+    for(int i = 0; i < 31; i++) {
+       cout << exphairpin[i] << endl;
+    }
+    
+    cout << "expninio[5][32]:" << endl;
+    for(int i = 0; i < 5; i++) {
+       for(int j = 0; j < 32; j++) {
+           cout << expninio[i][j] << " ";
+       }
+       cout << endl;
+    }
+
+    cout << "expdangle5[6][4]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 4; j++) {
+           cout << expdangle5[i][j] << " ";
+       }
+       cout << endl;
+    }
+
+    cout << "expdangle3[6][4]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 4; j++) {
+           cout << expdangle3[i][j] << " ";
+       }
+       cout << endl;
+    }
+
+    cout << "expinternalLoop[31]:" << endl;
+    for(int i = 0; i < 31; i++) {
+       cout << i << ":" << expinternalLoop[i] << endl;
+    }
+    cout << "expbulge[31]:" << endl;
+    for(int i = 0; i < 31; i++) {
+       cout << i << ":" << expbulge[i] << endl;
+    }
+    
+    cout << "exptriLoopEnergy[2]:" << endl;
+    for(int i = 0; i < 2; i++) {
+       cout << i << ":" << exptriLoopEnergy[i] << endl;
+    }
+
+    cout << "exptetraLoopEnergy[15]" << endl;
+    for(int i = 0; i < 15; i++) {
+       cout << i << ":" << exptetraLoopEnergy[i] << endl;
+    }
+    
+    cout << "expStack[6][6]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           cout << expStack[i][j] << " ";
+       }
+       cout << endl;
+    }
+
+    cout << "expTstackH[6][16]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 16; j++) {
+           cout << expTstackH[i][j] << " ";
+       }
+       cout << endl;
+    }
+
+    cout << "expTstackI[6][16]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 16; j++) {
+           cout << expTstackI[i][j] << " ";
+       }
+       cout << endl;
+    }
+    
+    cout << "expMLclosing=" << expMLclosing << endl;
+    cout << "expMLintern:" << endl;
+    for(int i = 0; i < 8; i++) {
+       cout << expMLintern[i] << " ";
+    }
+    cout << endl;
+
+    cout << "expMLbase[31]:";
+    for(int i = 0; i < 31; i++) {
+       cout << i << ":" << expMLbase[i] << endl;
+    }
+
+    cout << "expint11[6][6][16]:";
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+               cout << expint11[i][j][k] << " ";
+           }
+           cout << endl;
+       }
+       cout << endl;
+    }
+
+    cout << "expint21[6][6][16][4]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+               for(int l = 0; l < 4; l++) {
+                   cout << expint21[i][j][k][l] << " ";
+               }
+               cout << endl;
+           }
+           cout << endl;
+       }
+       cout << endl;
+    }
+
+    
+    cout << "expint22[6][6][16][16]:" << endl;
+    for(int i = 0; i < 6; i++) {
+       for(int j = 0; j < 6; j++) {
+           for(int k = 0; k < 16; k++) {
+               for(int l = 0; l < 16; l++) {
+                   cout << expint22[i][j][k][l] << " ";
+               }
+               cout << endl;
+           }
+           cout << endl;
+       }
+       cout << endl;
+    }
+
+}
+
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/McCaskill.hpp b/binaries/src/mafft/extensions/mxscarna_src/McCaskill.hpp
new file mode 100644 (file)
index 0000000..97ef7df
--- /dev/null
@@ -0,0 +1,202 @@
+
+#ifndef MCCAKILL_H
+#define MCCAKILL_H
+
+//#define NDEBUG
+
+#include <string>
+#include <iostream>
+#include "nrutil.h"
+#include <cassert>
+#include "Util.hpp"
+#include "Beta.hpp"
+
+#include "energy_param.hpp" 
+//#include "energy_param3.hpp"
+
+#include "ScoreType.hpp"
+
+
+using namespace std;
+using namespace ProbCons;
+
+namespace MXSCARNA {
+class McCaskill {
+    char *seq;
+    int  *numSeq;
+    int  n_seq;
+    static energy_param  energyParam;
+
+    Trimat<float> a, q1, ab, am, am1, p;
+    TriVertMat<float> q1v, abv, amv, am1v, pv;
+    Trimat<int> typeMat;
+    
+    void printExpEnergy();
+    void initParameter();
+    void Inside();
+    void Outside();
+    void convertProbability();
+
+    inline float expHairpinEnergy(const int type, const int l, const int i, const int j);
+    inline float expLoopEnergy(int u1, int u2, int type, int type2, 
+                        int si1, int sj1, int sp1, int sq1);
+    
+    inline float compQb(int i, int j, int tmpType);
+    inline float compQm1(int i, int j, int tmpType);
+    inline float compQm(int i, int j);
+    inline float compQ1(int i, int j, int tmpType);
+    inline float compQ(int i, int j);
+    inline float compP(int h, int l, int tmpType);
+    inline float compPm(int i, int l);
+    inline float compPm1(int i, int l);
+    inline float beginStemScore(const int i, const int j) const;
+    inline float endStemScore(const int i, const int j) const;
+    
+    static const float GASCONST;
+    static const float T;
+    static const int    MAXLOOP;
+    static const int    TETRA_ENTH37;
+    static const int    NBPAIRS;
+    static const int    SCALE;
+    static const int    TURN;
+    static float *exphairpin;
+    static float expninio[5][32];
+    static float expdangle5[6][4];
+    static float expdangle3[6][4];
+    static float expinternalLoop[31];
+    static float expbulge[31];
+    static char   exptriLoop[2][6];
+    static float exptriLoopEnergy[2];
+    static char   exptetraLoop[30][7];
+    static float exptetraLoopEnergy[30];
+    static float expStack[6][6];
+    static float expTstackH[6][16];
+    static float expTstackI[6][16];
+    static float expint11[6][6][16];
+    static float expint21[6][6][16][4];
+    static float expint22[6][6][16][16];
+    static float expMLclosing;
+    static float expMLintern[8];
+    static float expTermAU;
+    static float expMLbase[31];
+
+ public:
+    
+    McCaskill(int n, const char *mySeq) {
+       seq    = new char[n + 1];
+       numSeq = new int[n + 1];
+       n_seq = 0;
+
+       
+       for(int i = 0; i < n; i++) {
+           if     (mySeq[i] == 'a' || mySeq[i] == 'A') { seq[n_seq] = 'A'; numSeq[n_seq] = Beta::A_CODE; n_seq++; }
+           else if(mySeq[i] == 't' || mySeq[i] == 'T' ||
+                   mySeq[i] == 'u' || mySeq[i] == 'U') { seq[n_seq] = 'U'; numSeq[n_seq] = Beta::U_CODE; n_seq++; }
+           else if(mySeq[i] == 'g' || mySeq[i] == 'G') { seq[n_seq] = 'G'; numSeq[n_seq] = Beta::G_CODE; n_seq++; }
+           else if(mySeq[i] == 'c' || mySeq[i] == 'C') { seq[n_seq] = 'C'; numSeq[n_seq] = Beta::C_CODE; n_seq++; }
+           else if(mySeq[i] == 'n' || mySeq[i] == 'N') { seq[n_seq] = 'N'; numSeq[n_seq] = Beta::N_CODE; n_seq++; } 
+           else if(mySeq[i] == '.' || mySeq[i] == '-') { seq[n_seq] = '-'; numSeq[n_seq] = Beta::GAP_CODE; n_seq++; }
+           else { seq[n_seq] = mySeq[i]; numSeq[n_seq] = Beta::INVALID_CODE; n_seq++; }
+       }
+       seq[n_seq] = '\0'; 
+       a.Allocator(n_seq);
+       q1.Allocator(n_seq);
+       ab.Allocator(n_seq);
+       am.Allocator(n_seq);
+       am1.Allocator(n_seq);
+       p.Allocator(n_seq);
+       q1v.Allocator(n_seq);
+       abv.Allocator(n_seq);
+       amv.Allocator(n_seq);
+       am1v.Allocator(n_seq);
+       pv.Allocator(n_seq);
+       typeMat.Allocator(n_seq);
+
+       if(n_seq > 31) {
+         exphairpin = new float[n_seq + 1];
+       }
+       else {
+         exphairpin = new float[31];
+       }
+
+       for(int i = 0; i < n_seq; i++) {
+           for(int j = i; j < n_seq; j++) {
+               a.ref(i,j)  = q1.ref(i,j) = IMPOSSIBLE;
+               q1v.ref(i,j) = IMPOSSIBLE;
+           }
+       }
+       
+       for(int i = 0; i < n_seq; i++) {
+           a.ref(i,i)   = 0.0; 
+           q1.ref(i,i)  = IMPOSSIBLE;
+           q1v.ref(i,i) = IMPOSSIBLE;
+       }
+
+       for(int i = 0; i < n_seq-1; i++) {
+           a.ref(i,i+1)   = 0.0;
+           q1.ref(i,i+1)  = IMPOSSIBLE;
+           q1v.ref(i,i+1) = IMPOSSIBLE;
+       }
+
+       for(int i = 0; i < n_seq-2; i++) {
+           a.ref(i,i+2)   = 0.0;
+           q1.ref(i,i+2)  = IMPOSSIBLE;
+           q1v.ref(i,i+2) = IMPOSSIBLE;
+       }
+
+       for(int i = 0; i < n_seq-3; i++) {
+           a.ref(i,i+3)   = 0.0;
+           q1.ref(i,i+3)  = IMPOSSIBLE;   
+           q1v.ref(i,i+3) = IMPOSSIBLE;
+           
+       }
+
+       for(int i = 0; i < n_seq; i++) {
+           for(int j = i; j < n_seq; j++) {
+               ab.ref(i,j)  = am.ref(i,j)  = am1.ref(i,j)  = p.ref(i,j)  = IMPOSSIBLE;
+               abv.ref(i,j) = amv.ref(i,j) = am1v.ref(i,j) = pv.ref(i,j) = IMPOSSIBLE;
+           }
+       }
+
+       /* the type of base pair */
+       /* C <-> G : type 1      */
+       /* G <-> C : type 2      */
+       /* G <-> U : type 3      */
+       /* U <-> G : type 5      */
+       /* A <-> U : type 0      */
+       /* U <-> A : type 4      */
+       /* ? <-> ? : type 6      */
+       for(int i = 0; i < n_seq; i++) {
+           for(int j = i; j < n_seq; j++) {
+               typeMat.ref(i,j) = Beta::getReducedPairCode(numSeq[i], numSeq[j]);
+           }
+       }
+
+    }
+
+    /*------------------------------------------------------------------------*/
+    /* dangling ends should never be destabilizing, i.e. expdangle>=1         */
+    /* specific heat needs smooth function (2nd derivative)                   */
+    /* we use a*(sin(x+b)+1)^2, with a=2/(3*sqrt(3)), b=Pi/6-sqrt(3)/2,       */
+    /* in the interval b<x<sqrt(3)/2                                          */
+    float SMOOTH(float X) { 
+      return ((X)/SCALE<-1.2283697)?0:(((X)/SCALE>0.8660254)?(X):
+                                 SCALE*0.38490018*(sin((X)/SCALE-0.34242663)+1)*(sin((X)/SCALE-0.34242663)+1));
+    }
+
+    ~McCaskill() {
+       delete[] seq;
+       delete[] numSeq;
+       delete[] exphairpin;
+    }
+
+    void calcPartitionFunction();
+    void printProbMat();
+
+    inline float getProb(const int i, const int j) const { 
+       // 0 origin : 0..(n-1)
+       return p.ref(i, j);
+    }
+};
+}
+#endif // MCCASKILL_H
diff --git a/binaries/src/mafft/extensions/mxscarna_src/README b/binaries/src/mafft/extensions/mxscarna_src/README
new file mode 100644 (file)
index 0000000..0578545
--- /dev/null
@@ -0,0 +1,129 @@
+1.Program name
+ MXSCARNA
+
+2.Author
+ Yasuo Tabei
+
+ Department of Computational Biology,
+ Graduate School of Frontier Science,
+ The University of Tokyo
+ and
+ Computational Biology Research Center (CBRC),
+ National Institute of Advanced Industrial Science and Technology (AIST)
+
+ E-mail: scarna@m.aist.go.jp
+
+3.What is MXSCARNA
+ MXSCARNA (Multiplex Stem Candidate Aligner for RNAs) is a tool for
+ fast structural multiple alignment of RNA sequences using progressive
+ alignment based on pairwise structural alignment algorithm of SCARNA.
+
+4.License
+ While its original source code is provided as free software, MXSCARNA
+ contains the source codes of ProbCons and Rfold and the energy parameters
+ of Vienna RNA package (version 1.5).
+ The author thanks Dr. Chuong Do, Dr. Hisanori Kiryu and Dr. Ivo Hofacker,
+ the authors of ProbCons, Rfold and Vienna RNA package respectively,
+ and Institute for Theoretical Chemistry of the  University of Vienna.
+
+ The source code of Rfold is located in ./src/rfold-0.1, which includes
+ energy parameters of Vienna RNA package in ./src/rfold-0.1/src/vienna.
+ Energy parameters of Vienna RNA package are also included in the source
+ code of MXSCARNA (./src/vienna). Please follow ./src/rfold-0.1/readme.txt
+ file, which describes the license of Rfold, and
+ ./src/rfold-0.1/src/vienna/COPYING file and ./src/vienna/COPYING file,
+ which describe the copyright notice of the Vienna RNA package.
+ The source code of ProbCons is located in ./src/probconsRNA. Please follow
+ ./src/probcons/README.
+
+ The original part of MXSCARNA is provided as free software. It is
+ distributed in the hope that it will be useful but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ PARTICULAR PURPOSE.
+
+ Permission is granted for research, educational, and commercial use
+ and modification so long as
+ 1) the package and any derived works are not redistributed for any fee,
+    other than media costs,
+ 2) proper credit is given to
+    the authors of MXSCARNA, ProbCons, Rfold and Vienna RNA package,
+    the Univeristy of Tokyo,
+    Computational Biology Research Center (CBRC), AIST
+    and Institute for Theoretical Chemistry of the  University of Vienna.
+
+ If you want to include this software in a commercial product, please
+ contact the author.
+
+5.Citation
+ Yasuo Tabei, Hisanori Kiryu, Taishin Kin, Kiyoshi Asai:
+ "A fast structural multiple alignment method for long RNA sequences,"
+ BMC bioinformatics, to appear.
+
+6.References
+
+ Do, C.B., Mahabhashyam, M.S.P., Brudno, M., and Batzoglou, S. 2005.
+ PROBCONS: Probabilistic Consistency-based Multiple Sequence Alignment.
+ Genome Research 15: 330-340.
+
+ Hisanori Kiryu, Taishin Kin, and Kiyoshi Asai
+ Rfold: An exact algorithm for computing local base pairing probabilities
+ Bioinformatics, Advance Access published on December 4, 2007;
+ doi:10.1093/bioinformatics/btm591
+
+ Ivo L. Hofacker
+ Vienna RNA secondary structure server
+ Nucleic Acids Res., Jul 2003; 31: 3429 - 3431.
+
+ Yasuo Tabei, Koji Tsuda, Taishin Kin, and Kiyoshi Asai
+ SCARNA: fast and accurate structural alignment of RNA sequences by matching fixed-length stem fragments
+ Bioinformatics 2006 22(14):1723-1729.
+
+7.Install
+ The program was tested using gcc 3.3.3 on linux machines and gcc 3.4 on
+ cygwin Some gcc specific features are currently used.
+
+ The command to compile this software is as follows:
+
+ make
+ cd program
+
+8.Usage
+
+ ./mxscarna [options] seqfile
+
+ seqfile:
+   sequence file is multi fasta format.
+
+ options:
+   -clustalw
+      use CLUSTALW output format instead of MFA
+
+   -stockholm
+      use STOCKHOLM output format instead of MFA
+
+   -mxscarna
+      use original output format instead of MFA
+
+   -l <SCSLENGTH>
+      the length of stem candidates (default:2)
+
+   -b <BASEPROBTHRESHOLD>
+      the threshold of base-pairing probability (default:0.01)
+
+   -g <BASEPAIRSCORECONT>
+      the control parameter of the prediction of base-pairs, (default:6)
+
+   -rfold
+      use Rfold instead of global McCaskill algorithm to calcurate base
+      paring probality matrices, (default: off)
+
+   -w <BANDWIDTH>
+      the control parameter of the distance of stem candidates, (default:500)
+
+9.Example
+   ./mxscarna -mxscarna ../sample/trna.mfa
+
+10.Version History
+1. 1/16/2008 (Yasuo Tabei)
+-- MXSCARNA ver 2.0 release
+  - Rfold was included.
\ No newline at end of file
diff --git a/binaries/src/mafft/extensions/mxscarna_src/ScoreType.hpp b/binaries/src/mafft/extensions/mxscarna_src/ScoreType.hpp
new file mode 100644 (file)
index 0000000..46aa698
--- /dev/null
@@ -0,0 +1,340 @@
+/////////////////////////////////////////////////////////////////
+// ScoreType.h
+//
+// Routines for doing math operations in PROBCONS.
+/////////////////////////////////////////////////////////////////
+
+#ifndef SCORETYPE_H
+#define SCORETYPE_H
+
+#include <cmath>
+#include <algorithm>
+#include <cfloat>
+#include <cassert>
+
+typedef float ScoreType;
+
+const float LOG_ZERO = -2e20;
+const float LOG_ONE = 0.0;
+
+/////////////////////////////////////////////////////////////////
+// LOG()
+//
+// Compute the logarithm of x.
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOG (ScoreType x){
+  return log (x);
+}
+
+/////////////////////////////////////////////////////////////////
+// EXP()
+//
+// Computes exp(x).
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType EXP (ScoreType x){
+  //return exp(x);
+  if (x > -2){
+    if (x > -0.5){
+      if (x > 0)
+       return exp(x);
+      return (((0.03254409303190190000*x + 0.16280432765779600000)*x + 0.49929760485974900000)*x + 0.99995149601363700000)*x + 0.99999925508501600000;
+    }
+    if (x > -1)
+      return (((0.01973899026052090000*x + 0.13822379685007000000)*x + 0.48056651562365000000)*x + 0.99326940370383500000)*x + 0.99906756856399500000;
+    return (((0.00940528203591384000*x + 0.09414963667859410000)*x + 0.40825793595877300000)*x + 0.93933625499130400000)*x + 0.98369508190545300000;
+  }
+  if (x > -8){
+    if (x > -4)
+      return (((0.00217245711583303000*x + 0.03484829428350620000)*x + 0.22118199801337800000)*x + 0.67049462206469500000)*x + 0.83556950223398500000;
+    return (((0.00012398771025456900*x + 0.00349155785951272000)*x + 0.03727721426017900000)*x + 0.17974997741536900000)*x + 0.33249299994217400000;
+  }
+  if (x > -16)
+    return (((0.00000051741713416603*x + 0.00002721456879608080)*x + 0.00053418601865636800)*x + 0.00464101989351936000)*x + 0.01507447981459420000;
+  return 0;
+}
+
+/*
+/////////////////////////////////////////////////////////////////
+// LOOKUP()
+//
+// Computes log (exp (x) + 1), for 0 <= x <= 7.5.
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOOKUP (ScoreType x){
+  //return log (exp(x) + 1);
+  if (x < 2){
+    if (x < 0.5){
+      if (x < 0)
+       return log (exp(x) + 1);
+      return (((-0.00486373205785640000*x - 0.00020245408813934800)*x + 0.12504222666029800000)*x + 0.49999685320563000000)*x + 0.69314723138948900000;
+    }
+    if (x < 1)
+      return (((-0.00278634205460548000*x - 0.00458097251248546000)*x + 0.12865849880472500000)*x + 0.49862228499205200000)*x + 0.69334810088688000000;
+    return (((0.00059633755154209200*x - 0.01918996666063320000)*x + 0.15288232492093800000)*x + 0.48039958825756900000)*x + 0.69857578503189200000;
+  }
+  if (x < 8){
+    if (x < 4)
+      return (((0.00135958539181047000*x - 0.02329807659316430000)*x + 0.15885799609532100000)*x + 0.48167498563270800000)*x + 0.69276185058669200000;
+    return (((0.00011992394456683500*x - 0.00338464503306568000)*x + 0.03622746366545470000)*x + 0.82481250248383700000)*x + 0.32507892994863100000;
+  }
+  if (x < 16)
+    return (((0.00000051726300753785*x - 0.00002720671238876090)*x + 0.00053403733818413500)*x + 0.99536021775747900000)*x + 0.01507065715532010000;
+  return x;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP_SLOW()
+//
+// Computes log (exp (x) + 1).
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOOKUP_SLOW (ScoreType x){
+  return log (exp (x) + 1);
+}
+
+/////////////////////////////////////////////////////////////////
+// MAX()
+//
+// Compute max of three numbers
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType MAX (ScoreType x, ScoreType y, ScoreType z){
+  if (x >= y){
+    if (x >= z)
+      return x;
+    return z;
+  }
+  if (y >= z)
+    return y;
+  return z;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS (ScoreType &x, ScoreType y){
+  if (x < y)
+    x = (x <= LOG_ZERO) ? y : LOOKUP(y-x) + x;
+  else
+    x = (y <= LOG_ZERO) ? x : LOOKUP(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS_SLOW()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS_SLOW (ScoreType &x, ScoreType y){
+  if (x < y)
+    x = (x <= LOG_ZERO) ? y : LOOKUP_SLOW(y-x) + x;
+  else
+    x = (y <= LOG_ZERO) ? x : LOOKUP_SLOW(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add two log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOG_ADD (ScoreType x, ScoreType y){
+  if (x < y) return (x <= LOG_ZERO) ? y : LOOKUP(y-x) + x;
+  return (y <= LOG_ZERO) ? x : LOOKUP(x-y) + y;
+}
+*/
+
+/*
+/////////////////////////////////////////////////////////////////
+// LOG()
+//
+// Compute the logarithm of x.
+/////////////////////////////////////////////////////////////////
+
+inline float LOG (float x){
+  return log (x);
+}
+
+/////////////////////////////////////////////////////////////////
+// EXP()
+//
+// Computes exp(x), fr -4.6 <= x <= 0.
+/////////////////////////////////////////////////////////////////
+
+inline float EXP (float x){
+  assert (x <= 0.00f);
+  if (x < EXP_UNDERFLOW_THRESHOLD) return 0.0f;
+  return (((0.006349841068584 * x + 0.080775412572352) * x + 0.397982026296272) * x + 0.95279335963787f) * x + 0.995176455837312f;
+  //return (((0.00681169825657f * x + 0.08386267698832f) * x + 0.40413983195844f) * x + 0.95656674979767f) * x + 0.99556744049130f;
+}
+*/
+
+const float EXP_UNDERFLOW_THRESHOLD = -4.6;
+const float LOG_UNDERFLOW_THRESHOLD = 7.5;
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP()
+//
+// Computes log (exp (x) + 1), for 0 <= x <= 7.5.
+/////////////////////////////////////////////////////////////////
+
+inline float LOOKUP (float x){
+  assert (x >= 0.00f);
+  assert (x <= LOG_UNDERFLOW_THRESHOLD);
+  //return ((-0.00653779113685f * x + 0.09537236626558f) * x + 0.55317574459331f) * x + 0.68672959851568f;
+  if (x <= 1.00f) return ((-0.009350833524763f * x + 0.130659527668286f) * x + 0.498799810682272f) * x + 0.693203116424741f;
+  if (x <= 2.50f) return ((-0.014532321752540f * x + 0.139942324101744f) * x + 0.495635523139337f) * x + 0.692140569840976f;
+  if (x <= 4.50f) return ((-0.004605031767994f * x + 0.063427417320019f) * x + 0.695956496475118f) * x + 0.514272634594009f;
+  assert (x <= LOG_UNDERFLOW_THRESHOLD);
+  return ((-0.000458661602210f * x + 0.009695946122598f) * x + 0.930734667215156f) * x + 0.168037164329057f;
+
+  //return (((0.00089738532761f * x - 0.01859488697982f) * x + 0.14415772028626f) * x + 0.49515490689159f) * x + 0.69311928966454f;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP_SLOW()
+//
+// Computes log (exp (x) + 1).
+/////////////////////////////////////////////////////////////////
+
+inline float LOOKUP_SLOW (float x){
+  return log (exp (x) + 1);
+}
+
+/////////////////////////////////////////////////////////////////
+// MAX()
+//
+// Compute max of three numbers
+/////////////////////////////////////////////////////////////////
+
+inline float MAX (float x, float y, float z){
+  if (x >= y){
+    if (x >= z)
+      return x;
+    return z;
+  }
+  if (y >= z)
+    return y;
+  return z;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS (float &x, float y){
+  if (x < y)
+    x = (x == LOG_ZERO || y - x >= LOG_UNDERFLOW_THRESHOLD) ? y : LOOKUP(y-x) + x;
+  else
+    x = (y == LOG_ZERO || x - y >= LOG_UNDERFLOW_THRESHOLD) ? x : LOOKUP(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS_SLOW()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS_SLOW (float &x, float y){
+  if (x < y)
+    x = (x == LOG_ZERO) ? y : LOOKUP_SLOW(y-x) + x;
+  else
+    x = (y == LOG_ZERO) ? x : LOOKUP_SLOW(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add two log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x, float y){
+  if (x < y) return (x == LOG_ZERO || y - x >= LOG_UNDERFLOW_THRESHOLD) ? y : LOOKUP(y-x) + x;
+  return (y == LOG_ZERO || x - y >= LOG_UNDERFLOW_THRESHOLD) ? x : LOOKUP(x-y) + y;
+}
+
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add three log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3){
+  return LOG_ADD (x1, LOG_ADD (x2, x3));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add four log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, x4)));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add five log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, x5))));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add siz log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5, float x6){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, LOG_ADD (x5, x6)))));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add seven log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5, float x6, float x7){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, LOG_ADD (x5, LOG_ADD (x6, x7))))));
+}
+
+/////////////////////////////////////////////////////////////////
+// ChooseBestOfThree()
+//
+// Store the largest of three values x1, x2, and x3 in *x.  Also
+// if xi is the largest value, then store bi in *b.
+/////////////////////////////////////////////////////////////////
+
+inline void ChooseBestOfThree (float x1, float x2, float x3, char b1, char b2, char b3, float *x, char *b){
+  if (x1 >= x2){
+    if (x1 >= x3){
+      *x = x1;
+      *b = b1;
+      return;
+    }
+    *x = x3;
+    *b = b3;
+    return;
+  }
+  if (x2 >= x3){
+    *x = x2;
+    *b = b2;
+    return;
+  }
+  *x = x3;
+  *b = b3;
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/StemCandidate.hpp b/binaries/src/mafft/extensions/mxscarna_src/StemCandidate.hpp
new file mode 100644 (file)
index 0000000..e1678d6
--- /dev/null
@@ -0,0 +1,129 @@
+/////////////////////////////////////////////////////////////
+// StemCandidate.hpp
+// Profile Stem Candidate calcurated by profile base pairing
+// probability matrix 
+////////////////////////////////////////////////////////////
+
+#ifndef __STEMCANDIDATE_HPP__
+#define __STEMCANDIDATE_HPP__
+
+#include <string>
+#include <vector>
+
+using namespace std;
+
+namespace MXSCARNA {
+class StemCandidate {
+private:
+    int numSeq;                      /* the number of sequences in the profile */
+    int length;                      /* length of profile stem candidate of fixed length */
+    int position;                    /* 5' start position of SC in profile */
+    int distance;
+    std::vector<std::string> substr; /* profile base string of SC */
+    std::vector<std::string> rvstr;  /* profile base string of stem partner of SC */
+    int rvposition;                  /* 3' end position of stem partner of SC */
+    int rvscnumber;                  /* SC number of stem partner */
+    int contPos;                            /* previous stem that corresponds continuous stem and has position -1. */
+    int beforePos;                  /* most recent stem that doesn't overlap to SC and has position -len. */
+    float score;                     /* score of the sum of base pairing probability matrix */
+    std::vector<float> baseScore;
+    float stacking;                  /* the mean of stacking energy */
+    float stemStacking;              /* the mean of 1-continuous stacking energy */
+
+public:
+    StemCandidate() : numSeq(0), length(0), position(0), distance(0), 
+                      rvposition(0), rvscnumber(0), contPos(-1), beforePos(0),
+                      score(0), stacking(0), stemStacking(0) {}
+    StemCandidate(int numSeq, int length) : numSeq(numSeq), length(length), 
+                                           substr(numSeq), rvstr(numSeq), 
+                                           contPos(-1) { }
+
+    void SetNumSeq(int num) { numSeq = num; }
+    void SetLength(int len) { length = len; }
+    void SetNumSubstr(int num) {
+        substr.resize(num);
+       for(int i = 0; i < num; i++) {
+           string &tmpStr = substr[i];
+           tmpStr = "";
+           substr[i] = tmpStr;
+       }
+    }
+    void SetNumRvstr(int num) {
+        rvstr.resize(num);
+       
+       for(int i = 0; i < num; i++) {
+           string &tmpStr = rvstr[i];
+           tmpStr = "";
+           rvstr[i] = tmpStr;
+       }
+    }
+    void SetPosition(int pos) { position = pos; }
+
+    void AddSubstr(int num, char word) {
+       std::string &tmpStr = substr[num];
+       tmpStr += word;
+       substr[num] = tmpStr;
+    }
+
+    void AddRvstr(int num, char word) {
+       std::string &tmpStr = rvstr[num];
+       tmpStr += word;
+       rvstr[num] = tmpStr;
+    }
+
+    void AddBaseScore(float score) {
+        baseScore.push_back(score);
+    }
+
+    void SetRvposition(int pos) { rvposition = pos; }
+    void SetRvscnumber(int num) { rvscnumber = num; }
+    void SetContPos(int pos) { contPos = pos; }
+    void SetBeforePos(int pos) { beforePos = pos; }
+    void SetDistance(int d) { distance = d; }
+    void SetScore(float s) { score = s; }
+    void AddScore(float s) { score += s; }
+    void SetStacking(float s) { stacking = s; }
+    void AddStacking(float s) { stacking += s; }
+    void SetStemStacking(float s) { stemStacking = s; }
+    int  GetNumSeq() const { return numSeq; }
+    int  GetLength() const { return length; }
+    int  GetPosition() const { return position; }
+    
+    string GetSubstr(int num) const { 
+       const std::string &tmpStr = substr[num];
+       return tmpStr;
+    }
+    string GetRvstr(int num) const {
+       const std::string &tmpStr = rvstr[num];
+       return tmpStr;
+    }
+    float GetBaseScore(int i) const  {
+        return baseScore[i];
+    }
+    int GetRvposition() const {
+       return rvposition;
+    }
+    int GetRvscnumber() const {
+       return rvscnumber;
+    }
+    int GetContPos() const {
+       return contPos;
+    }
+    int GetBeforePos() const {
+       return beforePos;
+    }
+    int GetDistance() const {
+        return distance;
+    }
+    float GetScore() const {
+       return score;
+    }
+    float GetStacking() const  {
+       return stacking;
+    }
+    float GetStemStacking() const {
+       return stemStacking;
+    }
+};
+}
+#endif // __STEMCANDIDATE_HPP__
diff --git a/binaries/src/mafft/extensions/mxscarna_src/Util.hpp b/binaries/src/mafft/extensions/mxscarna_src/Util.hpp
new file mode 100644 (file)
index 0000000..eab7667
--- /dev/null
@@ -0,0 +1,102 @@
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <algorithm>
+#include <cassert>
+#include <cstdio>
+#include <cstdlib>
+#include <cstdarg>
+#include <cstring>
+#include <cmath>
+#include <cctype>
+#include <climits>
+#include <cfloat>
+#include <ctime>
+#include <fstream>
+#include <functional>
+#include <iomanip>
+#include <iostream>
+#include <iterator>
+#include <list>
+#include <map>
+#include <numeric>
+#include <string>
+#include <sstream>
+#include <stack>
+#include <vector>
+#include <fcntl.h>
+#include <unistd.h>
+//#include <pthread.h> // mingw de error, by katoh
+#include <signal.h>
+
+namespace ProbCons {
+    
+const double IMPOSSIBLE = -FLT_MAX + 1000;
+const double IMPOSSIBLEDBL = -DBL_MAX + 10000;
+
+namespace MXSCARNA {
+template <typename T>
+inline bool
+IsPossible(const T& v) { 
+    return (v > (IMPOSSIBLE + 1.0e-5));
+}
+
+template <typename T>
+inline T
+logSum(const T& a, const T& b)
+{
+    if (a >= b) {
+       return a + log(1.0 + exp(b - a));
+    } else {
+       return b + log(1.0 + exp(a - b));
+    }
+}
+
+template <typename T>
+inline T
+logSub(const T&a, const T& b)
+{
+  if(a > b) {
+    return log(exp(a) - exp(b));
+  }
+  else {
+    return log(exp(a) - exp(b));
+  }
+}
+
+template <typename T>
+inline T
+logSum(const T& a, const T& b, const T& c)
+{
+    if (a >= b) {
+       if( a >= c ) {
+           return a + log(1.0 + (exp(b - a) + exp(c - a)));
+       }
+       else {
+           if( b >= c) {
+               return b + log(exp(a - b) + 1.0 + exp(c - b));
+           }
+       }
+    }
+    return c + log(exp(a - c) + exp(b - c) + 1.0);
+}
+
+}
+
+template <typename T>
+inline T
+logSumExp(const T& x, const T& y)
+{
+    if(x == y) return x + 0.69314718055;
+    double vmin = std::min(x, y);
+    double vmax = std::max(x, y);
+    
+    if (vmax > vmin + 50) {
+       return vmax;
+    }
+    else {
+       return vmax + std::log (std::exp (vmin - vmax) + 1.0);
+    }
+}
+}
+#endif /* UTIL_H */
diff --git a/binaries/src/mafft/extensions/mxscarna_src/config.h b/binaries/src/mafft/extensions/mxscarna_src/config.h
new file mode 100644 (file)
index 0000000..51c27b8
--- /dev/null
@@ -0,0 +1,86 @@
+/* config.h.  Generated by configure.  */
+/* config.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define to 1 if you have the `erand48' function. */
+#define HAVE_ERAND48 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strchr' function. */
+#define HAVE_STRCHR 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Name of package */
+#define PACKAGE "ViennaRNA"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "rna@tbi.univie.ac.at"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "ViennaRNA"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "ViennaRNA 1.6.1"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "ViennaRNA"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "1.6.1"
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* only for gcc */
+#define UNUSED __attribute__ ((unused))
+
+/* Version number of package */
+#define VERSION "1.6.1"
+
+/* Define if using the dmalloc debugging malloc package */
+/* #undef WITH_DMALLOC */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+   calls it, or to nothing if 'inline' is not supported under any name.  */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `unsigned' if <sys/types.h> does not define. */
+/* #undef size_t */
diff --git a/binaries/src/mafft/extensions/mxscarna_src/nrutil.h b/binaries/src/mafft/extensions/mxscarna_src/nrutil.h
new file mode 100644 (file)
index 0000000..3a33874
--- /dev/null
@@ -0,0 +1,991 @@
+/*
+  McCaskill's Algorithm -- The algorithm calculates a base paring probability matrix from the input of one sequence.
+
+  $Id: nrutil.h,v 1.0 2005/10/20 14:22 $;
+
+  Copyright (C) 2005 Yasuo Tabei <tabei@cb.k.u-tokyo.ac.jp>
+
+  This is free software with ABSOLUTELY NO WARRANTY.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+*/
+
+#ifndef _NR_UTIL_H_
+#define _NR_UTIL_H_
+#include <string>
+#include <cmath>
+#include <complex>
+#include <iostream>
+#include <cstdlib> // by katoh
+
+using namespace std;
+
+typedef double DP;
+
+template<class T>
+inline const T SQR(const T a) {return a*a;}
+
+template<class T>
+inline const T MAX(const T &a, const T &b)
+{return b > a ? (b) : (a);}
+
+inline float MAX(const double &a, const float &b)
+{return b > a ? (b) : float(a);}
+
+inline float MAX(const float &a, const double &b)
+{return b > a ? float(b) : (a);}
+
+template<class T>
+inline const T MIN(const T &a, const T &b)
+{return b < a ? (b) : (a);}
+
+inline float MIN(const double &a, const float &b)
+{return b < a ? (b) : float(a);}
+
+inline float MIN(const float &a, const double &b)
+{return b < a ? float(b) : (a);}
+
+template<class T>
+inline const T SIGN(const T &a, const T &b)
+{return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
+
+inline float SIGN(const float &a, const double &b)
+{return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
+
+inline float SIGN(const double &a, const float &b)
+{return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
+
+template<class T>
+inline void SWAP(T &a, T &b)
+{T dum=a; a=b; b=dum;}
+namespace NR {
+    inline void nrerror(const string error_text)
+// Numerical Recipes standard error handler
+       {
+           cerr << "Numerical Recipes run-time error..." << endl;
+           cerr << error_text << endl;
+           cerr << "...now exiting to system..." << endl;
+           exit(1);
+       }
+}
+
+template <class T>
+class NRVec {
+ private:
+    int nn; // size of array. upper index is nn-1
+    T *v;
+ public:
+    NRVec();
+    explicit NRVec(int n);    // Zero-based array
+    NRVec(const T &a, int n); //initialize to constant value
+    NRVec(const T *a, int n); // Initialize to array
+    NRVec(const NRVec &rhs);  // Copy constructor
+    NRVec & operator=(const NRVec &rhs); //assignment
+    NRVec & operator=(const T &a); //assign a to every element
+    inline T & operator[](const int i); //i¡Çth element
+    inline const T & operator[](const int i) const;
+    void Allocator(int i);
+    inline int size() const;
+    ~NRVec();
+};
+
+template <class T>
+NRVec<T>::NRVec() : nn(0), v(0) {}
+
+template <class T>
+NRVec<T>::NRVec(int n) : nn(n), v(new T[n]) {}
+
+template <class T>
+NRVec<T>::NRVec(const T& a, int n) : nn(n), v(new T[n])
+{
+    for(int i=0; i<n; i++)
+       v[i] = a;
+}
+
+template <class T>
+NRVec<T>::NRVec(const T *a, int n) : nn(n), v(new T[n])
+{
+for(int i=0; i<n; i++)
+    v[i] = *a++;
+}
+
+template <class T>
+void NRVec<T>::Allocator(int n = 0)
+{
+   v = new T[n];
+}
+
+template <class T>
+NRVec<T>::NRVec(const NRVec<T> &rhs) : nn(rhs.nn), v(new T[nn])
+{
+    for(int i=0; i<nn; i++)
+       v[i] = rhs[i];
+}
+
+template <class T>
+NRVec<T> & NRVec<T>::operator=(const NRVec<T> &rhs)
+// postcondition: normal assignment via copying has been performed;
+// if vector and rhs were different sizes, vector
+// has been resized to match the size of rhs
+{
+    if (this != &rhs)
+{
+    if (nn != rhs.nn) {
+       if (v != 0) delete [] (v);
+       nn=rhs.nn;
+       v= new T[nn];
+    }
+    for (int i=0; i<nn; i++)
+       v[i]=rhs[i];
+}
+    return *this;
+}
+
+template <class T>
+NRVec<T> & NRVec<T>::operator=(const T &a) //assign a to every element
+{
+    for (int i=0; i<nn; i++)
+       v[i]=a;
+    return *this;
+}
+
+template <class T>
+inline T & NRVec<T>::operator[](const int i) //subscripting
+{
+    return v[i];
+}
+
+template <class T>
+inline const T & NRVec<T>::operator[](const int i) const //subscripting
+{
+    return v[i];
+}
+
+template <class T>
+inline int NRVec<T>::size() const
+{
+    return nn;
+}
+
+template <class T>
+NRVec<T>::~NRVec()
+{
+    if (v != 0)
+       delete[] (v);
+}
+
+template <class T>
+class NRMat {
+ private:
+    int nn;
+    int mm;
+    T **v;
+ public:
+    NRMat();
+    NRMat(int n, int m); // Zero-based array
+    NRMat(const T &a, int n, int m); //Initialize to constant
+    NRMat(const T *a, int n, int m); // Initialize to array
+    NRMat(const NRMat &rhs); // Copy constructor
+    void Allocator(int n, int m);
+    void Allocator(const T &a, int n, int m);
+    void Allocator(const T *a, int n, int m);
+    NRMat & operator=(const NRMat &rhs); //assignment
+    NRMat & operator=(const T &a); //assign a to every element
+    inline T* operator[](const int i); //subscripting: pointer to row i
+    inline const T* operator[](const int i) const;
+    inline T &  ref(const int i, const int j);
+    inline const T ref(const int i, const int j) const;
+    inline int nrows() const;
+    inline int ncols() const;
+    ~NRMat();
+};
+
+template <class T>
+NRMat<T>::NRMat() : nn(0), mm(0), v(0) {}
+
+template <class T>
+NRMat<T>::NRMat(int n, int m) : nn(n), mm(m), v(new T*[n])
+{
+    v[0] = new T[m*n];
+    for (int i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+}
+
+template <class T>
+NRMat<T>::NRMat(const T &a, int n, int m) : nn(n), mm(m), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[m*n];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+    for (i=0; i< n; i++)
+       for (j=0; j<m; j++)
+           v[i][j] = a;
+}
+
+template <class T>
+NRMat<T>::NRMat(const T *a, int n, int m) : nn(n), mm(m), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[m*n];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+    for (i=0; i< n; i++)
+       for (j=0; j<m; j++)
+           v[i][j] = *a++;
+}
+
+template <class T> 
+void NRMat<T>::Allocator(int n, int m)
+{
+    if( v != 0 ) {
+       delete[] (v[0]); delete (v);
+    }
+
+    nn = n; mm = m; v = new T*[n];
+    
+    v[0] = new T[m*n];
+    for (int i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+}
+
+template <class T>
+void NRMat<T>::Allocator(const T &a, int n, int m)
+{
+    if( v != 0 ) {
+       delete[] (v[0]); delete (v);
+    }
+
+    int i,j;
+
+    nn = n; mm = m; v = new T*[n];
+
+    v[0] = new T[m*n];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+    for (i=0; i< n; i++)
+       for (j=0; j<m; j++)
+           v[i][j] = a;
+}
+
+template <class T>
+void NRMat<T>::Allocator(const T *a, int n, int m)
+{
+    if( v != 0 ) {
+       delete[] (v[0]); delete (v);
+    }
+
+    int i,j;
+
+    nn = n; mm = m; v = new T*[n];
+    
+    v[0] = new T[m*n];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + m;
+    for (i=0; i< n; i++)
+       for (j=0; j<m; j++)
+           v[i][j] = *a++;
+}
+
+template <class T>
+NRMat<T>::NRMat(const NRMat &rhs) : nn(rhs.nn), mm(rhs.mm), v(new T*[nn])
+{
+    int i,j;
+    v[0] = new T[mm*nn];
+    for (i=1; i< nn; i++)
+       v[i] = v[i-1] + mm;
+    for (i=0; i< nn; i++)
+       for (j=0; j<mm; j++)
+           v[i][j] = rhs[i][j];
+}
+template <class T>
+NRMat<T> & NRMat<T>::operator=(const NRMat<T> &rhs)
+// postcondition: normal assignment via copying has been performed;
+// if matrix and rhs were different sizes, matrix
+// has been resized to match the size of rhs
+{
+    if (this != &rhs) {
+       int i,j;
+       if (nn != rhs.nn || mm != rhs.mm) {
+           if (v != 0) {
+               delete[] (v[0]);
+               delete[] (v);
+           }
+           nn=rhs.nn;
+           mm=rhs.mm;
+           v = new T*[nn];
+           v[0] = new T[mm*nn];
+       }
+       for (i=1; i< nn; i++)
+           v[i] = v[i-1] + mm;
+       for (i=0; i< nn; i++)
+           for (j=0; j<mm; j++)
+               v[i][j] = rhs[i][j];
+    }
+    return *this;
+}
+
+template <class T>
+NRMat<T> & NRMat<T>::operator=(const T &a) //assign a to every element
+{
+    for (int i=0; i< nn; i++)
+       for (int j=0; j<mm; j++)
+           v[i][j] = a;
+    return *this;
+}
+
+template <class T>
+inline T* NRMat<T>::operator[](const int i) //subscripting: pointer to row i
+{
+    return v[i];
+}
+
+template <class T>
+inline const T* NRMat<T>::operator[](const int i) const
+{
+    return v[i];
+}
+
+template <class T>
+inline T &  NRMat<T>::ref(const int i, const int j)
+{
+    return v[i][j];
+}
+
+template <class T>
+inline const T NRMat<T>::ref(const int i, const int j) const
+{
+    return v[i][j];
+}
+
+template <class T>
+inline int NRMat<T>::nrows() const
+{
+    return nn;
+}
+
+template <class T>
+inline int NRMat<T>::ncols() const
+{
+    return mm;
+}
+
+template <class T>
+NRMat<T>::~NRMat()
+{
+    if (v != 0) {
+       delete[] (v[0]);
+       delete[] (v);
+    }
+}
+
+template <class T>
+class NRMat3d {
+ private:
+    int nn;
+    int mm;
+    int kk;
+    T ***v;
+ public:
+    NRMat3d();
+    NRMat3d(int n, int m, int k);
+    inline void Allocator(int n, int m, int k);
+    inline T** operator[](const int i); //subscripting: pointer to row i
+    inline const T* const * operator[](const int i) const;
+    inline int dim1() const;
+    inline int dim2() const;
+    inline int dim3() const;
+    ~NRMat3d();
+};
+
+template <class T>
+NRMat3d<T>::NRMat3d(): nn(0), mm(0), kk(0), v(0) {}
+template <class T>
+NRMat3d<T>::NRMat3d(int n, int m, int k) : nn(n), mm(m), kk(k), v(new T**[n])
+{
+    int i,j;
+    v[0] = new T*[n*m];
+    v[0][0] = new T[n*m*k];
+    for(j=1; j<m; j++)
+       v[0][j] = v[0][j-1] + k;
+    for(i=1; i<n; i++) {
+       v[i] = v[i-1] + m;
+       v[i][0] = v[i-1][0] + m*k;
+       for(j=1; j<m; j++)
+           v[i][j] = v[i][j-1] + k;
+    }
+}
+
+template <class T>
+inline void NRMat3d<T>::Allocator(int n, int m, int k) 
+{
+    int i,j;
+    v[0] = new T*[n*m];
+    v[0][0] = new T[n*m*k];
+    for(j=1; j<m; j++)
+       v[0][j] = v[0][j-1] + k;
+    for(i=1; i<n; i++) {
+       v[i] = v[i-1] + m;
+       v[i][0] = v[i-1][0] + m*k;
+       for(j=1; j<m; j++)
+           v[i][j] = v[i][j-1] + k;
+    }
+}
+
+template <class T>
+inline T** NRMat3d<T>::operator[](const int i) //subscripting: pointer to row i
+{
+    return v[i];
+}
+
+template <class T>
+inline const T* const * NRMat3d<T>::operator[](const int i) const
+{
+    return v[i];
+}
+
+template <class T>
+inline int NRMat3d<T>::dim1() const
+{
+    return nn;
+}
+
+template <class T>
+inline int NRMat3d<T>::dim2() const
+{
+    return mm;
+}
+
+template <class T>
+inline int NRMat3d<T>::dim3() const
+{
+    return kk;
+}
+
+template <class T>
+NRMat3d<T>::~NRMat3d()
+{
+    if (v != 0) {
+       delete[] (v[0][0]);
+       delete[] (v[0]);
+       delete[] (v);
+    }
+}
+
+//The next 3 classes are used in artihmetic coding, Huffman coding, and
+//wavelet transforms respectively. This is as good a place as any to put them!
+class arithcode {
+ private:
+    NRVec<unsigned long> *ilob_p,*iupb_p,*ncumfq_p;
+ public:
+    NRVec<unsigned long> &ilob,&iupb,&ncumfq;
+    unsigned long jdif,nc,minint,nch,ncum,nrad;
+    arithcode(unsigned long n1, unsigned long n2, unsigned long n3)
+       : ilob_p(new NRVec<unsigned long>(n1)),
+       iupb_p(new NRVec<unsigned long>(n2)),
+       ncumfq_p(new NRVec<unsigned long>(n3)),
+       ilob(*ilob_p),iupb(*iupb_p),ncumfq(*ncumfq_p) {}
+    ~arithcode() {
+       if (ilob_p != 0) delete ilob_p;
+       if (iupb_p != 0) delete iupb_p;
+       if (ncumfq_p != 0) delete ncumfq_p;
+    }
+};
+
+class huffcode {
+ private:
+    NRVec<unsigned long> *icod_p,*ncod_p,*left_p,*right_p;
+ public:
+    NRVec<unsigned long> &icod,&ncod,&left,&right;
+    int nch,nodemax;
+    huffcode(unsigned long n1, unsigned long n2, unsigned long n3,
+            unsigned long n4) :
+       icod_p(new NRVec<unsigned long>(n1)),
+       ncod_p(new NRVec<unsigned long>(n2)),
+       left_p(new NRVec<unsigned long>(n3)),
+       right_p(new NRVec<unsigned long>(n4)),
+       icod(*icod_p),ncod(*ncod_p),left(*left_p),right(*right_p) {}
+    ~huffcode() {
+       if (icod_p != 0) delete icod_p;
+       if (ncod_p != 0) delete ncod_p;
+       if (left_p != 0) delete left_p;
+       if (right_p != 0) delete right_p;
+    }
+};
+
+class wavefilt {
+ private:
+    NRVec<DP> *cc_p,*cr_p;
+ public:
+    int ncof,ioff,joff;
+    NRVec<DP> &cc,&cr;
+    wavefilt() : cc(*cc_p),cr(*cr_p) {}
+    wavefilt(const DP *a, const int n) : //initialize to array
+       cc_p(new NRVec<DP>(n)),cr_p(new NRVec<DP>(n)),
+       ncof(n),ioff(-(n >> 1)),joff(-(n >> 1)),cc(*cc_p),cr(*cr_p) {
+       int i;
+       for (i=0; i<n; i++)
+           cc[i] = *a++;
+       DP sig = -1.0;
+       for (i=0; i<n; i++) {
+           cr[n-1-i]=sig*cc[i];
+           sig = -sig;
+       }
+    }
+    ~wavefilt() {
+       if (cc_p != 0) delete cc_p;
+       if (cr_p != 0) delete cr_p;
+    }
+};
+
+
+/* Triangle Matrix Class
+   ---------------------------------------------------------
+   |v[0][0]|v[0][1]|      |            |         |v[0][n-1]|
+   |-------|-------|------|------------|---------|---------|
+   |v[1][1]|v[1][2]|      |            |v[1][n-2]|         |
+   |-------|-------|------|------------|---------|---------|
+   |       |       |      |            |         |         |
+   |-------|-------|------|------------|---------|---------|
+   |       |                                               |     
+   |       |                                               |
+   |       |                                               |
+   |-------|-----------------------------------------------|
+   |       |                                               |
+   |-------|-----------------------------------------------|
+   |v[n-2][0]|v[n-2][1]|                                   |                         
+   |-------|-----------------------------------------------|
+   |v[n-1][0]|                                             |  
+   |-------------------------------------------------------|
+ */
+template <class T>
+class Trimat {
+ private:
+    int nn;
+    T **v;
+    inline T* operator[](const int i); //subscripting: pointer to row i
+    inline const T* operator[](const int i) const;
+ public:
+    Trimat();
+    Trimat(int n); // Zero-based array
+    Trimat(const T &a, int n); //Initialize to constant
+    Trimat(const T *a, int n); // Initialize to array
+    Trimat(const Trimat &rhs); // Copy constructor
+    void Allocator(int n);
+    void Allocator(const T &a, int n);
+    void Allocator(const T *a, int n);
+    Trimat & operator=(const Trimat &rhs); //assignment
+    Trimat & operator=(const T &a); //assign a to every element
+    inline T & ref(const int i, const int j);
+    inline T * getPointer(const int i, const int j);
+    inline T * begin() const;
+    inline T * end() const;
+    inline const T ref(const int i, const int j) const;
+    inline int nrows() const;
+    ~Trimat();
+};
+
+template <class T>
+Trimat<T>::Trimat() : nn(0), v(0) {}
+
+template <class T>
+Trimat<T>::Trimat(int n) : nn(n), v(new T*[n])
+{
+    v[0] = new T[n*(n+1)/2];
+    for (int i=1; i< n; i++) 
+       v[i] = v[i-1] + (n-i+1);
+
+    for (int i=0; i< n; i++)
+       for (int j=0; j<(n-i); j++)
+           v[i][j] = 0;
+}
+template <class T>
+Trimat<T>::Trimat(const T &a, int n) : nn(n), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + (n-i+1);
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = a;
+}
+
+template <class T>
+Trimat<T>::Trimat(const T *a, int n) : nn(n), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + (n-i+1);
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = *a++;
+}
+
+
+template <class T>
+void Trimat<T>::Allocator(int n)
+{
+    nn = n; v = new T*[n];
+
+    v[0] = new T[n*(n+1)/2];
+    for (int i=1; i< n; i++)
+       v[i] = v[i-1] + (n-i+1);
+}
+
+template <class T>
+void Trimat<T>::Allocator(const T &a, int n)
+{
+    nn = n; v = new T*[n];
+
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i < n; i++)
+       v[i] = v[i-1] + (n-i+1);
+    for (i=0; i < n; i++)
+       for (j=0; j < (n-i); j++)
+           v[i][j] = a;
+}
+
+template <class T>
+void Trimat<T>::Allocator(const T *a, int n)
+{
+    nn = n; v = new T*[n];
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + (n-i+1);
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = *a++;
+}
+
+
+template <class T>
+Trimat<T>::Trimat(const Trimat &rhs) : nn(rhs.nn), v(new T*[nn])
+{
+    int i,j;
+    v[0] = new T[nn*(nn+1)/2];
+    for (i=1; i< nn; i++)
+       v[i] = v[i-1] + (nn-i+1);
+    for (i=0; i< nn; i++)
+       for (j=0; j<(nn-i); j++)
+           v[i][j] = rhs[i][j];
+}
+template <class T>
+Trimat<T> & Trimat<T>::operator=(const Trimat<T> &rhs)
+// postcondition: normal assignment via copying has been performed;
+// if matrix and rhs were different sizes, matrix
+// has been resized to match the size of rhs
+{
+    if (this != &rhs) {
+       int i,j;
+       if (nn != rhs.nn) {
+           if (v != 0) {
+               delete[] (v[0]);
+               delete[] (v);
+           }
+           nn=rhs.nn;
+           v = new T*[nn];
+           v[0] = new T[nn*(nn+1)/2];
+       }
+       for (i=1; i< nn; i++)
+           v[i] = v[i-1] + (nn-i+1);
+       for (i=0; i< nn; i++)
+           for (j=0; j<(nn-i); j++)
+               v[i][j] = rhs[i][j];
+    }
+    return *this;
+}
+
+template <class T>
+Trimat<T> & Trimat<T>::operator=(const T &a) //assign a to every element
+{
+    for (int i=0; i< nn; i++)
+       for (int j=0; j<nn-i; j++)
+           v[i][j] = a;
+    return *this;
+}
+
+template <class T>
+inline T &  Trimat<T>::ref(const int i, const int j)
+{
+    return v[i][j-i];
+}
+
+template <class T>
+inline const T Trimat<T>::ref(const int i, const int j) const
+{
+    return v[i][j-i];
+}
+
+template <class T>
+inline T * Trimat<T>::getPointer(const int i, const int j) 
+{
+    return &v[i][j-i];
+}
+
+template <class T>
+inline T * Trimat<T>::begin() const
+{
+    return &v[0][0];
+}
+
+template <class T>
+inline T * Trimat<T>::end() const
+{
+    return (&v[nn-1][0] + 1);
+}
+
+template <class T>
+inline int Trimat<T>::nrows() const
+{
+    return nn;
+}
+
+template <class T>
+Trimat<T>::~Trimat()
+{
+    if (v != 0) {
+       delete[] (v[0]);
+       delete[] (v);
+    }
+}
+
+
+/* Triangle Vertical Matrix Class
+   ---------------------------------------------------------
+   |v[0][0]|v[1][0]|      |            |         |v[n-1][0]|
+   |-------|-------|------|------------|---------|---------|
+   |v[0][1]|v[1][1]|      |            |v[n-2][1]|         |
+   |-------|-------|------|------------|---------|---------|
+   |       |       |      |            |         |         |
+   |-------|-------|------|------------|---------|---------|
+   |       |                                               |     
+   |       |                                               |
+   |       |                                               |
+   |-------|-----------------------------------------------|
+   |       |                                               |
+   |-------|-----------------------------------------------|
+   |v[0][n-2]|v[n-2][n-2]|                                   |                         
+   |-------|-----------------------------------------------|
+   |v[0][n-1]|                                             |  
+   |-------------------------------------------------------|
+ */
+template <class T>
+class TriVertMat {
+ private:
+    int nn;
+    T **v;
+    inline T* operator[](const int i); //subscripting: pointer to row i
+    inline const T* operator[](const int i) const;
+ public:
+    TriVertMat();
+    TriVertMat(int n); // Zero-based array
+    TriVertMat(const T &a, int n); //Initialize to constant
+    TriVertMat(const T *a, int n); // Initialize to array
+    TriVertMat(const TriVertMat &rhs); // Copy constructor
+    void Allocator(int n);
+    void Allocator(const T &a, int n);
+    void Allocator(const T *a, int n);
+    TriVertMat & operator=(const TriVertMat &rhs); //assignment
+    TriVertMat & operator=(const T &a); //assign a to every element
+    inline T & ref(const int i, const int j);
+    inline T * getPointer(const int i, const int j);
+    inline const T ref(const int i, const int j) const;
+    inline int nrows() const;
+    ~TriVertMat();
+};
+
+template <class T>
+TriVertMat<T>::TriVertMat() : nn(0), v(0) {}
+
+template <class T>
+TriVertMat<T>::TriVertMat(int n) : nn(n), v(new T*[n])
+{
+    v[0] = new T[n*(n+1)/2];
+    for (int i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+}
+
+template <class T>
+TriVertMat<T>::TriVertMat(const T &a, int n) : nn(n), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = a;
+}
+
+template <class T>
+TriVertMat<T>::TriVertMat(const T *a, int n) : nn(n), v(new T*[n])
+{
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = *a++;
+}
+
+
+template <class T>
+void TriVertMat<T>::Allocator(int n)
+{
+    nn = n; v = new T*[n];
+
+    v[0] = new T[n*(n+1)/2];
+    for (int i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+}
+
+template <class T>
+void TriVertMat<T>::Allocator(const T &a, int n)
+{
+    nn = n; v = new T*[n];
+
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = a;
+}
+
+template <class T>
+void TriVertMat<T>::Allocator(const T *a, int n)
+{
+    nn = n; v = new T*[n];
+    int i,j;
+    v[0] = new T[n*(n+1)/2];
+    for (i=1; i< n; i++)
+       v[i] = v[i-1] + i;
+    for (i=0; i< n; i++)
+       for (j=0; j<(n-i); j++)
+           v[i][j] = *a++;
+}
+
+
+template <class T>
+TriVertMat<T>::TriVertMat(const TriVertMat &rhs) : nn(rhs.nn), v(new T*[nn])
+{
+    int i,j;
+    v[0] = new T[nn*(nn+1)/2];
+    for (i=1; i< nn; i++)
+       v[i] = v[i-1] + i;
+    for (i=0; i< nn; i++)
+       for (j=0; j<(nn-i); j++)
+           v[i][j] = rhs[i][j];
+}
+template <class T>
+TriVertMat<T> & TriVertMat<T>::operator=(const TriVertMat<T> &rhs)
+// postcondition: normal assignment via copying has been performed;
+// if matrix and rhs were different sizes, matrix
+// has been resized to match the size of rhs
+{
+    if (this != &rhs) {
+       int i,j;
+       if (nn != rhs.nn) {
+           if (v != 0) {
+               delete[] (v[0]);
+               delete[] (v);
+           }
+           nn=rhs.nn;
+           v = new T*[nn];
+           v[0] = new T[nn*(nn+1)/2];
+       }
+       for (i=1; i< nn; i++)
+           v[i] = v[i-1] + i;
+       for (i=0; i< nn; i++)
+           for (j=0; j<(nn-i); j++)
+               v[i][j] = rhs[i][j];
+    }
+    return *this;
+}
+
+template <class T>
+TriVertMat<T> & TriVertMat<T>::operator=(const T &a) //assign a to every element
+{
+    for (int i=0; i< nn; i++)
+       for (int j=0; j<nn-i; j++)
+           v[i][j] = a;
+    return *this;
+}
+
+template <class T>
+inline T &  TriVertMat<T>::ref(const int i, const int j)
+{
+    return v[j][i];
+}
+
+template <class T>
+inline const T TriVertMat<T>::ref(const int i, const int j) const
+{
+    return v[j][i];
+}
+
+template <class T>
+inline T * TriVertMat<T>::getPointer(const int i, const int j) 
+{
+    return &v[j][i];
+}
+
+template <class T>
+inline int TriVertMat<T>::nrows() const
+{
+    return nn;
+}
+
+template <class T>
+TriVertMat<T>::~TriVertMat()
+{
+    if (v != 0) {
+       delete[] (v[0]);
+       delete[] (v);
+    }
+}
+
+
+//Overloaded complex operations to handle mixed float and double
+//This takes care of e.g. 1.0/z, z complex<float>
+inline const complex<float> operator+(const double &a,
+                                     const complex<float> &b) { return float(a)+b; }
+inline const complex<float> operator+(const complex<float> &a,
+                                     const double &b) { return a+float(b); }
+inline const complex<float> operator-(const double &a,
+                                     const complex<float> &b) { return float(a)-b; }
+inline const complex<float> operator-(const complex<float> &a,
+                                     const double &b) { return a-float(b); }
+inline const complex<float> operator*(const double &a,
+                                     const complex<float> &b) { return float(a)*b; }
+inline const complex<float> operator*(const complex<float> &a,
+                                     const double &b) { return a*float(b); }
+inline const complex<float> operator/(const double &a,
+                                     const complex<float> &b) { return float(a)/b; }
+inline const complex<float> operator/(const complex<float> &a,
+                                     const double &b) { return a/float(b); }
+//some compilers choke on pow(float,double) in single precision. also atan2
+inline float pow (float x, double y) {return pow(double(x),y);}
+inline float pow (double x, float y) {return pow(x,double(y));}
+inline float atan2 (float x, double y) {return atan2(double(x),y);}
+inline float atan2 (double x, float y) {return atan2(x,double(y));}
+
+#endif /* _NR_UTIL_H_ */
diff --git a/binaries/src/mafft/extensions/mxscarna_src/params-weird b/binaries/src/mafft/extensions/mxscarna_src/params-weird
new file mode 100644 (file)
index 0000000..58601f4
--- /dev/null
@@ -0,0 +1,10 @@
+0.8969780803 0.0000000001 0.0000000001 0.0515111387 0.0515111387 
+0.0006874357 0.0006874357 0.0502248816 0.0502248816 
+0.1025763303 0.1025763303 0.2891978920 0.2891978920 
+ACGTN
+0.1907979101 
+0.0187792275 0.2023714036 
+0.0437292010 0.0242512580 0.2525959611 
+0.0171148051 0.0289713815 0.0146772768 0.1689696163 
+0.0000359111 0.0000737346 0.0000853324 0.0000768761 0.0000296087 
+0.1390289217 0.2925130725 0.1882306933 0.2944687903 0.0016553127 
diff --git a/binaries/src/mafft/extensions/mxscarna_src/postProcessings.cpp b/binaries/src/mafft/extensions/mxscarna_src/postProcessings.cpp
new file mode 100644 (file)
index 0000000..1028630
--- /dev/null
@@ -0,0 +1,91 @@
+//////////////////////////////////////////////////////////////////////////////////////
+// postProcessings.cpp
+// 
+// several post process functions after aligning two profile stem candidate sequences
+//////////////////////////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include "scarna.hpp"
+#include "StemCandidate.hpp"
+#include <vector>
+#include <string>
+
+using namespace::MXSCARNA;
+
+void printStructure(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2, std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2);
+
+void removeConflicts(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2, std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2)
+{
+    int size = matchPSCS1->size();
+    
+    std::vector<int> found(size, 0);
+    for(int k = size - 1; k >= 0; k--) {
+       int i    = matchPSCS1->at(k);
+       int i_rv = pscs1->at(i).GetRvscnumber();
+       int j    = matchPSCS2->at(k);
+       int j_rv = pscs2->at(j).GetRvscnumber();
+       
+       found[k] = 0;
+       
+       for(int m = size - 1; m >= 0; m--) {
+           if ( (matchPSCS1->at(m) == i_rv) && (matchPSCS2->at(m) == j_rv) ) {
+               found[k] = 1;
+               break;
+           }
+       }
+    }
+
+    int pt = 0;
+    for(int k = 0; k < size; k++) {
+       matchPSCS1->at(pt) = matchPSCS1->at(k);
+       matchPSCS2->at(pt) = matchPSCS2->at(k);
+       if(found[k] == 1) ++pt; 
+    }
+
+    matchPSCS1->resize(pt);
+    matchPSCS2->resize(pt);
+    
+    //printStructure (pscs1, pscs2, matchPSCS1, matchPSCS2);
+}
+
+void printStructure(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2, std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2)
+{
+    int size = matchPSCS1->size();
+    int len  = WORDLENGTH;
+    std::vector<char> structure1(100, '.');
+    std::vector<char> structure2(100, '.');
+    for(int k = 0; k < size; k++) {
+       int i    = matchPSCS1->at(k);
+       int pos1 = pscs1->at(i).GetPosition();
+       int j    = matchPSCS2->at(k);
+       int pos2 = pscs2->at(j).GetPosition();
+       for(int l = 0; l < len; l++) {
+           if(pscs1->at(i).GetDistance() > 0) {
+               structure1[pos1 + l] = '(';
+           }
+           else {
+               structure1[pos1 + l] = ')';
+           }
+       
+           if(pscs2->at(j).GetDistance() > 0) {
+               structure2[pos2 + l] = '(';
+           }
+           else {
+               structure2[pos2 + l] = ')';
+           }
+       }
+       /*
+       std::cout << i << "\t" << pscs1->at(i).GetLength() << "\t" << pscs1->at(i).GetPosition() << "\t" << pscs1->at(i).GetRvposition() << "\t" << pscs1->at(i).GetDistance()  << "\t" << pscs1->at(i).GetContPos() << "\t" << pscs1->at(i).GetBeforePos() << "\t" << pscs1->at(i).GetRvscnumber() << endl;
+       */
+    }
+    size = structure1.size();
+    for(int k = 0; k < size; k++) {
+       std::cout << structure1[k];
+    }
+    std::cout << endl;
+    for(int k = 0; k < size; k++) {
+       std::cout << structure2[k];
+    }
+    std::cout << endl;
+}
+
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/CompareToRef.cc b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/CompareToRef.cc
new file mode 100644 (file)
index 0000000..142fa4c
--- /dev/null
@@ -0,0 +1,348 @@
+/////////////////////////////////////////////////////////////////
+// CompareToRef.cc
+//
+// Program for scoring alignments according to the SUM-OF-PAIRS
+// or COLUMN score.
+/////////////////////////////////////////////////////////////////
+
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <set>
+#include <limits>
+#include <cstdio>
+#include <cstdlib>
+#include <cerrno>
+#include <iomanip>
+
+const char CORE_BLOCK = 'h';
+typedef pair<int,int> PII;
+bool useCoreBlocks = false;
+bool useColScore = false;
+bool useCaps = false;
+bool useBaliAnnot = false;
+bool makeAnnot = false;
+
+/////////////////////////////////////////////////////////////////
+// Function prototypes
+/////////////////////////////////////////////////////////////////
+
+set<PII> ComputePairs (MultiSequence *align, bool isRef);
+set<VI> ComputeColumns (MultiSequence *align, bool isRef);
+string GetName (string s);
+set<int> coreCols;
+
+set<VI> refCols, testCols;
+set<PII> refPairs, testPairs;
+VI annotation;
+
+/////////////////////////////////////////////////////////////////
+// main()
+//
+// Main program.
+/////////////////////////////////////////////////////////////////
+
+int main (int argc, char **argv){
+
+  // check arguments
+  if (argc < 3){
+    cerr << "Usage: score TEST_ALIGNMENT REFERENCE_ALIGNMENT [BALIBASE_ANNOT_FILE] [-col] [-core] [-caps] [-annot FILENAME]" << endl;
+    exit (1);
+  }
+
+  // try opening file
+  FileBuffer infile (argv[1]);
+
+  MultiSequence *testAlign;
+  if (infile.fail()){
+    cerr << "ERROR: Could not open file '" << argv[1] << "' for reading." << endl;
+    testAlign = NULL;
+  }
+  else {
+    testAlign = new MultiSequence(); assert (testAlign);
+    testAlign->LoadMFA (infile);
+  }
+  infile.close();
+
+  MultiSequence *refAlign = new MultiSequence (string (argv[2])); assert (refAlign);
+  
+  string outFilename = "";
+
+  for (int i = 3; i < argc; i++){
+    if (strcmp (argv[i], "-core") == 0)
+      useCoreBlocks = true;
+    else if (strcmp (argv[i], "-col") == 0)
+      useColScore = true;
+    else if (strcmp (argv[i], "-caps") == 0)
+      useCaps = true;
+    else if (strcmp (argv[i], "-annot") == 0){
+      makeAnnot = true;
+      outFilename = string (argv[++i]);
+    }
+    else { // annotation file
+      useBaliAnnot = true;
+
+      ifstream annotFile (argv[i]);
+      if (annotFile.fail()){
+        cerr << "ERROR: Could not read BAliBASE annotation file." << endl;
+        exit (1);
+      }
+
+      SafeVector<int> *indices = refAlign->GetSequence(0)->GetMapping();
+
+      char buffer[10000];
+      while (annotFile.getline (buffer, 10000)){
+        istringstream ss;
+        ss.str (string (buffer));
+
+        string s;
+
+        if ((ss >> s) && s == string ("BPOS")){
+          while (ss >> s){
+            int begin=-1, end=-1;
+            if (sscanf (s.c_str(), "%d=%d", &begin, &end) == 2){
+              for (int i = (*indices)[begin]; i <= (*indices)[end]; i++)
+                coreCols.insert (i);
+            }
+          }
+        }
+      }
+
+      delete indices;
+
+      annotFile.close();
+    }
+  }
+
+  if (useColScore) makeAnnot = false;
+
+  if (testAlign){
+    for (int i = 0; i < testAlign->GetNumSequences(); i++){
+      bool found = false;
+      
+      for (int j = 0; !found && j < refAlign->GetNumSequences(); j++){
+       if (testAlign->GetSequence(i)->GetHeader() == refAlign->GetSequence(j)->GetHeader())
+         found = true;
+      }
+      
+      if (!found){
+       testAlign->RemoveSequence (i);
+       i--;
+      }
+    }
+    
+    for (int i = 0; i < refAlign->GetNumSequences(); i++){
+      bool found = false;
+      
+      for (int j = 0; !found && j < testAlign->GetNumSequences(); j++){
+       if (refAlign->GetSequence(i)->GetHeader() == testAlign->GetSequence(j)->GetHeader())
+         found = true;
+      }
+      
+      if (!found){
+       refAlign->RemoveSequence (i);
+       i--;
+      }
+    }
+    
+    testAlign->SortByHeader();
+    refAlign->SortByHeader();
+  }
+
+  int TP = 0;
+  int TPFN = 0;
+  int TPFP = 0;
+  double FD, FM;
+  if (useColScore){
+    refCols = ComputeColumns (refAlign, true);
+    if (testAlign) testCols = ComputeColumns (testAlign, false);
+    set<VI> colIntersect;
+    insert_iterator<set<VI> > colIntersectIter (colIntersect, colIntersect.begin());
+    set_intersection (testCols.begin(), testCols.end(), refCols.begin(), refCols.end(), colIntersectIter);
+    TP = (int) colIntersect.size();
+    TPFN = (int) refCols.size();
+    if (testAlign) TPFP = (int) testCols.size();
+  }
+  else {
+    refPairs = ComputePairs (refAlign, true);
+    if (testAlign) testPairs = ComputePairs (testAlign, false);
+    set<PII> pairIntersect;
+
+    insert_iterator<set<PII> > pairIntersectIter (pairIntersect, pairIntersect.begin());
+    set_intersection (testPairs.begin(), testPairs.end(), refPairs.begin(), refPairs.end(), pairIntersectIter);
+    TP = (int) pairIntersect.size();
+    TPFN = (int) refPairs.size();
+    if (testAlign) TPFP = (int) testPairs.size();
+  }
+
+  FD = (double) TP / TPFN;
+  FM = (double) TP / TPFP;
+  
+  cout << GetName(string (argv[2])) << " " << TP << " " << TPFN << " " << TPFP << " " << FD << " " << FM << endl;
+
+  if (makeAnnot){
+    ofstream outfile (outFilename.c_str());
+    for (int i = 0; i < (int) annotation.size(); i++){
+      outfile << annotation[i] << endl;
+    }
+    outfile.close();
+  }
+
+  if (testAlign) delete testAlign;
+  delete refAlign;
+}
+
+int GetOffset (Sequence *testSeq, Sequence *refSeq){
+  string test = testSeq->GetString();
+  string ref = refSeq->GetString();
+
+  for (int i = 0; i < (int) test.length(); i++) test[i] = toupper(test[i]);
+  for (int i = 0; i < (int) ref.length(); i++) ref[i] = toupper(ref[i]);
+
+  size_t offset = test.find (ref, 0);
+  if (offset == string::npos){
+    cerr << "ERROR: Reference string not found in original sequence!" << endl;
+    cerr << "       test = " << test << endl;
+    cerr << "       ref = " << ref << endl;
+    exit (1);
+  }
+
+  cerr << "Offset found: " << offset << endl;
+
+  return (int) offset;
+}
+
+string GetName (string s){
+
+  size_t index1 = s.rfind ('/');
+  size_t index2 = s.rfind ('.');
+
+  if (index1 == string::npos) index1 = 0; else index1++;
+  if (index2 == string::npos) index2 = s.length();
+
+  if (index2 < index1) index2 = s.length();
+
+  return s.substr (index1, index2 - index1);
+}
+
+bool isCore (char ch, int col){
+  if (ch == '-') return false;
+  if (useBaliAnnot){
+    return coreCols.find (col) != coreCols.end();
+  }
+  if (useCaps){
+    return ch >= 'A' && ch <= 'Z';
+  }
+  return ch == CORE_BLOCK;
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputePairs
+//
+// Returns the set of all matching pairs.
+/////////////////////////////////////////////////////////////////
+
+set<PII> ComputePairs (MultiSequence *align, bool isRef){
+  int N = align->GetNumSequences();
+  int L = align->GetSequence(0)->GetLength();
+
+  // retrieve all sequence data pointers
+  SafeVector<SafeVector<char>::iterator> seqs (N);
+  for (int i = 0; i < N; i++){
+    seqs[i] = align->GetSequence(i)->GetDataPtr();
+    assert (align->GetSequence(i)->GetLength() == L);
+  }
+
+  set<PII> ret;
+  VI ctr(N);
+
+  // compute pairs
+  for (int i = 1; i <= L; i++){
+
+    // ctr keeps track of the current position in each sequence
+    for (int j = 0; j < N; j++){
+      ctr[j] += (seqs[j][i] != '-');
+    }
+
+    int good = 0;
+    int ct = 0;
+
+    // check for all matching pairs
+    for (int j = 0; j < N - 1; j++){
+      for (int k = j + 1; k < N; k++){
+       
+       // skip if one of the sequences is gapped
+       if (seqs[j][i] == '-' || seqs[k][i] == '-') continue;
+
+       // check for core blocks in the reference sequence
+       if (isRef && useCoreBlocks)
+         if (!isCore (seqs[j][i], i) || !isCore (seqs[k][i], i)) continue;
+      
+       // if all ok, then add pair to list of pairs
+       pair<int,int> p (10000 * j + ctr[j], 10000 * k + ctr[k]);
+
+       // if we're making an annotation, compute annotation statistics
+       if (makeAnnot && !isRef){
+         ct++;
+         if (refPairs.find (p) != refPairs.end()) good++;
+       }
+        ret.insert (p);
+      }
+    }
+
+    // build annotation
+    if (makeAnnot && !isRef){
+      annotation.push_back ((ct == 0) ? 0 : 100 * good / ct);
+    }
+
+  }
+
+  return ret;
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeColumns
+//
+// Returns the set of all columns.
+/////////////////////////////////////////////////////////////////
+
+set<VI> ComputeColumns (MultiSequence *align,  bool isRef){
+  int N = align->GetNumSequences();
+  int L = align->GetSequence(0)->GetLength();
+
+  // retrieve all sequence data pointers
+  SafeVector<SafeVector<char>::iterator> seqs (N);
+  for (int i = 0; i < N; i++){
+    seqs[i] = align->GetSequence(i)->GetDataPtr();
+  }
+
+  set<VI> ret;
+  VI ctr(N);
+
+  // compute pairs
+  for (int i = 1; i <= L; i++){
+
+    // ctr keeps track of the current position in each sequence
+    for (int j = 0; j < N; j++){
+      ctr[j] += (seqs[j][i] != '-');
+    }
+
+    // add column, pick only positions that are matched
+    SafeVector<int> column (N);
+    bool useThisColumn = !useCoreBlocks;
+
+    for (int j = 0; j < N; j++){
+      if (isCore (seqs[j][i], i)) useThisColumn = true;
+      column[j] = (seqs[j][i] == '-') ? -1 : ctr[j];
+    }
+
+    if (useThisColumn || !isRef)
+      ret.insert (column);
+  }
+
+  return ret;
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h
new file mode 100644 (file)
index 0000000..e8ad944
--- /dev/null
@@ -0,0 +1,86 @@
+/////////////////////////////////////////////////////////////////
+// Defaults.h
+//
+// Default constants for use in PROBCONS.  The emission
+// probabilities were computed using the program used to build
+// the BLOSUM62 matrix from the BLOCKS 5.0 dataset.  Transition
+// parameters were obtained via unsupervised EM training on the
+// BALIBASE 2.0 benchmark alignment database.
+/////////////////////////////////////////////////////////////////
+
+#ifndef DEFAULTS_H
+#define DEFAULTS_H
+
+#include <string>
+
+using namespace std;
+/* Default */
+namespace MXSCARNA {
+/*
+float initDistrib1Default[] = { 0.9588437676f, 0.0205782652f, 0.0205782652f };
+float gapOpen1Default[] = { 0.0190259293f, 0.0190259293f };
+float gapExtend1Default[] = { 0.3269913495f, 0.3269913495f };
+*/
+
+/* EMtrainingALL.txt*/
+float initDistrib1Default[] = { 0.9234497547, 0.0385021642, 0.0385021642 };
+float gapOpen1Default[] = { 0.0266662259, 0.0266662259 };
+float gapExtend1Default[] = { 0.3849118352, 0.3849118352 };
+
+
+float initDistrib2Default[] = { 0.9615409374f, 0.0000004538f, 0.0000004538f, 0.0192291681f, 0.0192291681f };
+float gapOpen2Default[] = { 0.0082473317f, 0.0082473317f, 0.0107844425f, 0.0107844425f };
+float gapExtend2Default[] = { 0.3210460842f, 0.3210460842f, 0.3298229277f, 0.3298229277f };
+
+string alphabetDefault = "ACGUTN";
+
+//float emitSingleDefault[6] = {
+//   0.2174750715, 0.2573366761, 0.3005372882, 0.2233072966, 0.2233072966, 0.0004049665
+//};
+
+/* Default */
+/*
+float emitSingleDefault[6] = {
+  0.2270790040f, 0.2422080040f, 0.2839320004f, 0.2464679927f, 0.2464679927f, 0.0003124650f 
+};
+*/
+
+/* EMtrainingALL.txt */
+float emitSingleDefault[6] = {
+    0.2017124593, 0.2590311766, 0.2929603755, 0.2453189045, 0.2453189045, 0.0000873194 };
+
+/* ACGUTN */
+/* Default */
+/*
+float emitPairsDefault[6][6] = {
+  { 0.1487240046f, 0.0184142999f, 0.0361397006f, 0.0238473993f, 0.0238473993f, 0.0000375308f },
+  { 0.0184142999f, 0.1583919972f, 0.0275536999f, 0.0389291011f, 0.0389291011f, 0.0000815823f },
+  { 0.0361397006f, 0.0275536999f, 0.1979320049f, 0.0244289003f, 0.0244289003f, 0.0000824765f },
+  { 0.0238473993f, 0.0389291011f, 0.0244289003f, 0.1557479948f, 0.1557479948f, 0.0000743985f },
+  { 0.0238473993f, 0.0389291011f, 0.0244289003f, 0.1557479948f, 0.1557479948f, 0.0000743985f },
+  { 0.0000375308f, 0.0000815823f, 0.0000824765f, 0.0000743985f, 0.0000743985f, 0.0000263252f }
+};
+*/
+/* EMtrainingALL.txt */
+float emitPairsDefault[6][6] = {
+    { 0.1659344733, 0.0298952684, 0.0543937907, 0.0344539173, 0.0344539173, 0.0000032761 },
+    { 0.0298952684, 0.1817403436, 0.0415624641, 0.0589077808, 0.0589077808, 0.0000117011 },
+    { 0.0543937907, 0.0415624641, 0.2342105955, 0.0410407558, 0.0410407558, 0.0000072893 },
+    { 0.0344539173, 0.0589077808, 0.0410407558, 0.1578272283, 0.1578272283, 0.0000067871 },
+    { 0.0344539173, 0.0589077808, 0.0410407558, 0.1578272283, 0.1578272283, 0.0000067871 },
+    { 0.0344539173, 0.0589077808, 0.0410407558, 0.1578272283, 0.1578272283, 0.0000067871 },
+//    { 0.0000032761, 0.0000117011, 0.0000072893, 0.0000067871, 0.0000067871, 0.0000000166 } 
+};
+
+  /*
+float emitPairsDefault[6][6] = {
+    {0.1731323451, 0.0378843173, 0.0656677559, 0.0450690985, 0.0450690985, 0.0000215275},
+    {0.0378843173, 0.1611578614, 0.0492933467, 0.0651549697, 0.0651549697, 0.0000362353},
+    {0.0656677559, 0.0492933467, 0.1937607974, 0.0464556068, 0.0464556068, 0.0000293904},
+    {0.0450690985, 0.0651549697, 0.0464556068, 0.1622997671, 0.1622997671, 0.0000352637},
+    {0.0450690985, 0.0651549697, 0.0464556068, 0.1622997671, 0.1622997671, 0.0000352637},
+    {0.0000215275, 0.0000362353, 0.0000293904, 0.0000352637, 0.0000352637, 0.0000000000}
+};
+  */
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h_backup b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Defaults.h_backup
new file mode 100644 (file)
index 0000000..e09abb5
--- /dev/null
@@ -0,0 +1,57 @@
+/////////////////////////////////////////////////////////////////
+// Defaults.h
+//
+// Default constants for use in PROBCONS.  The emission
+// probabilities were computed using the program used to build
+// the BLOSUM62 matrix from the BLOCKS 5.0 dataset.  Transition
+// parameters were obtained via unsupervised EM training on the
+// BALIBASE 2.0 benchmark alignment database.
+/////////////////////////////////////////////////////////////////
+
+#ifndef DEFAULTS_H
+#define DEFAULTS_H
+
+#include <string>
+
+using namespace std;
+
+float initDistrib1Default[] = { 0.9588437676f, 0.0205782652f, 0.0205782652f };
+float gapOpen1Default[] = { 0.0190259293f, 0.0190259293f };
+float gapExtend1Default[] = { 0.3269913495f, 0.3269913495f };
+
+float initDistrib2Default[] = { 0.9615409374f, 0.0000004538f, 0.0000004538f, 0.0192291681f, 0.0192291681f };
+float gapOpen2Default[] = { 0.0082473317f, 0.0082473317f, 0.0107844425f, 0.0107844425f };
+float gapExtend2Default[] = { 0.3210460842f, 0.3210460842f, 0.3298229277f, 0.3298229277f };
+
+string alphabetDefault = "ACGUTN";
+
+//float emitSingleDefault[6] = {
+//   0.2174750715, 0.2573366761, 0.3005372882, 0.2233072966, 0.2233072966, 0.0004049665
+//};
+
+float emitSingleDefault[6] = {
+  0.2270790040f, 0.2422080040f, 0.2839320004f, 0.2464679927f, 0.2464679927f, 0.0003124650f 
+};
+
+/* ACGUTN */
+
+float emitPairsDefault[6][6] = {
+  { 0.1487240046f, 0.0184142999f, 0.0361397006f, 0.0238473993f, 0.0238473993f, 0.0000375308f },
+  { 0.0184142999f, 0.1583919972f, 0.0275536999f, 0.0389291011f, 0.0389291011f, 0.0000815823f },
+  { 0.0361397006f, 0.0275536999f, 0.1979320049f, 0.0244289003f, 0.0244289003f, 0.0000824765f },
+  { 0.0238473993f, 0.0389291011f, 0.0244289003f, 0.1557479948f, 0.1557479948f, 0.0000743985f },
+  { 0.0238473993f, 0.0389291011f, 0.0244289003f, 0.1557479948f, 0.1557479948f, 0.0000743985f },
+  { 0.0000375308f, 0.0000815823f, 0.0000824765f, 0.0000743985f, 0.0000743985f, 0.0000263252f }
+};
+
+  /*
+float emitPairsDefault[6][6] = {
+    {0.1731323451, 0.0378843173, 0.0656677559, 0.0450690985, 0.0450690985, 0.0000215275},
+    {0.0378843173, 0.1611578614, 0.0492933467, 0.0651549697, 0.0651549697, 0.0000362353},
+    {0.0656677559, 0.0492933467, 0.1937607974, 0.0464556068, 0.0464556068, 0.0000293904},
+    {0.0450690985, 0.0651549697, 0.0464556068, 0.1622997671, 0.1622997671, 0.0000352637},
+    {0.0450690985, 0.0651549697, 0.0464556068, 0.1622997671, 0.1622997671, 0.0000352637},
+    {0.0000215275, 0.0000362353, 0.0000293904, 0.0000352637, 0.0000352637, 0.0000000000}
+};
+  */
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EMtrainingALL.txt b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EMtrainingALL.txt
new file mode 100644 (file)
index 0000000..c2f24a0
--- /dev/null
@@ -0,0 +1,11 @@
+0.9234497547 0.0385021642 0.0385021642 
+0.0266662259 0.0266662259 
+0.3849118352 0.3849118352 
+ACGUTN
+0.1659344733 
+0.0298952684 0.1817403436 
+0.0543937907 0.0415624641 0.2342105955 
+0.0344539173 0.0589077808 0.0410407558 0.1578272283 
+0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 
+0.0000032761 0.0000117011 0.0000072893 0.0000067871 0.0000000000 0.0000000166 
+0.2017124593 0.2590311766 0.2929603755 0.2453189045 0.0000000000 0.0000873194 
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EvolutionaryTree.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/EvolutionaryTree.h
new file mode 100644 (file)
index 0000000..eceeafe
--- /dev/null
@@ -0,0 +1,200 @@
+/////////////////////////////////////////////////////////////////
+// EvolutionaryTree.hpp
+//
+// Utilities for reading/writing multiple sequence data.
+/////////////////////////////////////////////////////////////////
+
+#ifndef __EVOLUTIONARYTREE_HPP__
+#define __EVOLUTIONARYTREE_HPP__
+
+#include <string>
+#include <list>
+#include <stdio.h>
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include "Sequence.h"
+#include "Util.hpp"
+
+using namespace std;
+
+
+/////////////////////////////////////////////////////////////////
+// TreeNode
+//
+// The fundamental unit for representing an alignment tree.  The
+// guide tree is represented as a binary tree.
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+class TreeNode {
+  int sequenceLabel;                  // sequence label
+  float sequenceIdentity;             // sequence identity
+  TreeNode *left, *right, *parent;    // pointers to left, right children
+  float leftLength, rightLength;      // the length of left and right edge
+  /////////////////////////////////////////////////////////////////
+  // TreeNode::PrintNode()
+  //
+  // Internal routine used to print out the sequence comments
+  // associated with the evolutionary tree, using a hierarchical
+  // parenthesized format.
+  /////////////////////////////////////////////////////////////////
+
+  void PrintNode (ostream &outfile, const MultiSequence *sequences) const {
+
+    // if this is a leaf node, print out the associated sequence comment
+    if (sequenceLabel >= 0)
+       //outfile << sequences->GetSequence (sequenceLabel)->GetHeader();
+       outfile << sequences->GetSequence (sequenceLabel)->GetLabel();
+
+    // otherwise, it must have two children; print out their subtrees recursively
+    else {
+      assert (left);
+      assert (right);
+
+      outfile << "(";
+      left->PrintNode (outfile, sequences);
+      outfile << ",";
+      right->PrintNode (outfile, sequences);
+      outfile << ")";
+    }
+  }
+
+ public:
+
+  /////////////////////////////////////////////////////////////////
+  // TreeNode::TreeNode()
+  //
+  // Constructor for a tree node.  Note that sequenceLabel = -1
+  // implies that the current node is not a leaf in the tree.
+  /////////////////////////////////////////////////////////////////
+
+  TreeNode (int sequenceLabel) : sequenceLabel (sequenceLabel),
+    left (NULL), right (NULL), parent (NULL) {
+    assert (sequenceLabel >= -1);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // TreeNode::~TreeNode()
+  //
+  // Destructor for a tree node.  Recursively deletes all children.
+  /////////////////////////////////////////////////////////////////
+
+  ~TreeNode (){
+    if (left){ delete left; left = NULL; }
+    if (right){ delete right; right = NULL; }
+    parent = NULL;
+  }
+
+
+  // getters
+  int GetSequenceLabel () const { return sequenceLabel; }
+  TreeNode *GetLeftChild () const { return left; }
+  TreeNode *GetRightChild () const { return right; }
+  TreeNode *GetParent () const { return parent; }
+  float GetIdentity () const { return sequenceIdentity; }
+  float GetLeftLength () const { return leftLength; }
+  float GetRightLength () const { return rightLength; }
+  // setters
+  void SetSequenceLabel (int sequenceLabel){ this->sequenceLabel = sequenceLabel; assert (sequenceLabel >= -1); }
+  void SetLeftChild (TreeNode *left){ this->left = left; }
+  void SetRightChild (TreeNode *right){ this->right = right; }
+  void SetParent (TreeNode *parent){ this->parent = parent; }
+  void SetIdentity (float identity) { this->sequenceIdentity = identity; }
+  void SetLeftLength (float identity) { this->leftLength = identity; }
+  void SetRightLength (float identity) {this->rightLength = identity; }
+  /////////////////////////////////////////////////////////////////
+  // TreeNode::ComputeTree()
+  //
+  // Routine used to compute an evolutionary tree based on the
+  // given distance matrix.  We assume the distance matrix has the
+  // form, distMatrix[i][j] = expected accuracy of aligning i with j.
+  /////////////////////////////////////////////////////////////////
+
+  static TreeNode *ComputeTree (const VVF &distMatrix, const VVF &identityMatrix){
+
+    int numSeqs = distMatrix.size();                 // number of sequences in distance matrix
+    VVF distances (numSeqs, VF (numSeqs));           // a copy of the distance matrix
+    SafeVector<TreeNode *> nodes (numSeqs, NULL);    // list of nodes for each sequence
+    SafeVector<int> valid (numSeqs, 1);              // valid[i] tells whether or not the ith
+                                                     // nodes in the distances and nodes array
+                                                     // are valid
+    VVF identities (numSeqs, VF (numSeqs));
+    SafeVector<int> countCluster (numSeqs, 1);
+
+    // initialization: make a copy of the distance matrix
+    for (int i = 0; i < numSeqs; i++) {
+       for (int j = 0; j < numSeqs; j++) {
+           distances[i][j]  = distMatrix[i][j];
+           identities[i][j] = identityMatrix[i][j];
+       }
+    }
+
+    // initialization: create all the leaf nodes
+    for (int i = 0; i < numSeqs; i++){
+      nodes[i] = new TreeNode (i);
+      assert (nodes[i]);
+    }
+
+    // repeat until only a single node left
+    for (int numNodesLeft = numSeqs; numNodesLeft > 1; numNodesLeft--){
+       float bestProb = -1;
+      pair<int,int> bestPair;
+
+      // find the closest pair
+      for (int i = 0; i < numSeqs; i++) if (valid[i]){
+        for (int j = i+1; j < numSeqs; j++) if (valid[j]){
+          if (distances[i][j] > bestProb){
+            bestProb = distances[i][j];
+            bestPair = make_pair(i, j);
+          }
+        }
+      }
+
+      // merge the closest pair
+      TreeNode *newParent = new TreeNode (-1);
+      newParent->SetLeftChild (nodes[bestPair.first]);
+      newParent->SetRightChild (nodes[bestPair.second]);
+      nodes[bestPair.first]->SetParent (newParent);
+      nodes[bestPair.second]->SetParent (newParent);
+      nodes[bestPair.first] = newParent;
+      nodes[bestPair.second] = NULL;
+      newParent->SetIdentity(identities[bestPair.first][bestPair.second]);
+
+
+      // now update the distance matrix
+      for (int i = 0; i < numSeqs; i++) if (valid[i]){
+         distances[bestPair.first][i] = distances[i][bestPair.first]
+           = (distances[i][bestPair.first]*countCluster[bestPair.first] 
+              + distances[i][bestPair.second]*countCluster[bestPair.second])
+              / (countCluster[bestPair.first] + countCluster[bestPair.second]);
+//       distances[bestPair.first][i] = distances[i][bestPair.first]
+//           = (distances[i][bestPair.first] + distances[i][bestPair.second]) * bestProb / 2;
+       identities[bestPair.first][i] = identities[i][bestPair.first]
+           = (identities[i][bestPair.first]*countCluster[bestPair.first] 
+              + identities[i][bestPair.second]*countCluster[bestPair.second])
+              / (countCluster[bestPair.first] + countCluster[bestPair.second]);
+      }
+
+      // finally, mark the second node entry as no longer valid
+      countCluster[bestPair.first] += countCluster[bestPair.second];
+      valid[bestPair.second] = 0;
+    }
+
+    assert (nodes[0]);
+    return nodes[0];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // TreeNode::Print()
+  //
+  // Print out the subtree associated with this node in a
+  // parenthesized representation.
+  /////////////////////////////////////////////////////////////////
+
+  void Print (ostream &outfile, const MultiSequence *sequences) const {
+//    outfile << "Alignment tree: ";
+    PrintNode (outfile, sequences);
+    outfile << endl;
+  }
+};
+}
+#endif //__EVOLUTIONARYTREE_HPP__
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FileBuffer.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FileBuffer.h
new file mode 100644 (file)
index 0000000..9c36188
--- /dev/null
@@ -0,0 +1,104 @@
+/////////////////////////////////////////////////////////////////
+// FileBuffer.h
+//
+// Buffered file reading.
+/////////////////////////////////////////////////////////////////
+
+
+#ifndef FILEBUFFER_H
+#define FILEBUFFER_H
+
+#include <string>
+#include <fstream>
+#include <iostream>
+
+using namespace std;
+
+const int BufferSize = 1000;
+
+/////////////////////////////////////////////////////////////////
+// FileBuffer
+//
+// Class for buffering file reading.
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+class FileBuffer {
+  ifstream file;
+  char buffer[BufferSize];
+  int currPos;
+  int size;
+  bool isEOF;
+  bool isValid;
+  bool canUnget;
+
+ public:
+
+  // Some common routines
+
+  FileBuffer (const char *filename) : file (filename), currPos (0), size (0), isEOF (false), isValid (!file.fail()), canUnget (false){}
+  ~FileBuffer (){ close(); }
+  bool fail () const { return !isValid; }
+  bool eof () const { return (!isValid || isEOF); }
+  void close(){ file.close(); isValid = false; }
+
+  /////////////////////////////////////////////////////////////////
+  // FileBuffer::Get()
+  //
+  // Retrieve a character from the file buffer.  Returns true if
+  // and only if a character is read.
+  /////////////////////////////////////////////////////////////////
+
+  bool Get (char &ch){
+
+    // check to make sure that there's more stuff in the file
+    if (!isValid || isEOF) return false;
+
+    // if the buffer is empty, it's time to reload it
+    if (currPos == size){
+      file.read (buffer, BufferSize);
+      size = file.gcount();
+      isEOF = (size == 0);
+      currPos = 0;
+      if (isEOF) return false;
+    }
+
+    // store the read character
+    ch = buffer[currPos++];
+    canUnget = true;
+    return true;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // FileBuffer::UnGet()
+  //
+  // Unretrieve the most recently read character from the file
+  // buffer.  Note that this allows only a one-level undo.
+  /////////////////////////////////////////////////////////////////
+
+  void UnGet (){
+    assert (canUnget);
+    assert (isValid);
+    assert (currPos > 0);
+    currPos--;
+    assert (currPos < size);
+    isEOF = false;
+    canUnget = false;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // FileBuffer::GetLine()
+  //
+  // Retrieve characters of text until a newline character is
+  // encountered.  Terminates properly on end-of-file condition.
+  /////////////////////////////////////////////////////////////////
+
+  void GetLine (string &s){
+    char ch;
+    s = "";
+    while (Get (ch) && ch != '\n')
+      s += ch;
+  }
+
+};
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FixRef.cc b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/FixRef.cc
new file mode 100644 (file)
index 0000000..7060c79
--- /dev/null
@@ -0,0 +1,1000 @@
+/////////////////////////////////////////////////////////////////
+// Main.cc
+/////////////////////////////////////////////////////////////////
+
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include "Defaults.h"
+#include "ScoreType.h"
+#include "ProbabilisticModel.h"
+#include "EvolutionaryTree.h"
+#include "SparseMatrix.h"
+#include <string>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <set>
+#include <algorithm>
+#include <cstdio>
+#include <cstdlib>
+#include <cerrno>
+#include <iomanip>
+
+string matrixFilename = "";
+string parametersInputFilename = "";
+string parametersOutputFilename = "no training";
+
+bool enableTraining = false;
+bool enableVerbose = false;
+int numConsistencyReps = 2;
+int numPreTrainingReps = 0;
+int numIterativeRefinementReps = 100;
+
+float gapOpenPenalty = 0;
+float gapContinuePenalty = 0;
+VF initDistrib (NumMatrixTypes);
+VF gapOpen (2*NumInsertStates);
+VF gapExtend (2*NumInsertStates);
+SafeVector<char> alphabet;
+VVF emitPairs;
+VF emitSingle;
+
+const int MIN_PRETRAINING_REPS = 0;
+const int MAX_PRETRAINING_REPS = 20;
+const int MIN_CONSISTENCY_REPS = 0;
+const int MAX_CONSISTENCY_REPS = 5;
+const int MIN_ITERATIVE_REFINEMENT_REPS = 0;
+const int MAX_ITERATIVE_REFINEMENT_REPS = 1000;
+
+/////////////////////////////////////////////////////////////////
+// Function prototypes
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading();
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const char *filename);
+MultiSequence *DoAlign (MultiSequence *sequence, const ProbabilisticModel &model);
+SafeVector<string> ParseParams (int argc, char **argv);
+void ReadParameters ();
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model);
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model);
+void DoRelaxation (MultiSequence *sequences, SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior);
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment);
+//float ScoreAlignment (MultiSequence *alignment, MultiSequence *sequences, SparseMatrix **sparseMatrices, const int numSeqs);
+
+/////////////////////////////////////////////////////////////////
+// main()
+//
+// Calls all initialization routines and runs the PROBCONS
+// aligner.
+/////////////////////////////////////////////////////////////////
+
+int main (int argc, char **argv){
+
+  if (argc != 3){
+    cerr << "Usage: FixRef inputfile reffile" << endl;
+    exit (1);
+  }
+
+  string inputFilename = string (argv[1]);
+  string refFilename = string (argv[2]);
+
+  ReadParameters();
+
+  // build new model for aligning
+  ProbabilisticModel model (initDistrib, gapOpen, gapExtend, 
+                            alphabet, emitPairs, emitSingle);
+
+  MultiSequence *inputSeq = new MultiSequence(); inputSeq->LoadMFA (inputFilename);
+  MultiSequence *refSeq = new MultiSequence(); refSeq->LoadMFA (refFilename);
+
+  SafeVector<char> *ali = new SafeVector<char>;
+
+  if (refSeq->GetNumSequences() != 2){
+    cerr << "ERROR: Expected two sequences in reference alignment." << endl;
+    exit (1);
+  }
+  set<int> s; s.insert (0);
+  MultiSequence *ref1 = refSeq->Project (s);
+  s.clear(); s.insert (1);
+  MultiSequence *ref2 = refSeq->Project (s);
+
+  for (int i = 0; i < inputSeq->GetNumSequences(); i++){
+    if (inputSeq->GetSequence(i)->GetHeader() == ref1->GetSequence(0)->GetHeader()){
+      ref1->AddSequence (inputSeq->GetSequence(i)->Clone());
+    }
+    if (inputSeq->GetSequence(i)->GetHeader() == ref2->GetSequence(0)->GetHeader())
+      ref2->AddSequence (inputSeq->GetSequence(i)->Clone());
+  }
+  if (ref1->GetNumSequences() != 2){
+    cerr << "ERROR: Expected two sequences in reference1 alignment." << endl;
+    exit (1);
+  }
+  if (ref2->GetNumSequences() != 2){
+    cerr << "ERROR: Expected two sequences in reference2 alignment." << endl;
+    exit (1);
+  }
+
+  ref1->GetSequence(0)->SetLabel(0);
+  ref2->GetSequence(0)->SetLabel(0);
+  ref1->GetSequence(1)->SetLabel(1);
+  ref2->GetSequence(1)->SetLabel(1);
+
+  //  cerr << "Aligning..." << endl;
+
+  // now, we can perform the alignments and write them out
+  MultiSequence *alignment1 = DoAlign (ref1,
+                                       ProbabilisticModel (initDistrib, gapOpen, gapExtend, 
+                                                           alphabet, emitPairs, emitSingle));
+
+  //cerr << "Aligning second..." << endl;
+  MultiSequence *alignment2 = DoAlign (ref2,
+                                       ProbabilisticModel (initDistrib, gapOpen, gapExtend, 
+                                                           alphabet, emitPairs, emitSingle));
+
+  SafeVector<char>::iterator iter1 = alignment1->GetSequence(0)->GetDataPtr();
+  SafeVector<char>::iterator iter2 = alignment1->GetSequence(1)->GetDataPtr();
+  for (int i = 1; i <= alignment1->GetSequence(0)->GetLength(); i++){
+    if (islower(iter1[i])) iter2[i] = tolower(iter2[i]);
+    if (isupper(iter1[i])) iter2[i] = toupper(iter2[i]);
+  }
+  iter1 = alignment2->GetSequence(0)->GetDataPtr();
+  iter2 = alignment2->GetSequence(1)->GetDataPtr();
+  for (int i = 1; i <= alignment2->GetSequence(0)->GetLength(); i++){
+    if (islower(iter1[i])) iter2[i] = tolower(iter2[i]);
+    if (isupper(iter1[i])) iter2[i] = toupper(iter2[i]);
+  }
+  //alignment1->WriteMFA (cout);
+  //alignment2->WriteMFA (cout);
+
+  int a1 = 0, a = 0;
+  int b1 = 0, b = 0;
+
+  for (int i = 1; i <= refSeq->GetSequence(0)->GetLength(); i++){
+
+    // catch up in filler sequences
+    if (refSeq->GetSequence(0)->GetPosition(i) != '-'){
+      while (true){
+        a++;
+        if (alignment1->GetSequence(0)->GetPosition(a) != '-') break;
+        ali->push_back ('X');
+      }
+    }
+    if (refSeq->GetSequence(1)->GetPosition(i) != '-'){
+      while (true){
+        b++;
+        if (alignment2->GetSequence(0)->GetPosition(b) != '-') break;
+        ali->push_back ('Y');
+      }
+    }
+
+    if (refSeq->GetSequence(0)->GetPosition(i) != '-' &&
+        refSeq->GetSequence(1)->GetPosition(i) != '-'){
+      //cerr << "M: " << refSeq->GetSequence(0)->GetPosition(i) << refSeq->GetSequence(1)->GetPosition(i) << endl;
+      ali->push_back ('B');
+    }
+    else if (refSeq->GetSequence(0)->GetPosition(i) != '-'){
+      //cerr << "X" << endl;
+      ali->push_back ('X');
+    }
+    else if (refSeq->GetSequence(1)->GetPosition(i) != '-'){
+      //cerr << "Y" << endl;
+      ali->push_back ('Y');
+    }
+  }
+
+  while (a < alignment1->GetSequence(0)->GetLength()){
+    a++;
+    ali->push_back ('X');
+    if (alignment1->GetSequence(0)->GetPosition(a) != '-') a1++;
+  }
+  while (b < alignment2->GetSequence(0)->GetLength()){
+    b++;
+    ali->push_back ('Y');
+    if (alignment2->GetSequence(0)->GetPosition(b) != '-') b1++;
+  }
+
+  Sequence *seq1 = alignment1->GetSequence(1)->AddGaps (ali, 'X');
+  Sequence *seq2 = alignment2->GetSequence(1)->AddGaps (ali, 'Y');
+  seq1->WriteMFA (cout, 60);
+  seq2->WriteMFA (cout, 60);
+
+  delete seq1;
+  delete seq2;
+
+  delete ali;
+  delete alignment1;
+  delete alignment2;
+  delete inputSeq;
+  delete refSeq;
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintHeading()
+//
+// Prints heading for PROBCONS program.
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading (){
+  cerr << endl
+       << "PROBCONS version 1.02 - align multiple protein sequences and print to standard output" << endl
+       << "Copyright (C) 2004  Chuong Ba Do" << endl
+       << endl;
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintParameters()
+//
+// Prints PROBCONS parameters to STDERR.  If a filename is
+// specified, then the parameters are also written to the file.
+/////////////////////////////////////////////////////////////////
+
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const char *filename){
+
+  // print parameters to the screen
+  cerr << message << endl
+       << "    initDistrib[] = { ";
+  for (int i = 0; i < NumMatrixTypes; i++) cerr << setprecision (10) << initDistrib[i] << " ";
+  cerr << "}" << endl
+       << "        gapOpen[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapOpen[i] << " ";
+  cerr << "}" << endl
+       << "      gapExtend[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapExtend[i] << " ";
+  cerr << "}" << endl
+       << endl;
+
+  // if a file name is specified
+  if (filename){
+
+    // attempt to open the file for writing
+    FILE *file = fopen (filename, "w");
+    if (!file){
+      cerr << "ERROR: Unable to write parameter file: " << filename << endl;
+      exit (1);
+    }
+
+    // if successful, then write the parameters to the file
+    for (int i = 0; i < NumMatrixTypes; i++) fprintf (file, "%.10f ", initDistrib[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapOpen[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapExtend[i]); fprintf (file, "\n");
+    fclose (file);
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoAlign()
+//
+// First computes all pairwise posterior probability matrices.
+// Then, computes new parameters if training, or a final
+// alignment, otherwise.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *DoAlign (MultiSequence *sequences, const ProbabilisticModel &model){
+
+  assert (sequences);
+
+  const int numSeqs = sequences->GetNumSequences();
+  VVF distances (numSeqs, VF (numSeqs, 0));
+  SafeVector<SafeVector<SparseMatrix *> > sparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+
+  // do all pairwise alignments
+  for (int a = 0; a < numSeqs-1; a++){
+    for (int b = a+1; b < numSeqs; b++){
+      Sequence *seq1 = sequences->GetSequence (a);
+      Sequence *seq2 = sequences->GetSequence (b);
+
+      // verbose output
+      if (enableVerbose)
+        cerr << "(" << a+1 << ") " << seq1->GetHeader() << " vs. "
+             << "(" << b+1 << ") " << seq2->GetHeader() << ": ";
+
+      // compute forward and backward probabilities
+      VF *forward = model.ComputeForwardMatrix (seq1, seq2); assert (forward);
+      VF *backward = model.ComputeBackwardMatrix (seq1, seq2); assert (backward);
+
+      // if we are training, then we'll simply want to compute the
+      // expected counts for each region within the matrix separately;
+      // otherwise, we'll need to put all of the regions together and
+      // assemble a posterior probability match matrix
+
+      // compute posterior probability matrix
+      VF *posterior = model.ComputePosteriorMatrix (seq1, seq2, *forward, *backward); assert (posterior);
+
+      // compute "expected accuracy" distance for evolutionary tree computation
+      pair<SafeVector<char> *, float> alignment = model.ComputeAlignment (seq1->GetLength(),
+                                                                          seq2->GetLength(),
+                                                                          *posterior);
+
+      float distance = alignment.second / min (seq1->GetLength(), seq2->GetLength());
+
+      if (enableVerbose)
+        cerr << setprecision (10) << distance << endl;
+
+      // save posterior probability matrices in sparse format
+      distances[a][b] = distances[b][a] = distance;
+      sparseMatrices[a][b] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), *posterior);
+      sparseMatrices[b][a] = sparseMatrices[a][b]->ComputeTranspose();
+
+      delete alignment.first;
+      delete posterior;
+
+      delete forward;
+      delete backward;
+    }
+  }
+
+  if (!enableTraining){
+    if (enableVerbose)
+      cerr << endl;
+
+    // now, perform the consistency transformation the desired number of times
+    for (int i = 0; i < numConsistencyReps; i++)
+      DoRelaxation (sequences, sparseMatrices);
+
+    // compute the evolutionary tree
+    TreeNode *tree = TreeNode::ComputeTree (distances);
+
+    //tree->Print (cerr, sequences);
+    //cerr << endl;
+
+    // make the final alignment
+    MultiSequence *alignment = ComputeFinalAlignment (tree, sequences, sparseMatrices, model);
+    delete tree;
+
+    return alignment;
+  }
+
+  return NULL;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetInteger()
+//
+// Attempts to parse an integer from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetInteger (char *data, int *val){
+  char *endPtr;
+  long int retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtol (data, &endPtr, 0);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal == LONG_MAX || retVal == LONG_MIN)) return false;
+  if (retVal < (long) INT_MIN || retVal > (long) INT_MAX) return false;
+  *val = (int) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetFloat()
+//
+// Attempts to parse a float from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetFloat (char *data, float *val){
+  char *endPtr;
+  double retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtod (data, &endPtr);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal >= 1000000.0 || retVal <= -1000000.0)) return false;
+  *val = (float) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// ParseParams()
+//
+// Parse all command-line options.
+/////////////////////////////////////////////////////////////////
+
+SafeVector<string> ParseParams (int argc, char **argv){
+
+  if (argc < 2){
+
+    cerr << "PROBCONS comes with ABSOLUTELY NO WARRANTY.  This is free software, and" << endl
+         << "you are welcome to redistribute it under certain conditions.  See the" << endl
+         << "file COPYING.txt for details." << endl
+         << endl
+         << "Usage:" << endl
+         << "       probcons [OPTION]... [MFAFILE]..." << endl
+         << endl
+         << "Description:" << endl
+         << "       Align sequences in MFAFILE(s) and print result to standard output" << endl
+         << endl
+         << "       -t, --train FILENAME" << endl
+         << "              compute EM transition probabilities, store in FILENAME (default: "
+         << parametersOutputFilename << ")" << endl
+         << endl
+         << "       -m, --matrixfile FILENAME" << endl
+         << "              read transition parameters from FILENAME (default: "
+         << matrixFilename << ")" << endl
+         << endl
+         << "       -p, --paramfile FILENAME" << endl
+         << "              read scoring matrix probabilities from FILENAME (default: "
+         << parametersInputFilename << ")" << endl
+         << endl
+         << "       -c, --consistency REPS" << endl
+         << "              use " << MIN_CONSISTENCY_REPS << " <= REPS <= " << MAX_CONSISTENCY_REPS
+         << " (default: " << numConsistencyReps << ") passes of consistency transformation" << endl
+         << endl
+         << "       -ir, --iterative-refinement REPS" << endl
+         << "              use " << MIN_ITERATIVE_REFINEMENT_REPS << " <= REPS <= " << MAX_ITERATIVE_REFINEMENT_REPS
+         << " (default: " << numIterativeRefinementReps << ") passes of iterative-refinement" << endl
+         << endl
+         << "       -pre, --pre-training REPS" << endl
+         << "              use " << MIN_PRETRAINING_REPS << " <= REPS <= " << MAX_PRETRAINING_REPS
+         << " (default: " << numPreTrainingReps << ") rounds of pretraining" << endl
+         << endl
+         << "       -go, --gap-open VALUE" << endl
+         << "              gap opening penalty of VALUE <= 0 (default: " << gapOpenPenalty << ")" << endl
+         << endl
+         << "       -ge, --gap-extension VALUE" << endl
+         << "              gap extension penalty of VALUE <= 0 (default: " << gapContinuePenalty << ")" << endl
+         << endl
+         << "       -v, --verbose" << endl
+         << "              report progress while aligning (default: " << (enableVerbose ? "on" : "off") << ")" << endl
+         << endl;
+
+    exit (1);
+  }
+
+  SafeVector<string> sequenceNames;
+  int tempInt;
+  float tempFloat;
+
+  for (int i = 1; i < argc; i++){
+    if (argv[i][0] == '-'){
+
+      // training
+      if (!strcmp (argv[i], "-t") || !strcmp (argv[i], "--train")){
+        enableTraining = true;
+        if (i < argc - 1)
+          parametersOutputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // scoring matrix file
+      else if (!strcmp (argv[i], "-m") || !strcmp (argv[i], "--matrixfile")){
+        if (i < argc - 1)
+          matrixFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // transition/initial distribution parameter file
+      else if (!strcmp (argv[i], "-p") || !strcmp (argv[i], "--paramfile")){
+        if (i < argc - 1)
+          parametersInputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // number of consistency transformations
+      else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--consistency")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_CONSISTENCY_REPS || tempInt > MAX_CONSISTENCY_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_CONSISTENCY_REPS << " and " << MAX_CONSISTENCY_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numConsistencyReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // number of randomized partitioning iterative refinement passes
+      else if (!strcmp (argv[i], "-ir") || !strcmp (argv[i], "--iterative-refinement")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_ITERATIVE_REFINEMENT_REPS || tempInt > MAX_ITERATIVE_REFINEMENT_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_ITERATIVE_REFINEMENT_REPS << " and " << MAX_ITERATIVE_REFINEMENT_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numIterativeRefinementReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // number of EM pre-training rounds
+      else if (!strcmp (argv[i], "-pre") || !strcmp (argv[i], "--pre-training")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_PRETRAINING_REPS || tempInt > MAX_PRETRAINING_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_PRETRAINING_REPS << " and " << MAX_PRETRAINING_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numPreTrainingReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap open penalty
+      else if (!strcmp (argv[i], "-go") || !strcmp (argv[i], "--gap-open")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapOpenPenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap extension penalty
+      else if (!strcmp (argv[i], "-ge") || !strcmp (argv[i], "--gap-extension")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapContinuePenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // verbose reporting
+      else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--verbose")){
+        enableVerbose = true;
+      }
+
+      // bad arguments
+      else {
+        cerr << "ERROR: Unrecognized option: " << argv[i] << endl;
+        exit (1);
+      }
+    }
+    else {
+      sequenceNames.push_back (string (argv[i]));
+    }
+  }
+
+  return sequenceNames;
+}
+
+/////////////////////////////////////////////////////////////////
+// ReadParameters()
+//
+// Read initial distribution, transition, and emission
+// parameters from a file.
+/////////////////////////////////////////////////////////////////
+
+void ReadParameters (){
+
+  ifstream data;
+
+  // read initial state distribution and transition parameters
+  if (parametersInputFilename == string ("")){
+    if (NumInsertStates == 1){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend1Default[i];
+    }
+    else if (NumInsertStates == 2){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend2Default[i];
+    }
+    else {
+      cerr << "ERROR: No default initial distribution/parameter settings exist" << endl
+           << "       for " << NumInsertStates << " pairs of insert states.  Use --paramfile." << endl;
+      exit (1);
+    }
+  }
+  else {
+    data.open (parametersInputFilename.c_str());
+    if (data.fail()){
+      cerr << "ERROR: Unable to read parameter file: " << parametersInputFilename << endl;
+      exit (1);
+    }
+    for (int i = 0; i < NumMatrixTypes; i++) data >> initDistrib[i];
+    for (int i = 0; i < 2*NumInsertStates; i++) data >> gapOpen[i];
+    for (int i = 0; i < 2*NumInsertStates; i++) data >> gapExtend[i];
+    data.close();
+  }
+
+  // read emission parameters
+  int alphabetSize = 20;
+
+  // allocate memory
+  alphabet = SafeVector<char>(alphabetSize);
+  emitPairs = VVF (alphabetSize, VF (alphabetSize, 0));
+  emitSingle = VF (alphabetSize);
+
+  if (matrixFilename == string ("")){
+    for (int i = 0; i < alphabetSize; i++) alphabet[i] = alphabetDefault[i];
+    for (int i = 0; i < alphabetSize; i++){
+      emitSingle[i] = emitSingleDefault[i];
+      for (int j = 0; j <= i; j++){
+        emitPairs[i][j] = emitPairs[j][i] = (i == j);
+      }
+    }
+  }
+  else {
+    data.open (matrixFilename.c_str());
+    if (data.fail()){
+      cerr << "ERROR: Unable to read scoring matrix file: " << matrixFilename << endl;
+      exit (1);
+    }
+
+    for (int i = 0; i < alphabetSize; i++) data >> alphabet[i];
+    for (int i = 0; i < alphabetSize; i++){
+      for (int j = 0; j <= i; j++){
+        data >> emitPairs[i][j];
+        emitPairs[j][i] = emitPairs[i][j];
+      }
+    }
+    for (int i = 0; i < alphabetSize; i++){
+      char ch;
+      data >> ch;
+      assert (ch == alphabet[i]);
+    }
+    for (int i = 0; i < alphabetSize; i++) data >> emitSingle[i];
+    data.close();
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// ProcessTree()
+//
+// Process the tree recursively.  Returns the aligned sequences
+// corresponding to a node or leaf of the tree.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *ProcessTree (const TreeNode *tree, MultiSequence *sequences,
+                            const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model){
+  MultiSequence *result;
+
+  // check if this is a node of the alignment tree
+  if (tree->GetSequenceLabel() == -1){
+    MultiSequence *alignLeft = ProcessTree (tree->GetLeftChild(), sequences, sparseMatrices, model);
+    MultiSequence *alignRight = ProcessTree (tree->GetRightChild(), sequences, sparseMatrices, model);
+
+    assert (alignLeft);
+    assert (alignRight);
+
+    result = AlignAlignments (alignLeft, alignRight, sparseMatrices, model);
+    assert (result);
+
+    delete alignLeft;
+    delete alignRight;
+  }
+
+  // otherwise, this is a leaf of the alignment tree
+  else {
+    result = new MultiSequence(); assert (result);
+    result->AddSequence (sequences->GetSequence(tree->GetSequenceLabel())->Clone());
+  }
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeFinalAlignment()
+//
+// Compute the final alignment by calling ProcessTree(), then
+// performing iterative refinement as needed.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model){
+
+  MultiSequence *alignment = ProcessTree (tree, sequences, sparseMatrices, model);
+
+  // iterative refinement
+  for (int i = 0; i < numIterativeRefinementReps; i++)
+    DoIterativeRefinement (sparseMatrices, model, alignment);
+
+  cerr << endl;
+
+  // return final alignment
+  return alignment;
+}
+
+/////////////////////////////////////////////////////////////////
+// AlignAlignments()
+//
+// Returns the alignment of two MultiSequence objects.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model){
+
+  // print some info about the alignment
+  if (enableVerbose){
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align1->GetSequence(i)->GetLabel();
+    cerr << "] vs. ";
+    for (int i = 0; i < align2->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align2->GetSequence(i)->GetLabel();
+    cerr << "]: ";
+  }
+
+  VF *posterior = model.BuildPosterior (align1, align2, sparseMatrices);
+  pair<SafeVector<char> *, float> alignment;
+
+  // choose the alignment routine depending on the "cosmetic" gap penalties used
+  if (gapOpenPenalty == 0 && gapContinuePenalty == 0)
+    alignment = model.ComputeAlignment (align1->GetSequence(0)->GetLength(), align2->GetSequence(0)->GetLength(), *posterior);
+  else
+    alignment = model.ComputeAlignmentWithGapPenalties (align1, align2,
+                                                        *posterior, align1->GetNumSequences(), align2->GetNumSequences(),
+                                                        gapOpenPenalty, gapContinuePenalty);
+
+  delete posterior;
+
+  if (enableVerbose){
+
+    // compute total length of sequences
+    int totLength = 0;
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      for (int j = 0; j < align2->GetNumSequences(); j++)
+        totLength += min (align1->GetSequence(i)->GetLength(), align2->GetSequence(j)->GetLength());
+
+    // give an "accuracy" measure for the alignment
+    cerr << alignment.second / totLength << endl;
+  }
+
+  // now build final alignment
+  MultiSequence *result = new MultiSequence();
+  for (int i = 0; i < align1->GetNumSequences(); i++)
+    result->AddSequence (align1->GetSequence(i)->AddGaps(alignment.first, 'X'));
+  for (int i = 0; i < align2->GetNumSequences(); i++)
+    result->AddSequence (align2->GetSequence(i)->AddGaps(alignment.first, 'Y'));
+  result->SortByLabel();
+
+  // free temporary alignment
+  delete alignment.first;
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// DoRelaxation()
+//
+// Performs one round of the consistency transformation.  The
+// formula used is:
+//                     1
+//    P'(x[i]-y[j]) = ---  sum   sum P(x[i]-z[k]) P(z[k]-y[j])
+//                    |S| z in S  k
+//
+// where S = {x, y, all other sequences...}
+//
+/////////////////////////////////////////////////////////////////
+
+void DoRelaxation (MultiSequence *sequences, SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+  const int numSeqs = sequences->GetNumSequences();
+
+  SafeVector<SafeVector<SparseMatrix *> > newSparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+
+  // for every pair of sequences
+  for (int i = 0; i < numSeqs; i++){
+    for (int j = i+1; j < numSeqs; j++){
+      Sequence *seq1 = sequences->GetSequence (i);
+      Sequence *seq2 = sequences->GetSequence (j);
+
+      if (enableVerbose)
+        cerr << "Relaxing (" << i+1 << ") " << seq1->GetHeader() << " vs. "
+             << "(" << j+1 << ") " << seq2->GetHeader() << ": ";
+
+      // get the original posterior matrix
+      VF *posteriorPtr = sparseMatrices[i][j]->GetPosterior(); assert (posteriorPtr);
+      VF &posterior = *posteriorPtr;
+
+      const int seq1Length = seq1->GetLength();
+      const int seq2Length = seq2->GetLength();
+
+      // contribution from the summation where z = x and z = y
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] += posterior[k];
+
+      if (enableVerbose)
+        cerr << sparseMatrices[i][j]->GetNumCells() << " --> ";
+
+      // contribution from all other sequences
+      for (int k = 0; k < numSeqs; k++) if (k != i && k != j){
+        Relax (sparseMatrices[i][k], sparseMatrices[k][j], posterior);
+      }
+
+      // now renormalization
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] /= numSeqs;
+
+      // save the new posterior matrix
+      newSparseMatrices[i][j] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), posterior);
+      newSparseMatrices[j][i] = newSparseMatrices[i][j]->ComputeTranspose();
+
+      if (enableVerbose)
+        cerr << newSparseMatrices[i][j]->GetNumCells() << " -- ";
+
+      delete posteriorPtr;
+
+      if (enableVerbose)
+        cerr << "done." << endl;
+    }
+  }
+
+  // now replace the old posterior matrices
+  for (int i = 0; i < numSeqs; i++){
+    for (int j = 0; j < numSeqs; j++){
+      delete sparseMatrices[i][j];
+      sparseMatrices[i][j] = newSparseMatrices[i][j];
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoRelaxation()
+//
+// Computes the consistency transformation for a single sequence
+// z, and adds the transformed matrix to "posterior".
+/////////////////////////////////////////////////////////////////
+
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior){
+
+  assert (matXZ);
+  assert (matZY);
+
+  int lengthX = matXZ->GetSeq1Length();
+  int lengthY = matZY->GetSeq2Length();
+  assert (matXZ->GetSeq2Length() == matZY->GetSeq1Length());
+
+  // for every x[i]
+  for (int i = 1; i <= lengthX; i++){
+    SafeVector<PIF>::iterator XZptr = matXZ->GetRowPtr(i);
+    SafeVector<PIF>::iterator XZend = XZptr + matXZ->GetRowSize(i);
+
+    VF::iterator base = posterior.begin() + i * (lengthY + 1);
+
+    // iterate through all x[i]-z[k]
+    while (XZptr != XZend){
+      SafeVector<PIF>::iterator ZYptr = matZY->GetRowPtr(XZptr->first);
+      SafeVector<PIF>::iterator ZYend = ZYptr + matZY->GetRowSize(XZptr->first);
+      const float XZval = XZptr->second;
+
+      // iterate through all z[k]-y[j]
+      while (ZYptr != ZYend){
+        base[ZYptr->first] += XZval * ZYptr->second;;
+        ZYptr++;
+      }
+      XZptr++;
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoIterativeRefinement()
+//
+// Performs a single round of randomized partionining iterative
+// refinement.
+/////////////////////////////////////////////////////////////////
+
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment){
+  set<int> groupOne, groupTwo;
+
+  // create two separate groups
+  for (int i = 0; i < alignment->GetNumSequences(); i++){
+    if (random() % 2)
+      groupOne.insert (i);
+    else
+      groupTwo.insert (i);
+  }
+
+  if (groupOne.empty() || groupTwo.empty()) return;
+
+  // project into the two groups
+  MultiSequence *groupOneSeqs = alignment->Project (groupOne); assert (groupOneSeqs);
+  MultiSequence *groupTwoSeqs = alignment->Project (groupTwo); assert (groupTwoSeqs);
+  delete alignment;
+
+  // realign
+  alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model);
+}
+
+/*
+float ScoreAlignment (MultiSequence *alignment, MultiSequence *sequences, SparseMatrix **sparseMatrices, const int numSeqs){
+  int totLength = 0;
+  float score = 0;
+
+  for (int a = 0; a < alignment->GetNumSequences(); a++){
+    for (int b = a+1; b < alignment->GetNumSequences(); b++){
+      Sequence *seq1 = alignment->GetSequence(a);
+      Sequence *seq2 = alignment->GetSequence(b);
+
+      const int seq1Length = sequences->GetSequence(seq1->GetLabel())->GetLength();
+      const int seq2Length = sequences->GetSequence(seq2->GetLabel())->GetLength();
+
+      totLength += min (seq1Length, seq2Length);
+
+      int pos1 = 0, pos2 = 0;
+      for (int i = 1; i <= seq1->GetLength(); i++){
+        char ch1 = seq1->GetPosition(i);
+        char ch2 = seq2->GetPosition(i);
+
+        if (ch1 != '-') pos1++;
+        if (ch2 != '-') pos2++;
+        if (ch1 != '-' && ch2 != '-'){
+          score += sparseMatrices[a * numSeqs + b]->GetValue (pos1, pos2);
+        }
+      }
+    }
+  }
+
+  return score / totLength;
+}
+*/
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Main.cc b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Main.cc
new file mode 100644 (file)
index 0000000..5392f40
--- /dev/null
@@ -0,0 +1,1870 @@
+/////////////////////////////////////////////////////////////////
+// Main.cc
+//
+// Main routines for MXSCARNA program.
+/////////////////////////////////////////////////////////////////
+
+#include "scarna.hpp"
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include "Defaults.h"
+#include "ScoreType.h"
+#include "ProbabilisticModel.h"
+#include "EvolutionaryTree.h"
+#include "SparseMatrix.h"
+#include "BPPMatrix.hpp"
+#include "StemCandidate.hpp"
+#include "Globaldp.hpp"
+#include "nrutil.h"
+#include "AlifoldMEA.h"
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <set>
+#include <algorithm>
+#include <cstdio>
+#include <cstdlib>
+#include <cerrno>
+#include <iomanip>
+#include <fstream>
+
+#include "RfoldWrapper.hpp"
+//static RFOLD::Rfold folder;
+
+using namespace::MXSCARNA;
+using namespace::RFOLD;
+
+string parametersInputFilename = "";
+string parametersOutputFilename = "no training";
+string annotationFilename = "";
+string weboutputFileName = "";
+
+ofstream *outputFile;
+
+bool enableTraining = false;
+bool enableVerbose = false;
+bool enableAllPairs = false;
+bool enableAnnotation = false;
+bool enableViterbi = false;
+bool enableClustalWOutput = false;
+bool enableTrainEmissions = false;
+bool enableAlignOrder = false;
+bool enableWebOutput  = false;
+bool enableStockholmOutput = false;
+bool enableMXSCARNAOutput = false;
+bool enableMcCaskillMEAMode = false;
+int numConsistencyReps = 2;
+int numPreTrainingReps = 0;
+int numIterativeRefinementReps = 100;
+int scsLength = SCSLENGTH;
+float cutoff = 0;
+float gapOpenPenalty = 0;
+float gapContinuePenalty = 0;
+float threshhold = 1.0;
+float BaseProbThreshold = BASEPROBTHRESHOLD;
+float BasePairConst = BASEPAIRCONST;
+int   BandWidth = BANDWIDTH;
+bool  useRfold = USERFOLD;
+SafeVector<string> sequenceNames;
+
+VF initDistrib (NumMatrixTypes);
+VF gapOpen (2*NumInsertStates);
+VF gapExtend (2*NumInsertStates);
+VVF emitPairs (256, VF (256, 1e-10));
+VF emitSingle (256, 1e-5);
+
+string alphabet = alphabetDefault;
+
+string *ssCons = NULL;
+
+const int MIN_PRETRAINING_REPS = 0;
+const int MAX_PRETRAINING_REPS = 20;
+const int MIN_CONSISTENCY_REPS = 0;
+const int MAX_CONSISTENCY_REPS = 5;
+const int MIN_ITERATIVE_REFINEMENT_REPS = 0;
+const int MAX_ITERATIVE_REFINEMENT_REPS = 1000;
+
+/////////////////////////////////////////////////////////////////
+// Function prototypes
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading();
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const VVF &emitPairs, const VF &emitSingle, const char *filename);
+MultiSequence *DoAlign (MultiSequence *sequence, const ProbabilisticModel &model, VF &initDistrib, VF &gapOpen, VF &gapExtend, VVF &emitPairs, VF &emitSingle);
+SafeVector<string> ParseParams (int argc, char **argv);
+void ReadParameters ();
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model,
+                                     SafeVector<BPPMatrix*> &BPPMatrices);
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model, SafeVector<BPPMatrix*> &BPPMatrices, float identity);
+SafeVector<SafeVector<SparseMatrix *> > DoRelaxation (MultiSequence *sequences, 
+                                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior);
+void Relax1 (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior);
+void DoBasePairProbabilityRelaxation (MultiSequence *sequences, 
+                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                     SafeVector<BPPMatrix*> &BPPMatrices);
+set<int> GetSubtree (const TreeNode *tree);
+void TreeBasedBiPartitioning (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                              const ProbabilisticModel &model, MultiSequence* &alignment,
+                              const TreeNode *tree, SafeVector<BPPMatrix*> &BPPMatrices);
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment);
+void WriteAnnotation (MultiSequence *alignment,
+                     const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+int ComputeScore (const SafeVector<pair<int, int> > &active, 
+                 const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices);
+std::vector<StemCandidate>* seq2scs(MultiSequence *Sequences, SafeVector<BPPMatrix*> &BPPMatrices, int BandWidth);
+void removeConflicts(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2, std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2);
+
+struct prob {
+    int i;
+    int j;
+    float p;
+};
+
+/////////////////////////////////////////////////////////////////
+// main()
+//
+// Calls all initialization routines and runs the MXSCARNA
+// aligner.
+/////////////////////////////////////////////////////////////////
+
+
+int main (int argc, char **argv){
+
+    // print MXSCARNA heading
+    PrintHeading();
+  
+    // parse program parameters
+    sequenceNames = ParseParams (argc, argv);
+    ReadParameters();
+    PrintParameters ("Using parameter set:", initDistrib, gapOpen, gapExtend, emitPairs, emitSingle, NULL);
+  
+  // now, we'll process all the files given as input.  If we are given
+  // several filenames as input, then we'll load all of those sequences
+  // simultaneously, as long as we're not training.  On the other hand,
+  // if we are training, then we'll treat each file as a separate
+  // training instance
+
+    if (enableMcCaskillMEAMode) {
+      MultiSequence *sequences = new MultiSequence(); assert (sequences);
+      for (int i = 0; i < (int) sequenceNames.size(); i++){
+         cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+         sequences->LoadMFA (sequenceNames[i], true);
+      }
+
+      const int numSeqs = sequences->GetNumSequences();
+      SafeVector<BPPMatrix*> BPPMatrices;
+
+      // compute the base pairing matrices for each sequences
+      for(int i = 0; i < numSeqs; i++) {
+         Sequence *tmpSeq = sequences->GetSequence(i);
+         string   seq = tmpSeq->GetString();
+         int    n_seq = tmpSeq->GetLength();
+         BPPMatrix *bppmat = new BPPMatrix(seq, n_seq);
+         BPPMatrices.push_back(bppmat);
+      }
+      AlifoldMEA alifold(sequences, BPPMatrices, BasePairConst);
+      alifold.Run();
+      ssCons = alifold.getSScons();
+
+      if (enableStockholmOutput) {
+         sequences->WriteSTOCKHOLM (cout, ssCons);
+      }
+      else if (enableMXSCARNAOutput){
+         sequences->WriteMXSCARNA (cout, ssCons);
+      }
+      else {
+         sequences->WriteMFA (cout, ssCons);
+      }
+
+      delete sequences;
+  }
+  // if we are training
+  else if (enableTraining){
+
+    // build new model for aligning
+    ProbabilisticModel model (initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+
+    // prepare to average parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] = 0;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] = 0;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] = 0;
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] = 0;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] = 0;
+    }
+   
+    // align each file individually
+    for (int i = 0; i < (int) sequenceNames.size(); i++){
+
+      VF thisInitDistrib (NumMatrixTypes);
+      VF thisGapOpen (2*NumInsertStates);
+      VF thisGapExtend (2*NumInsertStates);
+      VVF thisEmitPairs (256, VF (256, 1e-10));
+      VF thisEmitSingle (256, 1e-5);
+      
+      // load sequence file
+      MultiSequence *sequences = new MultiSequence(); assert (sequences);
+      cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+      sequences->LoadMFA (sequenceNames[i], true);
+
+      // align sequences
+      DoAlign (sequences, model, thisInitDistrib, thisGapOpen, thisGapExtend, thisEmitPairs, thisEmitSingle);
+
+      // add in contribution of the derived parameters
+      for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] += thisInitDistrib[i];
+      for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] += thisGapOpen[i];
+      for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] += thisGapExtend[i];
+      if (enableTrainEmissions){
+       for (int i = 0; i < (int) emitPairs.size(); i++) 
+         for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] += thisEmitPairs[i][j];
+       for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] += thisEmitSingle[i];
+      }
+
+      delete sequences;
+    }
+
+    // compute new parameters and print them out
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] /= (int) sequenceNames.size();
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] /= (int) sequenceNames.size();
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] /= (int) sequenceNames.size();
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++) 
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] /= (int) sequenceNames.size();
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] /= sequenceNames.size();
+    }
+    
+    PrintParameters ("Trained parameter set:",
+                     initDistrib, gapOpen, gapExtend, emitPairs, emitSingle,
+                     parametersOutputFilename.c_str());
+  }
+  // pass
+  // if we are not training, we must simply want to align some sequences
+  else {
+    // load all files together
+    MultiSequence *sequences = new MultiSequence(); assert (sequences);
+    for (int i = 0; i < (int) sequenceNames.size(); i++){
+      cerr << "Loading sequence file: " << sequenceNames[i] << endl;
+
+      sequences->LoadMFA (sequenceNames[i], true);
+    }
+
+    // do all "pre-training" repetitions first
+    // NOT execute 
+    for (int ct = 0; ct < numPreTrainingReps; ct++){
+      enableTraining = true;
+
+      // build new model for aligning
+      ProbabilisticModel model (initDistrib, gapOpen, gapExtend, 
+                                emitPairs, emitSingle);
+
+      // do initial alignments
+      DoAlign (sequences, model, initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+
+      // print new parameters
+      PrintParameters ("Recomputed parameter set:", initDistrib, gapOpen, gapExtend, emitPairs, emitSingle, NULL);
+
+      enableTraining = false;
+    }
+
+    // now, we can perform the alignments and write them out
+    if (enableWebOutput) {
+       outputFile = new ofstream(weboutputFileName.c_str());
+       if (!outputFile) {
+           cerr << "cannot open output file." << weboutputFileName << endl;
+           exit(1);
+       }
+        *outputFile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
+       *outputFile << "<result>" << endl;
+    }
+       MultiSequence *alignment = DoAlign (sequences,
+                                           ProbabilisticModel (initDistrib, gapOpen, gapExtend,  emitPairs, emitSingle),
+                                           initDistrib, gapOpen, gapExtend, emitPairs, emitSingle);
+    
+
+    if (!enableAllPairs){
+       if (enableClustalWOutput) {
+           alignment->WriteALN (cout);
+       }
+       else if (enableWebOutput) {
+           alignment->WriteWEB (*outputFile, ssCons);
+//         computeStructureWithAlifold ();
+       }
+       else if (enableStockholmOutput) {
+           alignment->WriteSTOCKHOLM (cout, ssCons);
+       }
+       else if (enableMXSCARNAOutput) {
+           alignment->WriteMXSCARNA (cout, ssCons);
+       }
+       else {
+           alignment->WriteMFA (cout, ssCons);
+       }
+    }
+
+    if (enableWebOutput) {
+       *outputFile << "</result>" << endl;
+       delete outputFile;
+    }
+    
+    delete ssCons;
+    delete alignment;
+    delete sequences;
+   
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintHeading()
+//
+// Prints heading for PROBCONS program.
+/////////////////////////////////////////////////////////////////
+
+void PrintHeading (){
+  cerr << endl
+       << "Multiplex SCARNA"<< endl
+       << "version " << VERSION << " - align multiple RNA sequences and print to standard output" << endl
+       << "Written by Yasuo Tabei" << endl
+       << endl;
+}
+
+/////////////////////////////////////////////////////////////////
+// PrintParameters()
+//
+// Prints PROBCONS parameters to STDERR.  If a filename is
+// specified, then the parameters are also written to the file.
+/////////////////////////////////////////////////////////////////
+
+void PrintParameters (const char *message, const VF &initDistrib, const VF &gapOpen,
+                      const VF &gapExtend, const VVF &emitPairs, const VF &emitSingle, const char *filename){
+
+  // print parameters to the screen
+  cerr << message << endl
+       << "    initDistrib[] = { ";
+  for (int i = 0; i < NumMatrixTypes; i++) cerr << setprecision (10) << initDistrib[i] << " ";
+  cerr << "}" << endl
+       << "        gapOpen[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapOpen[i] << " ";
+  cerr << "}" << endl
+       << "      gapExtend[] = { ";
+  for (int i = 0; i < NumInsertStates*2; i++) cerr << setprecision (10) << gapExtend[i] << " ";
+  cerr << "}" << endl
+       << endl;
+
+  /*
+  for (int i = 0; i < 5; i++){
+    for (int j = 0; j <= i; j++){
+      cerr << emitPairs[(unsigned char) alphabet[i]][(unsigned char) alphabet[j]] << " ";
+    }
+    cerr << endl;
+    }*/
+
+  // if a file name is specified
+  if (filename){
+
+    // attempt to open the file for writing
+    FILE *file = fopen (filename, "w");
+    if (!file){
+      cerr << "ERROR: Unable to write parameter file: " << filename << endl;
+      exit (1);
+    }
+
+    // if successful, then write the parameters to the file
+    for (int i = 0; i < NumMatrixTypes; i++) fprintf (file, "%.10f ", initDistrib[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapOpen[i]); fprintf (file, "\n");
+    for (int i = 0; i < 2*NumInsertStates; i++) fprintf (file, "%.10f ", gapExtend[i]); fprintf (file, "\n");
+    fprintf (file, "%s\n", alphabet.c_str());
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      for (int j = 0; j <= i; j++)
+       fprintf (file, "%.10f ", emitPairs[(unsigned char) alphabet[i]][(unsigned char) alphabet[j]]);
+      fprintf (file, "\n");
+    }
+    for (int i = 0; i < (int) alphabet.size(); i++)
+      fprintf (file, "%.10f ", emitSingle[(unsigned char) alphabet[i]]);
+    fprintf (file, "\n");
+    fclose (file);
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoAlign()
+//
+// First computes all pairwise posterior probability matrices.
+// Then, computes new parameters if training, or a final
+// alignment, otherwise.
+/////////////////////////////////////////////////////////////////
+MultiSequence *DoAlign (MultiSequence *sequences, const ProbabilisticModel &model, VF &initDistrib, VF &gapOpen, VF &gapExtend, VVF &emitPairs, VF &emitSingle){
+
+  assert (sequences);
+
+  const int numSeqs = sequences->GetNumSequences();
+  VVF distances (numSeqs, VF (numSeqs, 0));
+  VVF identities (numSeqs, VF (numSeqs, 0));
+  SafeVector<SafeVector<SparseMatrix *> > sparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+  
+  SafeVector<BPPMatrix*> BPPMatrices;
+  
+  RfoldWrapper rfoldWrapper;
+  if (useRfold) {
+    BPPMatrices 
+      = rfoldWrapper.getProb(sequenceNames, sequences, BASEPROBTHRESHOLD, BandWidth);
+  }
+  else {
+    for(int i = 0; i < numSeqs; i++) {
+      Sequence *tmpSeq = sequences->GetSequence(i);
+      string   seq = tmpSeq->GetString();
+      int    n_seq = tmpSeq->GetLength();
+      BPPMatrix *bppmat = new BPPMatrix(seq, n_seq, BASEPROBTHRESHOLD);
+      BPPMatrices.push_back(bppmat);
+    }
+  }
+    
+  if (enableTraining){
+    // prepare to average parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] = 0;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] = 0;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] = 0;
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] = 0;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] = 0;
+    }
+  }
+
+  // skip posterior calculations if we just want to do Viterbi alignments
+  if (!enableViterbi){
+
+    // do all pairwise alignments for posterior probability matrices
+    for (int a = 0; a < numSeqs-1; a++){
+      for (int b = a+1; b < numSeqs; b++){
+       Sequence *seq1 = sequences->GetSequence (a); 
+       Sequence *seq2 = sequences->GetSequence (b);
+       
+       // verbose output
+       if (enableVerbose)
+         cerr << "Computing posterior matrix: (" << a+1 << ") " << seq1->GetHeader() << " vs. "
+              << "(" << b+1 << ") " << seq2->GetHeader() << " -- ";
+       
+       // compute forward and backward probabilities
+       VF *forward = model.ComputeForwardMatrix (seq1, seq2); assert (forward);
+       VF *backward = model.ComputeBackwardMatrix (seq1, seq2); assert (backward);
+       
+       // if we are training, then we'll simply want to compute the
+       // expected counts for each region within the matrix separately;
+       // otherwise, we'll need to put all of the regions together and
+       // assemble a posterior probability match matrix
+       
+       // so, if we're training
+       if (enableTraining){
+         
+         // compute new parameters
+         VF thisInitDistrib (NumMatrixTypes);
+         VF thisGapOpen (2*NumInsertStates);
+         VF thisGapExtend (2*NumInsertStates);
+         VVF thisEmitPairs (256, VF (256, 1e-10));
+         VF thisEmitSingle (256, 1e-5);
+         
+         model.ComputeNewParameters (seq1, seq2, *forward, *backward, thisInitDistrib, thisGapOpen, thisGapExtend, thisEmitPairs, thisEmitSingle, enableTrainEmissions);
+
+         // add in contribution of the derived parameters
+         for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] += thisInitDistrib[i];
+         for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] += thisGapOpen[i];
+         for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] += thisGapExtend[i];
+         if (enableTrainEmissions){
+           for (int i = 0; i < (int) emitPairs.size(); i++) 
+             for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] += thisEmitPairs[i][j];
+           for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] += thisEmitSingle[i];
+         }
+
+         // let us know that we're done.
+         if (enableVerbose) cerr << "done." << endl;
+       }
+       // pass
+       else {
+
+         // compute posterior probability matrix
+         VF *posterior = model.ComputePosteriorMatrix (seq1, seq2, *forward, *backward); assert (posterior);
+
+         // compute sparse representations
+         sparseMatrices[a][b] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), *posterior);
+         sparseMatrices[b][a] = NULL; 
+         
+         if (!enableAllPairs){
+           // perform the pairwise sequence alignment
+           pair<SafeVector<char> *, float> alignment = model.ComputeAlignment (seq1->GetLength(),
+                                                                               seq2->GetLength(),
+                                                                               *posterior);
+           
+           Sequence *tmpSeq1 = seq1->AddGaps (alignment.first, 'X');
+           Sequence *tmpSeq2 = seq2->AddGaps (alignment.first, 'Y');
+
+           // compute sequence identity for each pair of sequenceses
+           int length = tmpSeq1->GetLength();
+           int matchCount = 0;
+           int misMatchCount = 0;
+           for (int k = 1; k <= length; k++) {
+               int ch1 = tmpSeq1->GetPosition(k);
+               int ch2 = tmpSeq2->GetPosition(k);
+               if (ch1 == ch2 && ch1 != '-' && ch2 != '-') { ++matchCount; }
+               else if (ch1 != ch2 && ch1 != '-' && ch2 != '-') { ++misMatchCount; }
+           }
+
+           identities[a][b] = identities[b][a] = (float)matchCount/(float)(matchCount + misMatchCount);
+
+           // compute "expected accuracy" distance for evolutionary tree computation
+           float distance = alignment.second / min (seq1->GetLength(), seq2->GetLength());
+           distances[a][b] = distances[b][a] = distance;
+           
+           if (enableVerbose)
+             cerr << setprecision (10) << distance << endl;
+           
+             delete alignment.first;
+         }
+         else {
+           // let us know that we're done.
+           if (enableVerbose) cerr << "done." << endl;
+         }
+         
+         delete posterior;
+       }
+       
+       delete forward;
+       delete backward;
+      }
+    }
+  }
+
+  // now average out parameters derived
+  if (enableTraining){
+    // compute new parameters
+    for (int i = 0; i < (int) initDistrib.size(); i++) initDistrib[i] /= numSeqs * (numSeqs - 1) / 2;
+    for (int i = 0; i < (int) gapOpen.size(); i++) gapOpen[i] /= numSeqs * (numSeqs - 1) / 2;
+    for (int i = 0; i < (int) gapExtend.size(); i++) gapExtend[i] /= numSeqs * (numSeqs - 1) / 2;
+
+    if (enableTrainEmissions){
+      for (int i = 0; i < (int) emitPairs.size(); i++)
+       for (int j = 0; j < (int) emitPairs[i].size(); j++) emitPairs[i][j] /= numSeqs * (numSeqs - 1) / 2;
+      for (int i = 0; i < (int) emitSingle.size(); i++) emitSingle[i] /= numSeqs * (numSeqs - 1) / 2;
+    }
+  }
+
+  // see if we still want to do some alignments
+  else {
+      // pass
+    if (!enableViterbi){
+
+      // perform the consistency transformation the desired number of times
+      for (int r = 0; r < numConsistencyReps; r++){
+       SafeVector<SafeVector<SparseMatrix *> > newSparseMatrices = DoRelaxation (sequences, sparseMatrices);
+
+       // now replace the old posterior matrices
+       for (int i = 0; i < numSeqs; i++){
+         for (int j = 0; j < numSeqs; j++){
+           delete sparseMatrices[i][j];
+           sparseMatrices[i][j] = newSparseMatrices[i][j];
+         }
+       }
+      }
+      if (numSeqs > 8) {
+       for (int r = 0; r < 1; r++) 
+         DoBasePairProbabilityRelaxation(sequences, sparseMatrices, BPPMatrices);
+      }
+    }
+
+    MultiSequence *finalAlignment = NULL;
+
+    if (enableAllPairs){
+      for (int a = 0; a < numSeqs-1; a++){
+       for (int b = a+1; b < numSeqs; b++){
+         Sequence *seq1 = sequences->GetSequence (a);
+         Sequence *seq2 = sequences->GetSequence (b);
+         
+         if (enableVerbose)
+           cerr << "Performing pairwise alignment: (" << a+1 << ") " << seq1->GetHeader() << " vs. "
+                << "(" << b+1 << ") " << seq2->GetHeader() << " -- ";
+
+         
+         // perform the pairwise sequence alignment
+         pair<SafeVector<char> *, float> alignment;
+         if (enableViterbi)
+           alignment = model.ComputeViterbiAlignment (seq1, seq2);
+         else {
+
+           // build posterior matrix
+           VF *posterior = sparseMatrices[a][b]->GetPosterior(); assert (posterior);
+           int length = (seq1->GetLength() + 1) * (seq2->GetLength() + 1);
+           for (int i = 0; i < length; i++) (*posterior)[i] -= cutoff;
+
+           alignment = model.ComputeAlignment (seq1->GetLength(), seq2->GetLength(), *posterior);
+           delete posterior;
+         }
+
+         // write pairwise alignments 
+         string name = seq1->GetHeader() + "-" + seq2->GetHeader() + (enableClustalWOutput ? ".aln" : ".fasta");
+         ofstream outfile (name.c_str());
+         
+         MultiSequence *result = new MultiSequence();
+         result->AddSequence (seq1->AddGaps(alignment.first, 'X'));
+         result->AddSequence (seq2->AddGaps(alignment.first, 'Y'));
+         if (enableClustalWOutput)
+           result->WriteALN (outfile);
+         else
+           result->WriteMFA (outfile);
+         
+         outfile.close();
+         
+         delete alignment.first;
+       }
+      }
+    }
+    
+    // now if we still need to do a final multiple alignment
+    else {
+      
+      if (enableVerbose)
+       cerr << endl;
+      
+      // compute the evolutionary tree
+      TreeNode *tree = TreeNode::ComputeTree (distances, identities);
+      
+      if (enableWebOutput) {
+         *outputFile << "<tree>" << endl;
+         tree->Print (*outputFile, sequences);
+         *outputFile << "</tree>" << endl;
+      }
+      else {
+         tree->Print (cerr, sequences);
+         cerr << endl;
+      }
+      // make the final alignment
+      finalAlignment = ComputeFinalAlignment (tree, sequences, sparseMatrices, model, BPPMatrices);
+      
+      // build annotation
+      if (enableAnnotation){
+       WriteAnnotation (finalAlignment, sparseMatrices);
+      }
+
+      delete tree;
+    }
+
+    if (!enableViterbi){
+      // delete sparse matrices
+      for (int a = 0; a < numSeqs-1; a++){
+       for (int b = a+1; b < numSeqs; b++){
+         delete sparseMatrices[a][b];
+         delete sparseMatrices[b][a];
+       }
+      }
+    }
+
+    AlifoldMEA alifold(finalAlignment, BPPMatrices, BasePairConst);
+    alifold.Run();
+    ssCons = alifold.getSScons();
+
+    return finalAlignment;
+
+  }
+
+  return NULL;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetInteger()
+//
+// Attempts to parse an integer from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetInteger (char *data, int *val){
+  char *endPtr;
+  long int retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtol (data, &endPtr, 0);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal == LONG_MAX || retVal == LONG_MIN)) return false;
+  if (retVal < (long) INT_MIN || retVal > (long) INT_MAX) return false;
+  *val = (int) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// GetFloat()
+//
+// Attempts to parse a float from the character string given.
+// Returns true only if no parsing error occurs.
+/////////////////////////////////////////////////////////////////
+
+bool GetFloat (char *data, float *val){
+  char *endPtr;
+  double retVal;
+
+  assert (val);
+
+  errno = 0;
+  retVal = strtod (data, &endPtr);
+  if (retVal == 0 && (errno != 0 || data == endPtr)) return false;
+  if (errno != 0 && (retVal >= 1000000.0 || retVal <= -1000000.0)) return false;
+  *val = (float) retVal;
+  return true;
+}
+
+/////////////////////////////////////////////////////////////////
+// ParseParams()
+//
+// Parse all command-line options.
+/////////////////////////////////////////////////////////////////
+
+SafeVector<string> ParseParams (int argc, char **argv){
+
+  if (argc < 2){
+
+    cerr << "MXSCARNA comes with ABSOLUTELY NO WARRANTY.  This is free software, and" << endl
+         << "you are welcome to redistribute it under certain conditions.  See the" << endl
+         << "file COPYING.txt for details." << endl
+         << endl
+         << "Usage:" << endl
+         << "       mxscarna [OPTION]... [MFAFILE]..." << endl
+         << endl
+         << "Description:" << endl
+         << "       Align sequences in MFAFILE(s) and print result to standard output" << endl
+         << endl
+         << "       -clustalw" << endl
+         << "              use CLUSTALW output format instead of MFA" << endl
+        << endl
+        << "       -stockholm" << endl
+         << "              use STOCKHOLM output format instead of MFA" << endl
+        << endl
+        << "       -mxscarna" << endl
+         << "              use MXSCARNA output format instead of MFA" << endl
+        << endl
+        << "       -weboutput /<output_path>/<outputfilename>" << endl
+        << "        use web output format" << endl
+        << endl
+         << "       -c, --consistency REPS" << endl
+         << "              use " << MIN_CONSISTENCY_REPS << " <= REPS <= " << MAX_CONSISTENCY_REPS
+         << " (default: " << numConsistencyReps << ") passes of consistency transformation" << endl
+         << endl
+         << "       -ir, --iterative-refinement REPS" << endl
+         << "              use " << MIN_ITERATIVE_REFINEMENT_REPS << " <= REPS <= " << MAX_ITERATIVE_REFINEMENT_REPS
+         << " (default: " << numIterativeRefinementReps << ") passes of iterative-refinement" << endl
+         << endl
+        << "       -pre, --pre-training REPS" << endl
+        << "              use " << MIN_PRETRAINING_REPS << " <= REPS <= " << MAX_PRETRAINING_REPS
+        << " (default: " << numPreTrainingReps << ") rounds of pretraining" << endl
+        << endl
+        << "       -pairs" << endl
+         << "              generate all-pairs pairwise alignments" << endl
+         << endl
+        << "       -viterbi" << endl
+        << "              use Viterbi algorithm to generate all pairs (automatically enables -pairs)" << endl
+        << endl
+         << "       -v, --verbose" << endl
+         << "              report progress while aligning (default: " << (enableVerbose ? "on" : "off") << ")" << endl
+         << endl
+         << "       -annot FILENAME" << endl
+         << "              write annotation for multiple alignment to FILENAME" << endl
+         << endl
+         << "       -t, --train FILENAME" << endl
+         << "              compute EM transition probabilities, store in FILENAME (default: "
+         << parametersOutputFilename << ")" << endl
+         << endl
+         << "       -e, --emissions" << endl
+         << "              also reestimate emission probabilities (default: "
+         << (enableTrainEmissions ? "on" : "off") << ")" << endl
+         << endl
+        << "       -p, --paramfile FILENAME" << endl
+        << "              read parameters from FILENAME (default: "
+        << parametersInputFilename << ")" << endl
+        << endl
+        << "       -a, --alignment-order" << endl
+        << "              print sequences in alignment order rather than input order (default: "
+        << (enableAlignOrder ? "on" : "off") << ")" << endl
+        << endl
+        << "       -s THRESHOLD" << endl
+        << "               the threshold of SCS alignment" << endl
+        << endl
+        << "               In default, for less than " << threshhold << ", the SCS aligment is applied. " << endl
+        << "       -l SCSLENGTH" << endl
+        << "               the length of stem candidates " << SCSLENGTH << endl
+        << endl
+        << "       -b BASEPROBTRHESHHOLD" << endl
+        << "               the threshold of base pairing probability " << BASEPROBTHRESHOLD << endl
+        << endl
+        << "       -m, --mccaskillmea" << endl
+        << "               McCaskill MEA MODE: input the clustalw format file and output the secondary structure predicted by McCaskill MEA" << endl
+        << endl
+        << "       -g BASEPAIRSCORECONST" << endl
+        << "               the control parameter of the prediction of base pairs, default:" << BasePairConst << endl
+         << endl
+        << "       -w BANDWIDTH" << endl
+        << "               the control parameter of the distance of stem candidates, default:" << BANDWIDTH << endl
+        << "       -rfold" << endl
+        << "               use Rfold instead of global McCaskill algorithm to calcurate base paring probality matrices, default: (" << (useRfold? "on" : "off") << ")" << endl
+        << endl; 
+
+
+    //          << "       -go, --gap-open VALUE" << endl
+    //          << "              gap opening penalty of VALUE <= 0 (default: " << gapOpenPenalty << ")" << endl
+    //  << endl
+    //  << "       -ge, --gap-extension VALUE" << endl
+    //  << "              gap extension penalty of VALUE <= 0 (default: " << gapContinuePenalty << ")" << endl
+    //  << endl
+    //         << "       -co, --cutoff CUTOFF" << endl
+    //         << "              subtract 0 <= CUTOFF <= 1 (default: " << cutoff << ") from all posterior values before final alignment" << endl
+    //         << endl
+    
+    exit (1);
+  }
+
+  SafeVector<string> sequenceNames;
+  int tempInt;
+  float tempFloat;
+
+  for (int i = 1; i < argc; i++){
+    if (argv[i][0] == '-'){
+
+      // training
+      if (!strcmp (argv[i], "-t") || !strcmp (argv[i], "--train")){
+        enableTraining = true;
+        if (i < argc - 1)
+          parametersOutputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      
+      // emission training
+      else if (!strcmp (argv[i], "-e") || !strcmp (argv[i], "--emissions")){
+        enableTrainEmissions = true;
+      }
+
+      // parameter file
+      else if (!strcmp (argv[i], "-p") || !strcmp (argv[i], "--paramfile")){
+        if (i < argc - 1)
+          parametersInputFilename = string (argv[++i]);
+        else {
+          cerr << "ERROR: Filename expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      else if (! strcmp (argv[i], "-s")) {
+       if (i < argc - 1){
+         if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat < 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+              exit (1);
+            }
+            else
+              threshhold = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      
+      else if (! strcmp (argv[i], "-l")) {
+         if (i < argc - 1) {
+             if (!GetInteger (argv[++i], &tempInt)){
+                 cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempInt <= 0 || 6 <= tempInt) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                          << "1 and 6" << "." << endl;
+                     exit (1);
+                 }
+                 else
+                     scsLength = tempInt;
+             }
+         }
+      }
+      else if (! strcmp (argv[i], "-b")) {
+         if (i < argc - 1) {
+             if (!GetFloat (argv[++i], &tempFloat)){
+                 cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempFloat < 0 && 1 < tempFloat) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+                     exit (1);
+                 }
+                 else
+                     BaseProbThreshold = tempFloat;
+             }
+         }
+      }
+      else if (! strcmp (argv[i], "-g")) {
+         if (i < argc - 1) {
+             if (!GetFloat (argv[++i], &tempFloat)){
+                 cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+                 exit (1);
+             }
+             else {
+                 if (tempFloat < 0 && 1 < tempFloat) {
+                     cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be nagative." << endl;
+                     exit (1);
+                 }
+                 else
+                     BasePairConst = tempFloat;
+             }
+         }
+      }
+      
+      // number of consistency transformations
+      else if (!strcmp (argv[i], "-c") || !strcmp (argv[i], "--consistency")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_CONSISTENCY_REPS || tempInt > MAX_CONSISTENCY_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_CONSISTENCY_REPS << " and " << MAX_CONSISTENCY_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numConsistencyReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // number of randomized partitioning iterative refinement passes
+      else if (!strcmp (argv[i], "-ir") || !strcmp (argv[i], "--iterative-refinement")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_ITERATIVE_REFINEMENT_REPS || tempInt > MAX_ITERATIVE_REFINEMENT_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_ITERATIVE_REFINEMENT_REPS << " and " << MAX_ITERATIVE_REFINEMENT_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numIterativeRefinementReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+      else if (!strcmp (argv[i], "-rfold")){
+        useRfold = true;
+      }
+      // number of EM pre-training rounds
+      else if (!strcmp (argv[i], "-pre") || !strcmp (argv[i], "--pre-training")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempInt < MIN_PRETRAINING_REPS || tempInt > MAX_PRETRAINING_REPS){
+              cerr << "ERROR: For option " << argv[i-1] << ", integer must be between "
+                   << MIN_PRETRAINING_REPS << " and " << MAX_PRETRAINING_REPS << "." << endl;
+              exit (1);
+            }
+            else
+              numPreTrainingReps = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // the distance of stem candidate
+      else if (!strcmp (argv[i], "-w")){
+        if (i < argc - 1){
+          if (!GetInteger (argv[++i], &tempInt)){
+            cerr << "ERROR: Invalid integer following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+              BandWidth = tempInt;
+          }
+        }
+        else {
+          cerr << "ERROR: Integer expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap open penalty
+      else if (!strcmp (argv[i], "-go") || !strcmp (argv[i], "--gap-open")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapOpenPenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // gap extension penalty
+      else if (!strcmp (argv[i], "-ge") || !strcmp (argv[i], "--gap-extension")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat > 0){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must not be positive." << endl;
+              exit (1);
+            }
+            else
+              gapContinuePenalty = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // all-pairs pairwise alignments
+      else if (!strcmp (argv[i], "-pairs")){
+        enableAllPairs = true;
+      }
+
+      // all-pairs pairwise Viterbi alignments
+      else if (!strcmp (argv[i], "-viterbi")){
+        enableAllPairs = true;
+       enableViterbi = true;
+      }
+
+      // annotation files
+      else if (!strcmp (argv[i], "-annot")){
+        enableAnnotation = true;
+        if (i < argc - 1)
+         annotationFilename = argv[++i];
+        else {
+          cerr << "ERROR: FILENAME expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // clustalw output format
+      else if (!strcmp (argv[i], "-clustalw")){
+       enableClustalWOutput = true;
+      }
+      // mxscarna output format
+      else if (!strcmp (argv[i], "-mxscarna")) {
+         enableMXSCARNAOutput = true;
+      }
+      // stockholm output format
+      else if (!strcmp (argv[i], "-stockholm")) {
+         enableStockholmOutput = true;
+      }
+      // web output format
+      else if (!strcmp (argv[i], "-weboutput")) {
+         if (i < argc - 1) {
+             weboutputFileName = string(argv[++i]);
+         }
+         else {
+             cerr << "ERROR: Invalid following option " << argv[i-1] << ": " << argv[i] << endl;
+             exit (1);
+         }
+
+         enableWebOutput = true;
+      }
+
+      // cutoff
+      else if (!strcmp (argv[i], "-co") || !strcmp (argv[i], "--cutoff")){
+        if (i < argc - 1){
+          if (!GetFloat (argv[++i], &tempFloat)){
+            cerr << "ERROR: Invalid floating-point value following option " << argv[i-1] << ": " << argv[i] << endl;
+            exit (1);
+          }
+          else {
+            if (tempFloat < 0 || tempFloat > 1){
+              cerr << "ERROR: For option " << argv[i-1] << ", floating-point value must be between 0 and 1." << endl;
+              exit (1);
+            }
+            else
+              cutoff = tempFloat;
+          }
+        }
+        else {
+          cerr << "ERROR: Floating-point value expected for option " << argv[i] << endl;
+          exit (1);
+        }
+      }
+
+      // verbose reporting
+      else if (!strcmp (argv[i], "-v") || !strcmp (argv[i], "--verbose")){
+        enableVerbose = true;
+      }
+
+      // alignment order
+      else if (!strcmp (argv[i], "-a") || !strcmp (argv[i], "--alignment-order")){
+       enableAlignOrder = true;
+      }
+      // McCaskill MEA MODE
+      else if (!strcmp (argv[i], "-m") || !strcmp (argv[i], "--mccaskillmea")){
+        enableMcCaskillMEAMode = true;
+      }
+      // bad arguments
+      else {
+        cerr << "ERROR: Unrecognized option: " << argv[i] << endl;
+        exit (1);
+      }
+    }
+    else {
+      sequenceNames.push_back (string (argv[i]));
+    }
+  }
+
+  if (enableTrainEmissions && !enableTraining){
+    cerr << "ERROR: Training emissions (-e) requires training (-t)" << endl;
+    exit (1);
+  }
+
+  return sequenceNames;
+}
+
+/////////////////////////////////////////////////////////////////
+// ReadParameters()
+//
+// Read initial distribution, transition, and emission
+// parameters from a file.
+/////////////////////////////////////////////////////////////////
+
+void ReadParameters (){
+
+  ifstream data;
+
+  emitPairs = VVF (256, VF (256, 1e-10));
+  emitSingle = VF (256, 1e-5);
+
+  // read initial state distribution and transition parameters
+  // pass
+  if (parametersInputFilename == string ("")){
+    if (NumInsertStates == 1){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen1Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend1Default[i];
+    }
+    else if (NumInsertStates == 2){
+      for (int i = 0; i < NumMatrixTypes; i++) initDistrib[i] = initDistrib2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapOpen[i] = gapOpen2Default[i];
+      for (int i = 0; i < 2*NumInsertStates; i++) gapExtend[i] = gapExtend2Default[i];
+    }
+    else {
+      cerr << "ERROR: No default initial distribution/parameter settings exist" << endl
+           << "       for " << NumInsertStates << " pairs of insert states.  Use --paramfile." << endl;
+      exit (1);
+    }
+
+    alphabet = alphabetDefault;
+
+    for (int i = 0; i < (int) alphabet.length(); i++){
+      emitSingle[(unsigned char) tolower(alphabet[i])] = emitSingleDefault[i];
+      emitSingle[(unsigned char) toupper(alphabet[i])] = emitSingleDefault[i];
+      for (int j = 0; j <= i; j++){
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) tolower(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) toupper(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) tolower(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) toupper(alphabet[j])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) tolower(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) toupper(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) tolower(alphabet[i])] = emitPairsDefault[i][j];
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) toupper(alphabet[i])] = emitPairsDefault[i][j];
+      }
+    }
+  }
+  else {
+    data.open (parametersInputFilename.c_str());
+    if (data.fail()){
+      cerr << "ERROR: Unable to read parameter file: " << parametersInputFilename << endl;
+      exit (1);
+    }
+    
+    string line[3];
+    for (int i = 0; i < 3; i++){
+      if (!getline (data, line[i])){
+       cerr << "ERROR: Unable to read transition parameters from parameter file: " << parametersInputFilename << endl;
+       exit (1);
+      }
+    }
+    istringstream data2;
+    data2.clear(); data2.str (line[0]); for (int i = 0; i < NumMatrixTypes; i++) data2 >> initDistrib[i];
+    data2.clear(); data2.str (line[1]); for (int i = 0; i < 2*NumInsertStates; i++) data2 >> gapOpen[i];
+    data2.clear(); data2.str (line[2]); for (int i = 0; i < 2*NumInsertStates; i++) data2 >> gapExtend[i];
+
+    if (!getline (data, line[0])){
+      cerr << "ERROR: Unable to read alphabet from scoring matrix file: " << parametersInputFilename << endl;
+      exit (1);
+    }
+    
+    // read alphabet as concatenation of all characters on alphabet line
+    alphabet = "";
+    string token;
+    data2.clear(); data2.str (line[0]); while (data2 >> token) alphabet += token;
+
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      for (int j = 0; j <= i; j++){
+       float val;
+        data >> val;
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) tolower(alphabet[j])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[i])][(unsigned char) toupper(alphabet[j])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) tolower(alphabet[j])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[i])][(unsigned char) toupper(alphabet[j])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) tolower(alphabet[i])] = val;
+       emitPairs[(unsigned char) tolower(alphabet[j])][(unsigned char) toupper(alphabet[i])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) tolower(alphabet[i])] = val;
+       emitPairs[(unsigned char) toupper(alphabet[j])][(unsigned char) toupper(alphabet[i])] = val;
+      }
+    }
+
+    for (int i = 0; i < (int) alphabet.size(); i++){
+      float val;
+      data >> val;
+      emitSingle[(unsigned char) tolower(alphabet[i])] = val;
+      emitSingle[(unsigned char) toupper(alphabet[i])] = val;
+    }
+    data.close();
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// ProcessTree()
+//
+// Process the tree recursively.  Returns the aligned sequences
+// corresponding to a node or leaf of the tree.
+/////////////////////////////////////////////////////////////////
+float ide;
+MultiSequence *ProcessTree (const TreeNode *tree, MultiSequence *sequences,
+                            const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, SafeVector<BPPMatrix*> &BPPMatrices) {
+  MultiSequence *result;
+
+  // check if this is a node of the alignment tree
+  if (tree->GetSequenceLabel() == -1){
+    MultiSequence *alignLeft = ProcessTree (tree->GetLeftChild(), sequences, sparseMatrices, model, BPPMatrices);
+    MultiSequence *alignRight = ProcessTree (tree->GetRightChild(), sequences, sparseMatrices, model, BPPMatrices);
+
+    assert (alignLeft);
+    assert (alignRight);
+    
+    result = AlignAlignments (alignLeft, alignRight, sparseMatrices, model, BPPMatrices, tree->GetIdentity());
+    assert (result);
+
+    delete alignLeft;
+    delete alignRight;
+  }
+
+  // otherwise, this is a leaf of the alignment tree
+  else {
+    result = new MultiSequence(); assert (result);
+    result->AddSequence (sequences->GetSequence(tree->GetSequenceLabel())->Clone());
+  }
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeFinalAlignment()
+//
+// Compute the final alignment by calling ProcessTree(), then
+// performing iterative refinement as needed.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *ComputeFinalAlignment (const TreeNode *tree, MultiSequence *sequences,
+                                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                      const ProbabilisticModel &model, 
+                                     SafeVector<BPPMatrix*> &BPPMatrices) { 
+
+  MultiSequence *alignment = ProcessTree (tree, sequences, sparseMatrices, model, BPPMatrices);
+
+  if (enableAlignOrder){
+    alignment->SaveOrdering();
+    enableAlignOrder = false;
+  }
+
+  // tree-based refinement 
+  // if you use the function, you can degrade the quality of the software.
+  // TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree, BPPMatrices);
+
+  // iterative refinement
+/*
+  for (int i = 0; i < numIterativeRefinementReps; i++)
+      DoIterativeRefinement (sparseMatrices, model, alignment);
+
+      cerr << endl;
+*/
+  // return final alignment
+  return alignment;
+}
+
+/////////////////////////////////////////////////////////////////
+// AlignAlignments()
+//
+// Returns the alignment of two MultiSequence objects.
+/////////////////////////////////////////////////////////////////
+
+MultiSequence *AlignAlignments (MultiSequence *align1, MultiSequence *align2,
+                                const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                const ProbabilisticModel &model, 
+                               SafeVector<BPPMatrix*> &BPPMatrices, float identity){
+
+  // print some info about the alignment
+  if (enableVerbose){
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align1->GetSequence(i)->GetLabel();
+    cerr << "] vs. ";
+    for (int i = 0; i < align2->GetNumSequences(); i++)
+      cerr << ((i==0) ? "[" : ",") << align2->GetSequence(i)->GetLabel();
+    cerr << "]: ";
+  }
+
+  VF *posterior = model.BuildPosterior (align1, align2, sparseMatrices, cutoff);
+
+  pair<SafeVector<char> *, float> alignment;
+  // choose the alignment routine depending on the "cosmetic" gap penalties used
+  if (gapOpenPenalty == 0 && gapContinuePenalty == 0) {
+
+    if(identity < threshhold) {
+       std::vector<StemCandidate> *pscs1, *pscs2;
+       pscs1 = seq2scs(align1, BPPMatrices, BandWidth);
+       pscs2 = seq2scs(align2, BPPMatrices, BandWidth);
+       std::vector<int> *matchPSCS1 = new std::vector<int>;
+       std::vector<int> *matchPSCS2 = new std::vector<int>;
+
+       Globaldp globaldp(pscs1, pscs2, align1, align2, matchPSCS1, matchPSCS2, posterior, BPPMatrices);
+       //float scsScore = globaldp.Run();
+
+       globaldp.Run();
+
+       removeConflicts(pscs1, pscs2, matchPSCS1, matchPSCS2);
+
+       alignment = model.ComputeAlignment2 (align1->GetSequence(0)->GetLength(), align2->GetSequence(0)->GetLength(), *posterior, pscs1, pscs2, matchPSCS1, matchPSCS2);
+
+    } else {
+       alignment = model.ComputeAlignment (align1->GetSequence(0)->GetLength(), align2->GetSequence(0)->GetLength(), *posterior);
+    }
+  }
+  else {
+    alignment = model.ComputeAlignmentWithGapPenalties (align1, align2,
+                                                        *posterior, align1->GetNumSequences(), align2->GetNumSequences(),
+                                                        gapOpenPenalty, gapContinuePenalty);
+  }
+
+  delete posterior;
+
+  if (enableVerbose){
+
+    // compute total length of sequences
+    int totLength = 0;
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      for (int j = 0; j < align2->GetNumSequences(); j++)
+        totLength += min (align1->GetSequence(i)->GetLength(), align2->GetSequence(j)->GetLength());
+
+    // give an "accuracy" measure for the alignment
+    cerr << alignment.second / totLength << endl;
+  }
+
+  // now build final alignment
+  MultiSequence *result = new MultiSequence();
+  for (int i = 0; i < align1->GetNumSequences(); i++)
+    result->AddSequence (align1->GetSequence(i)->AddGaps(alignment.first, 'X'));
+  for (int i = 0; i < align2->GetNumSequences(); i++)
+    result->AddSequence (align2->GetSequence(i)->AddGaps(alignment.first, 'Y'));
+  if (!enableAlignOrder)
+    result->SortByLabel();
+
+  // free temporary alignment
+  delete alignment.first;
+
+  return result;
+}
+
+/////////////////////////////////////////////////////////////////
+// DoRelaxation()
+//
+// Performs one round of the consistency transformation.  The
+// formula used is:
+//                     1
+//    P'(x[i]-y[j]) = ---  sum   sum P(x[i]-z[k]) P(z[k]-y[j])
+//                    |S| z in S  k
+//
+// where S = {x, y, all other sequences...}
+//
+/////////////////////////////////////////////////////////////////
+
+SafeVector<SafeVector<SparseMatrix *> > DoRelaxation (MultiSequence *sequences, 
+                                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+  const int numSeqs = sequences->GetNumSequences();
+
+  SafeVector<SafeVector<SparseMatrix *> > newSparseMatrices (numSeqs, SafeVector<SparseMatrix *>(numSeqs, NULL));
+
+  // for every pair of sequences
+  for (int i = 0; i < numSeqs; i++){
+    for (int j = i+1; j < numSeqs; j++){
+      Sequence *seq1 = sequences->GetSequence (i);
+      Sequence *seq2 = sequences->GetSequence (j);
+      
+      if (enableVerbose)
+        cerr << "Relaxing (" << i+1 << ") " << seq1->GetHeader() << " vs. "
+             << "(" << j+1 << ") " << seq2->GetHeader() << ": ";
+
+      // get the original posterior matrix
+      VF *posteriorPtr = sparseMatrices[i][j]->GetPosterior(); assert (posteriorPtr);
+      VF &posterior = *posteriorPtr;
+
+      const int seq1Length = seq1->GetLength();
+      const int seq2Length = seq2->GetLength();
+
+      // contribution from the summation where z = x and z = y
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] += posterior[k];
+
+      if (enableVerbose)
+        cerr << sparseMatrices[i][j]->GetNumCells() << " --> ";
+
+      // contribution from all other sequences
+      for (int k = 0; k < numSeqs; k++) if (k != i && k != j){
+       if (k < i)
+         Relax1 (sparseMatrices[k][i], sparseMatrices[k][j], posterior);
+       else if (k > i && k < j)
+         Relax (sparseMatrices[i][k], sparseMatrices[k][j], posterior);
+       else {
+         SparseMatrix *temp = sparseMatrices[j][k]->ComputeTranspose();
+         Relax (sparseMatrices[i][k], temp, posterior);
+         delete temp;
+       }
+      }
+
+      // now renormalization
+      for (int k = 0; k < (seq1Length+1) * (seq2Length+1); k++) posterior[k] /= numSeqs;
+
+      // mask out positions not originally in the posterior matrix
+      SparseMatrix *matXY = sparseMatrices[i][j];
+      for (int y = 0; y <= seq2Length; y++) posterior[y] = 0;
+      for (int x = 1; x <= seq1Length; x++){
+       SafeVector<PIF>::iterator XYptr = matXY->GetRowPtr(x);
+       SafeVector<PIF>::iterator XYend = XYptr + matXY->GetRowSize(x);
+       VF::iterator base = posterior.begin() + x * (seq2Length + 1);
+       int curr = 0;
+       while (XYptr != XYend){
+
+         // zero out all cells until the first filled column
+         while (curr < XYptr->first){
+           base[curr] = 0;
+           curr++;
+         }
+
+         // now, skip over this column
+         curr++;
+         ++XYptr;
+       }
+       
+       // zero out cells after last column
+       while (curr <= seq2Length){
+         base[curr] = 0;
+         curr++;
+       }
+      }
+
+      // save the new posterior matrix
+      newSparseMatrices[i][j] = new SparseMatrix (seq1->GetLength(), seq2->GetLength(), posterior);
+      newSparseMatrices[j][i] = NULL;
+
+      if (enableVerbose)
+        cerr << newSparseMatrices[i][j]->GetNumCells() << " -- ";
+
+      delete posteriorPtr;
+
+      if (enableVerbose)
+        cerr << "done." << endl;
+    }
+  }
+  
+  return newSparseMatrices;
+}
+
+/////////////////////////////////////////////////////////////////
+// Relax()
+//
+// Computes the consistency transformation for a single sequence
+// z, and adds the transformed matrix to "posterior".
+/////////////////////////////////////////////////////////////////
+
+void Relax (SparseMatrix *matXZ, SparseMatrix *matZY, VF &posterior){
+
+  assert (matXZ);
+  assert (matZY);
+
+  int lengthX = matXZ->GetSeq1Length();
+  int lengthY = matZY->GetSeq2Length();
+  assert (matXZ->GetSeq2Length() == matZY->GetSeq1Length());
+
+  // for every x[i]
+  for (int i = 1; i <= lengthX; i++){
+    SafeVector<PIF>::iterator XZptr = matXZ->GetRowPtr(i);
+    SafeVector<PIF>::iterator XZend = XZptr + matXZ->GetRowSize(i);
+
+    VF::iterator base = posterior.begin() + i * (lengthY + 1);
+
+    // iterate through all x[i]-z[k]
+    while (XZptr != XZend){
+      SafeVector<PIF>::iterator ZYptr = matZY->GetRowPtr(XZptr->first);
+      SafeVector<PIF>::iterator ZYend = ZYptr + matZY->GetRowSize(XZptr->first);
+      const float XZval = XZptr->second;
+
+      // iterate through all z[k]-y[j]
+      while (ZYptr != ZYend){
+        base[ZYptr->first] += XZval * ZYptr->second;
+       ZYptr++;
+      }
+      XZptr++;
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// Relax1()
+//
+// Computes the consistency transformation for a single sequence
+// z, and adds the transformed matrix to "posterior".
+/////////////////////////////////////////////////////////////////
+
+void Relax1 (SparseMatrix *matZX, SparseMatrix *matZY, VF &posterior){
+
+  assert (matZX);
+  assert (matZY);
+
+  int lengthZ = matZX->GetSeq1Length();
+  int lengthY = matZY->GetSeq2Length();
+
+  // for every z[k]
+  for (int k = 1; k <= lengthZ; k++){
+    SafeVector<PIF>::iterator ZXptr = matZX->GetRowPtr(k);
+    SafeVector<PIF>::iterator ZXend = ZXptr + matZX->GetRowSize(k);
+
+    // iterate through all z[k]-x[i]
+    while (ZXptr != ZXend){
+      SafeVector<PIF>::iterator ZYptr = matZY->GetRowPtr(k);
+      SafeVector<PIF>::iterator ZYend = ZYptr + matZY->GetRowSize(k);
+      const float ZXval = ZXptr->second;
+      VF::iterator base = posterior.begin() + ZXptr->first * (lengthY + 1);
+
+      // iterate through all z[k]-y[j]
+      while (ZYptr != ZYend){
+        base[ZYptr->first] += ZXval * ZYptr->second;
+        ZYptr++;
+      }
+      ZXptr++;
+    }
+  }
+}
+
+void DoBasePairProbabilityRelaxation (MultiSequence *sequences, 
+                                     SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                                     SafeVector<BPPMatrix*> &BPPMatrices) {
+    const int numSeqs = sequences->GetNumSequences();
+
+    for (int i = 0; i < numSeqs; i++) {
+       Sequence *seq1 = sequences->GetSequence (i);
+       BPPMatrix *seq1BppMatrix = BPPMatrices[seq1->GetLabel()];
+       Trimat<float> consBppMat(seq1->GetLength() + 1);
+       int seq1Length = seq1->GetLength();
+
+       for (int k = 1; k <= seq1Length; k++) {
+           for (int l = k; l <= seq1Length; l++) {
+               consBppMat.ref(k, l) = seq1BppMatrix->GetProb(k, l);
+           }
+       }
+
+       for (int j = i + 1; j < numSeqs; j++) {
+
+   //          VF *posteriorPtr = sparseMatrices[i][j]->GetPosterior()
+         Sequence *seq2 = sequences->GetSequence (j);
+         BPPMatrix *seq2BppMatrix = BPPMatrices[seq2->GetLabel()];
+//       int seq2Length = seq2->GetLength();
+         SparseMatrix *matchProb = sparseMatrices[i][j];
+
+//       vector<PIF2> &probs1 = seq1BppMatrix->bppMat.data2;
+         for(int k = 1; k <= seq1Length; k++) {
+             for(int m = k, n = k; n <= k + 200 && m >= 1 && n <= seq1Length; m--, n++) {
+                 
+//       for (int k = 0; k < (int)probs1.size(); k++) {
+//           float tmpProb1 = probs1[k].prob;
+//           int   tmp1I    = probs1[k].i;
+//           int   tmp1J    = probs1[k].j;
+
+                 float sumProb = 0;
+                 vector<PIF2> &probs2 = seq2BppMatrix->bppMat.data2;
+                 for(int l = 0; l < (int)probs2.size(); l++) {
+                     float tmpProb2 = probs2[l].prob;
+                     int   tmp2I    = probs2[l].i;
+                     int   tmp2J    = probs2[l].j;
+                     sumProb += matchProb->GetValue(m, tmp2I)*matchProb->GetValue(n, tmp2J)*tmpProb2;
+                 }
+
+                 consBppMat.ref(m, n) += sumProb;
+             }
+
+             for(int m = k, n = k + 1; n <= k + 200 && m >= 1 && n <= seq1Length; m--, n++) {
+                 
+//       for (int k = 0; k < (int)probs1.size(); k++) {
+//           float tmpProb1 = probs1[k].prob;
+//           int   tmp1I    = probs1[k].i;
+//           int   tmp1J    = probs1[k].j;
+
+                 float sumProb = 0;
+                 vector<PIF2> &probs2 = seq2BppMatrix->bppMat.data2;
+                 for(int l = 0; l < (int)probs2.size(); l++) {
+                     float tmpProb2 = probs2[l].prob;
+                     int   tmp2I    = probs2[l].i;
+                     int   tmp2J    = probs2[l].j;
+                     sumProb += matchProb->GetValue(m, tmp2I)*matchProb->GetValue(n, tmp2J)*tmpProb2;
+                 }
+
+                 consBppMat.ref(m, n) += sumProb;
+             }
+         }
+       }
+
+/*
+         for(int k = 1; k <= seq1Length; k++) {
+             for(int m = k, n = k; n <= k + 30 && m >= 1 && n <= seq1Length; m--, n++) {
+                 float tmpProb = seq1BppMatrix->GetProb(m, n);
+                 for(int l = 1; l <= seq2Length; l++) {
+                     for(int s = l, t = l; t <= l + 30 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                     for(int s = l, t = l + 1; t <= l + 31 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                 }
+                 consBppMat.ref(m, n) += tmpProb;
+             }
+    
+             for(int m = k, n = k + 1; n <= k + 31 && m >= 1 && n <= seq1Length; m--, n++) {
+                 float tmpProb = seq1BppMatrix->GetProb(m, n);
+                 for(int l = 1; l <= seq2Length; l++) {
+                     for(int s = l, t = l; t <= l + 30 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                     for(int s = l, t = l + 1; t <= l + 31 && s >= 1 && t <= seq2Length; s--, t++) {
+                         tmpProb += matchProb->GetValue(m,s)*matchProb->GetValue(n,t)*seq2BppMatrix->GetProb(s,t);
+                     }
+                 }
+                 consBppMat.ref(m,n) += tmpProb;
+             }
+         }
+       }
+*/
+       for (int m = 1; m <= seq1Length; m++) {
+           for (int n = m + 4; n <= seq1Length; n++) {
+               consBppMat.ref(m,n) = consBppMat.ref(m,n)/(float)numSeqs;
+           }
+       }
+       seq1BppMatrix->updateBPPMatrix(consBppMat);
+    }
+}
+
+/////////////////////////////////////////////////////////////////
+// GetSubtree
+//
+// Returns set containing all leaf labels of the current subtree.
+/////////////////////////////////////////////////////////////////
+
+set<int> GetSubtree (const TreeNode *tree){
+  set<int> s;
+
+  if (tree->GetSequenceLabel() == -1){
+    s = GetSubtree (tree->GetLeftChild());
+    set<int> t = GetSubtree (tree->GetRightChild());
+
+    for (set<int>::iterator iter = t.begin(); iter != t.end(); ++iter)
+      s.insert (*iter);
+  }
+  else {
+    s.insert (tree->GetSequenceLabel());
+  }
+
+  return s;
+}
+
+/////////////////////////////////////////////////////////////////
+// TreeBasedBiPartitioning
+//
+// Uses the iterative refinement scheme from MUSCLE.
+/////////////////////////////////////////////////////////////////
+
+void TreeBasedBiPartitioning (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                              const ProbabilisticModel &model, MultiSequence* &alignment,
+                              const TreeNode *tree, SafeVector<BPPMatrix*> &BPPMatrices){
+  // check if this is a node of the alignment tree
+  if (tree->GetSequenceLabel() == -1){
+    TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree->GetLeftChild(), BPPMatrices);
+    TreeBasedBiPartitioning (sparseMatrices, model, alignment, tree->GetRightChild(), BPPMatrices);
+
+    set<int> leftSubtree = GetSubtree (tree->GetLeftChild());
+    set<int> rightSubtree = GetSubtree (tree->GetRightChild());
+    set<int> leftSubtreeComplement, rightSubtreeComplement;
+
+    // calculate complement of each subtree
+    for (int i = 0; i < alignment->GetNumSequences(); i++){
+      if (leftSubtree.find(i) == leftSubtree.end()) leftSubtreeComplement.insert (i);
+      if (rightSubtree.find(i) == rightSubtree.end()) rightSubtreeComplement.insert (i);
+    }
+
+    // perform realignments for edge to left child
+    if (!leftSubtree.empty() && !leftSubtreeComplement.empty()){
+      MultiSequence *groupOneSeqs = alignment->Project (leftSubtree); assert (groupOneSeqs);
+      MultiSequence *groupTwoSeqs = alignment->Project (leftSubtreeComplement); assert (groupTwoSeqs);
+      delete alignment;
+      alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model, BPPMatrices, tree->GetLeftChild()->GetIdentity());
+    }
+
+    // perform realignments for edge to right child
+    if (!rightSubtree.empty() && !rightSubtreeComplement.empty()){
+      MultiSequence *groupOneSeqs = alignment->Project (rightSubtree); assert (groupOneSeqs);
+      MultiSequence *groupTwoSeqs = alignment->Project (rightSubtreeComplement); assert (groupTwoSeqs);
+      delete alignment;
+      alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model, BPPMatrices, tree->GetRightChild()->GetIdentity());
+    }
+  }
+}
+
+/////////////////////////////////////////////////////////////////
+// DoterativeRefinement()
+//
+// Performs a single round of randomized partionining iterative
+// refinement.
+/////////////////////////////////////////////////////////////////
+/*
+void DoIterativeRefinement (const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                            const ProbabilisticModel &model, MultiSequence* &alignment){
+  set<int> groupOne, groupTwo;
+
+  // create two separate groups
+  for (int i = 0; i < alignment->GetNumSequences(); i++){
+    if (rand() % 2)
+      groupOne.insert (i);
+    else
+      groupTwo.insert (i);
+  }
+
+  if (groupOne.empty() || groupTwo.empty()) return;
+
+  // project into the two groups
+  MultiSequence *groupOneSeqs = alignment->Project (groupOne); assert (groupOneSeqs);
+  MultiSequence *groupTwoSeqs = alignment->Project (groupTwo); assert (groupTwoSeqs);
+  delete alignment;
+
+  // realign
+  alignment = AlignAlignments (groupOneSeqs, groupTwoSeqs, sparseMatrices, model);
+
+  delete groupOneSeqs;
+  delete groupTwoSeqs;
+}
+*/
+
+/////////////////////////////////////////////////////////////////
+// WriteAnnotation()
+//
+// Computes annotation for multiple alignment and write values
+// to a file.
+/////////////////////////////////////////////////////////////////
+
+void WriteAnnotation (MultiSequence *alignment, 
+                     const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+  ofstream outfile (annotationFilename.c_str());
+  
+  if (outfile.fail()){
+    cerr << "ERROR: Unable to write annotation file." << endl;
+    exit (1);
+  }
+
+  const int alignLength = alignment->GetSequence(0)->GetLength();
+  const int numSeqs = alignment->GetNumSequences();
+  
+  SafeVector<int> position (numSeqs, 0);
+  SafeVector<SafeVector<char>::iterator> seqs (numSeqs);
+  for (int i = 0; i < numSeqs; i++) seqs[i] = alignment->GetSequence(i)->GetDataPtr();
+  SafeVector<pair<int,int> > active;
+  active.reserve (numSeqs);
+  
+  // for every column
+  for (int i = 1; i <= alignLength; i++){
+    
+    // find all aligned residues in this particular column
+    active.clear();
+    for (int j = 0; j < numSeqs; j++){
+      if (seqs[j][i] != '-'){
+       active.push_back (make_pair(j, ++position[j]));
+      }
+    }
+    
+    outfile << setw(4) << ComputeScore (active, sparseMatrices) << endl;
+  }
+  
+  outfile.close();
+}
+
+/////////////////////////////////////////////////////////////////
+// ComputeScore()
+//
+// Computes the annotation score for a particular column.
+/////////////////////////////////////////////////////////////////
+
+int ComputeScore (const SafeVector<pair<int, int> > &active, 
+                 const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices){
+
+  if (active.size() <= 1) return 0;
+  
+  // ALTERNATIVE #1: Compute the average alignment score.
+
+  float val = 0;
+  for (int i = 0; i < (int) active.size(); i++){
+    for (int j = i+1; j < (int) active.size(); j++){
+      val += sparseMatrices[active[i].first][active[j].first]->GetValue(active[i].second, active[j].second);
+    }
+  }
+
+  return (int) (200 * val / ((int) active.size() * ((int) active.size() - 1)));
+  
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MakeGnuPlot.cc b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MakeGnuPlot.cc
new file mode 100644 (file)
index 0000000..fe6641a
--- /dev/null
@@ -0,0 +1,58 @@
+/////////////////////////////////////////////////////////////////
+// MakeGnuPlot.cc
+/////////////////////////////////////////////////////////////////
+
+#include <iostream>
+#include <fstream>
+
+using namespace std;
+
+int main (int argc, char **argv){
+  
+  if (argc == 1 || argc > 3){
+    cerr << "Usage: makegnuplot annotscores [refscores]" << endl;
+    exit (1);
+  }
+
+  ifstream data (argv[1]);
+
+  if (data.fail()){
+    cerr << "ERROR: Could not open file " << argv[1] << endl;
+    exit (1);
+  }
+  
+  int x, ct = 0;
+  while (data >> x) ct++;
+  data.close();
+  
+  ofstream out ("temporary_gnuplot_script");
+  
+  if (out.fail()){
+    cerr << "ERROR: Could not create temporary file." << endl;
+    exit (1);
+  }
+
+  out << "set title \"Column Reliability Scores\"" << endl
+      << "set xlabel \"Alignment Position\"" << endl
+      << "set ylabel \"Column Reliability\"" << endl
+      << "set xr [1:" << ct << "]" << endl
+      << "set term postscript enhanced color" << endl
+      << "set output \"reliability.ps\"" << endl;
+  
+  if (argc == 3){
+    out << "set style fill solid 0.5 noborder" << endl
+       << "plot \"" << argv[2] << "\" title \"actual\" with boxes lt 2, \\" << endl
+       << "     \"" << argv[1] << "\" title \"predicted\" with histeps lt 1 lw 3" << endl;
+  }
+  else 
+    out << "plot \"" << argv[1] << "\" title \"predicted\" with histeps lt 1 lw 3" << endl;
+
+  out.close();
+
+  if (system ("gnuplot temporary_gnuplot_script") == -1){
+    cerr << "ERROR: Could not run Gnuplot correctly." << endl;
+    exit (1);
+  }
+  
+  //system ("rm temporary_gnuplot_script");
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Makefile b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Makefile
new file mode 100644 (file)
index 0000000..d7581ec
--- /dev/null
@@ -0,0 +1,58 @@
+################################################################################
+# Makefile for probcons
+################################################################################
+
+################################################################################
+# 1) Choose C++ compiler.
+################################################################################
+
+CXX = g++
+
+################################################################################
+# 2) Set C++ flags.
+#    a) DEBUG mode -- no optimizations, enable SafeVector checking, no inlining
+#    b) PROFILE mode -- for gprof
+#    c) RELEASE mode
+################################################################################
+
+OTHERFLAGS = -DNumInsertStates=1 -DVERSION="1.10"
+
+# debug mode    
+#CXXFLAGS = -g -W -Wall -pedantic -DENABLE_CHECKS -fno-inline $(OTHERFLAGS)
+
+# profile mode
+#CXXFLAGS = -pg -W -Wall -pedantic $(OTHERFLAGS)
+
+# release mode
+#CXXFLAGS = -O3 -W -Wall -pedantic -DNDEBUG $(OTHERFLAGS) -mmmx -msse -msse2 -mfpmath=sse -march=pentium4 -mcpu=pentium4 -funroll-loops -fomit-frame-pointer 
+CXXFLAGS = -O3 -W -Wall -pedantic -DNDEBUG $(OTHERFLAGS) -funroll-loops
+
+################################################################################
+# 3) Dependencies
+################################################################################
+
+TARGETS = probcons 
+#compare project makegnuplot
+
+.PHONY : all
+all : $(TARGETS)
+
+#probcons : MultiSequence.h ProbabilisticModel.h ScoreType.h Sequence.h FileBuffer.h SparseMatrix.h EvolutionaryTree.h Defaults.h SafeVector.h Main.cc
+probcons : MultiSequence.h ProbabilisticModel.h ScoreType.h Sequence.h FileBuffer.h SparseMatrix.h EvolutionaryTree.h Defaults.h SafeVector.h
+       $(CXX) $(CXXFLAGS) -lm -o probcons Main.cc 
+
+compare : MultiSequence.h Sequence.h FileBuffer.h SafeVector.h CompareToRef.cc
+       $(CXX) $(CXXFLAGS) -o compare CompareToRef.cc
+
+fixref : MultiSequence.h ProbabilisticModel.h ScoreType.h Sequence.h FileBuffer.h SparseMatrix.h EvolutionaryTree.h Defaults.h SafeVector.h FixRef.cc
+       $(CXX) $(CXXFLAGS) -o fixref FixRef.cc
+
+project : MultiSequence.h Sequence.h SafeVector.h ProjectPairwise.cc
+       $(CXX) $(CXXFLAGS) -o project ProjectPairwise.cc
+
+makegnuplot : MakeGnuPlot.cc
+       $(CXX) $(CXXFLAGS) -o makegnuplot MakeGnuPlot.cc
+
+.PHONY : clean
+clean:
+       rm -f $(TARGETS)
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MultiSequence.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/MultiSequence.h
new file mode 100644 (file)
index 0000000..b28c186
--- /dev/null
@@ -0,0 +1,1120 @@
+////////////////////////////////////////////////////////////////
+// MultiSequence.h
+//
+// Utilities for reading/writing multiple sequence data.
+/////////////////////////////////////////////////////////////////
+
+#ifndef MULTISEQUENCE_H
+#define MULTISEQUENCE_H
+
+#include <cctype>
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <sstream>
+#include <algorithm>
+#include <set>
+#include "SafeVector.h"
+#include "Sequence.h"
+#include "FileBuffer.h"
+
+/////////////////////////////////////////////////////////////////
+// MultiSequence
+//
+// Class for multiple sequence alignment input/output.
+/////////////////////////////////////////////////////////////////
+
+namespace MXSCARNA {
+class MultiSequence {
+
+  SafeVector<Sequence *> *sequences;
+
+ public:
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::MultiSequence()
+  //
+  // Default constructor.
+  /////////////////////////////////////////////////////////////////
+
+  MultiSequence () : sequences (NULL) {}
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::MultiSequence()
+  //
+  // Constructor.  Load MFA from a FileBuffer object.
+  /////////////////////////////////////////////////////////////////
+
+  MultiSequence (FileBuffer &infile) : sequences (NULL) {
+    LoadMFA (infile);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::MultiSequence()
+  //
+  // Constructor.  Load MFA from a filename.
+  /////////////////////////////////////////////////////////////////
+
+  MultiSequence (const string &filename) : sequences (NULL){
+    LoadMFA (filename);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::~MultiSequence()
+  //
+  // Destructor.  Gets rid of sequence objects contained in the
+  // multiple alignment.
+  /////////////////////////////////////////////////////////////////
+
+  ~MultiSequence(){
+
+    // if sequences allocated
+    if (sequences){
+
+      // free all sequences
+      for (SafeVector<Sequence *>::iterator iter = sequences->begin(); iter != sequences->end(); ++iter){
+        assert (*iter);
+        delete *iter;
+        *iter = NULL;
+      }
+
+      // free sequence vector
+      delete sequences;
+      sequences = NULL;
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::LoadMFA()
+  //
+  // Load MFA from a filename.
+  /////////////////////////////////////////////////////////////////
+
+  void LoadMFA (const string &filename, bool stripGaps = false){
+
+    // try opening file
+    FileBuffer infile (filename.c_str());
+
+    if (infile.fail()){
+      cerr << "ERROR: Could not open file '" << filename << "' for reading." << endl;
+      exit (1);
+    }
+
+    // if successful, then load using other LoadMFA() routine
+    LoadMFA (infile, stripGaps);
+
+    infile.close();
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::LoadMFA()
+  //
+  // Load MSF from a FileBuffer object.
+  /////////////////////////////////////////////////////////////////
+
+  void ParseMSF (FileBuffer &infile, string header, bool stripGaps = false){
+
+    SafeVector<SafeVector<char> *> seqData;
+    SafeVector<string> seqNames;
+    SafeVector<int> seqLengths;
+
+    istringstream in;
+    bool valid = true;
+    bool missingHeader = false;
+    bool clustalW = false;
+
+    // read until data starts
+    while (!infile.eof() && header.find ("..", 0) == string::npos){
+      if (header.find ("CLUSTAL", 0) == 0 || header.find ("PROBCONS", 0) == 0){
+       clustalW = true;
+       break;
+      }
+      infile.GetLine (header);
+      if (header.find ("//", 0) != string::npos){
+        missingHeader = true;
+        break;
+      }
+    }
+
+    // read until end-of-file
+    while (valid){
+      infile.GetLine (header);
+      if (infile.eof()) break;
+
+      string word;
+      in.clear();
+      in.str(header);
+
+      // check if there's anything on this line
+      if (in >> word){
+
+       // clustalw name parsing
+       if (clustalW){
+         if (!isspace(header[0]) && find (seqNames.begin(), seqNames.end(), word) == seqNames.end()){
+           seqNames.push_back (word);
+           seqData.push_back (new SafeVector<char>());
+           seqLengths.push_back (0);
+           seqData[(int) seqData.size() - 1]->push_back ('@');
+         }       
+       }
+
+        // look for new sequence label
+        if (word == string ("Name:")){
+          if (in >> word){
+            seqNames.push_back (word);
+            seqData.push_back (new SafeVector<char>());
+            seqLengths.push_back (0);
+            seqData[(int) seqData.size() - 1]->push_back ('@');
+          }
+          else
+            valid = false;
+        }
+
+        // check if this is sequence data
+        else if (find (seqNames.begin(), seqNames.end(), word) != seqNames.end()){
+          int index = find (seqNames.begin(), seqNames.end(), word) - seqNames.begin();
+
+          // read all remaining characters on the line
+          char ch;
+          while (in >> ch){
+            if (isspace (ch)) continue;
+//            if (ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
+            if (ch == '.') ch = '-';
+           if (stripGaps && ch == '-') continue;
+/*
+            if (!((ch >= 'A' && ch <= 'Z') || ch == '*' || ch == '-')){
+              cerr << "ERROR: Unknown character encountered: " << ch << endl;
+              exit (1);
+           }
+*/
+           if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '*' || ch == '-')){
+              cerr << "ERROR: Unknown character encountered: " << ch << endl;
+              exit (1);
+            }
+
+            // everything's ok so far, so just store this character.
+            seqData[index]->push_back (ch);
+            seqLengths[index]++;
+          }
+        }
+        else if (missingHeader){
+          seqNames.push_back (word);
+          seqData.push_back (new SafeVector<char>());
+          seqLengths.push_back (0);
+          seqData[(int) seqData.size() - 1]->push_back ('@');
+
+          int index = (int) seqNames.size() - 1;
+
+          // read all remaining characters on the line
+          char ch;
+          while (in >> ch){
+            if (isspace (ch)) continue;
+//            if (ch >= 'a' && ch <= 'z') ch = ch - 'a' + 'A';
+            if (ch == '.') ch = '-';
+           if (stripGaps && ch == '-') continue;
+
+            if (!((ch >= 'A' && ch <= 'Z') || ch == '*' || ch == '-')){
+              cerr << "ERROR: Unknown character encountered: " << ch << endl;
+              exit (1);
+            }
+/*
+           if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '*' || ch == '-')){
+              cerr << "ERROR: Unknown character encountered: " << ch << endl;
+              exit (1);
+            }
+*/
+            // everything's ok so far, so just store this character.
+            seqData[index]->push_back (ch);
+            seqLengths[index]++;
+          }
+        }
+      }
+    }
+
+    // check for errorsq
+    if (seqNames.size() == 0){
+      cerr << "ERROR: No sequences read!" << endl;
+      exit (1);
+    }
+
+    assert (!sequences);
+    sequences = new SafeVector<Sequence *>;
+    for (int i = 0; i < (int) seqNames.size(); i++){
+      if (seqLengths[i] == 0){
+        cerr << "ERROR: Sequence of zero length!" << endl;
+        exit (1);
+      }
+      Sequence *seq = new Sequence (seqData[i], seqNames[i], seqLengths[i], i, i);
+      sequences->push_back (seq);
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::LoadMFA()
+  //
+  // Load MFA from a FileBuffer object.
+  /////////////////////////////////////////////////////////////////
+
+  void LoadMFA (FileBuffer &infile, bool stripGaps = false){
+
+    // check to make sure that file reading is ok
+    if (infile.fail()){
+      cerr << "ERROR: Error reading file." << endl;
+      exit (1);
+    }
+
+    // read all sequences
+    while (true){
+
+      // get the sequence label as being the current # of sequences
+      // NOTE: sequence labels here are zero-based
+      int index = (!sequences) ? 0 : sequences->size();
+
+      // read the sequence
+      Sequence *seq = new Sequence (infile, stripGaps);
+      if (seq->Fail()){
+
+        // check if alternative file format (i.e. not MFA)
+        if (index == 0){
+          string header = seq->GetHeader();
+          if (header.length() > 0 && header[0] != '>'){
+            // try MSF format
+            ParseMSF (infile, header);
+            break;
+          }
+        }
+
+        delete seq;
+        break;
+      }
+      seq->SetLabel (index);
+
+      // add the sequence to the list of current sequences
+      if (!sequences) sequences = new SafeVector<Sequence *>;
+      sequences->push_back (seq);
+    }
+
+    // make sure at least one sequence was read
+    if (!sequences){
+      cerr << "ERROR: No sequences read." << endl;
+      exit (1);
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::AddSequence()
+  //
+  // Add another sequence to an existing sequence list
+  /////////////////////////////////////////////////////////////////
+
+  void AddSequence (Sequence *sequence){
+    assert (sequence);
+    assert (!sequence->Fail());
+
+    // add sequence
+    if (!sequences) sequences = new SafeVector<Sequence *>;
+    sequences->push_back (sequence);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::RemoveSequence()
+  //
+  // Remove a sequence from the MultiSequence
+  /////////////////////////////////////////////////////////////////
+
+  void RemoveSequence (int index){
+    assert (sequences);
+
+    assert (index >= 0 && index < (int) sequences->size());
+    delete (*sequences)[index];
+
+    sequences->erase (sequences->begin() + index);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteMFA()
+  //
+  // Write MFA to the outfile.  Allows the user to specify the
+  // number of columns for the output.  Also, useIndices determines
+  // whether or not the actual sequence comments will be printed
+  // out or whether the artificially assigned sequence labels will
+  // be used instead.
+  /////////////////////////////////////////////////////////////////
+
+  void WriteMFA (ostream &outfile, string *ssCons = NULL, int numColumns = 60, bool useIndices = false){
+    if (!sequences) return;
+
+    // loop through all sequences and write them out
+    for (SafeVector<Sequence *>::iterator iter = sequences->begin(); iter != sequences->end(); ++iter){
+      (*iter)->WriteMFA (outfile, numColumns, useIndices);
+    }
+
+    int count = 0;
+    if (ssCons != NULL) {
+      outfile << ">#=GC SS_cons" << endl;
+      int length = ssCons->length();
+      for (int i = 1; i < length; i++ ) {
+       outfile << ssCons->at(i);
+       ++count;
+       
+       if (numColumns <= count) {
+         outfile << endl;
+         count = 0;
+       }
+       
+      }
+    }
+    outfile << endl;
+  }
+
+  void WriteMFAseq (ostream &outfile, int numColumns = 60, bool useIndices = false){
+    if (!sequences) return;
+
+    // loop through all sequences and write them out
+    for (SafeVector<Sequence *>::iterator iter = sequences->begin(); iter != sequences->end(); ++iter){
+      (*iter)->WriteMFA (outfile, numColumns, useIndices);
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::GetAnnotationChar()
+  //
+  // Return CLUSTALW annotation for column.
+  /////////////////////////////////////////////////////////////////
+
+  char GetAnnotationChar (SafeVector<char> &column){
+    SafeVector<int> counts (256, 0);
+    int allChars = (int) column.size();
+    
+    for (int i = 0; i < allChars; i++){
+      counts[(unsigned char) toupper(column[i])]++;
+    }
+    
+    allChars -= counts[(unsigned char) '-'];
+    if (allChars == 1) return ' ';
+    
+    for (int i = 0; i < 256; i++) if ((char) i != '-' && counts[i] == allChars) return '*';
+    
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'T'] + 
+       counts[(unsigned char) 'A'] == allChars) 
+      return ':';
+    
+    if (counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'E'] + 
+       counts[(unsigned char) 'Q'] +
+       counts[(unsigned char) 'K'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'Q'] +
+       counts[(unsigned char) 'K'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'D'] + 
+       counts[(unsigned char) 'E'] +
+       counts[(unsigned char) 'Q'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'Q'] + 
+       counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'R'] +
+       counts[(unsigned char) 'K'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'M'] + 
+       counts[(unsigned char) 'I'] + 
+       counts[(unsigned char) 'L'] +
+       counts[(unsigned char) 'V'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'M'] + 
+       counts[(unsigned char) 'I'] + 
+       counts[(unsigned char) 'L'] +
+       counts[(unsigned char) 'F'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'Y'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'F'] + 
+       counts[(unsigned char) 'Y'] + 
+       counts[(unsigned char) 'W'] == allChars) 
+      return ':';
+
+    if (counts[(unsigned char) 'C'] + 
+       counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'A'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'A'] + 
+       counts[(unsigned char) 'T'] + 
+       counts[(unsigned char) 'V'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'A'] + 
+       counts[(unsigned char) 'G'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'T'] + 
+       counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'K'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'T'] + 
+       counts[(unsigned char) 'P'] + 
+       counts[(unsigned char) 'A'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'G'] + 
+       counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'D'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'S'] + 
+       counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'D'] + 
+       counts[(unsigned char) 'E'] + 
+       counts[(unsigned char) 'Q'] + 
+       counts[(unsigned char) 'K'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'D'] + 
+       counts[(unsigned char) 'E'] + 
+       counts[(unsigned char) 'Q'] + 
+       counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'K'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'N'] + 
+       counts[(unsigned char) 'E'] + 
+       counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'Q'] + 
+       counts[(unsigned char) 'R'] + 
+       counts[(unsigned char) 'K'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'F'] + 
+       counts[(unsigned char) 'V'] + 
+       counts[(unsigned char) 'L'] + 
+       counts[(unsigned char) 'I'] + 
+       counts[(unsigned char) 'M'] == allChars) 
+      return '.';
+
+    if (counts[(unsigned char) 'H'] + 
+       counts[(unsigned char) 'F'] + 
+       counts[(unsigned char) 'Y'] == allChars) 
+      return '.';
+
+    return ' ';
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteALN()
+  //
+  // Write ALN to the outfile.  Allows the user to specify the
+  // number of columns for the output.  
+  /////////////////////////////////////////////////////////////////
+
+  void WriteALN (ostream &outfile, int numColumns = 60){
+    if (!sequences) return;
+
+//   outfile << "Multplex SCARNA version " << VERSION << " multiple sequence alignment"  << endl;
+//   outfile << "PROBCONS version " << VERSION << " multiple sequence alignment" << endl;
+    outfile << "CLUSTAL W(1.83) multiple sequence alignment" << endl;
+//    outfile << "//" << endl;
+
+    int longestComment = 0;
+    SafeVector<SafeVector<char>::iterator> ptrs (GetNumSequences());
+    SafeVector<int> lengths (GetNumSequences());
+    for (int i = 0; i < GetNumSequences(); i++){
+      ptrs[i] = GetSequence (i)->GetDataPtr();
+      lengths[i] = GetSequence (i)->GetLength();
+      longestComment = max (longestComment, (int) GetSequence(i)->GetName().length());
+    }
+    longestComment += 4;
+
+    int writtenChars = 0;    
+    bool allDone = false;
+
+    while (!allDone){
+      outfile << endl;
+      allDone = true;
+
+      // loop through all sequences and write them out
+      for (int i = 0; i < GetNumSequences(); i++){
+
+       if (writtenChars < lengths[i]){
+         outfile << GetSequence(i)->GetName();
+         for (int j = 0; j < longestComment - (int) GetSequence(i)->GetName().length(); j++)
+           outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++){
+           if (writtenChars + j < lengths[i])
+             outfile << ptrs[i][writtenChars + j + 1];
+           else
+             break;
+         }
+         
+         outfile << endl;
+         
+         if (writtenChars + numColumns < lengths[i]) allDone = false;
+       }
+      }
+
+      // write annotation line
+      for (int j = 0; j < longestComment; j++)
+       outfile << ' ';
+
+      for (int j = 0; j < numColumns; j++){
+       SafeVector<char> column;
+
+       for (int i = 0; i < GetNumSequences(); i++)
+         if (writtenChars + j < lengths[i])
+           column.push_back (ptrs[i][writtenChars + j + 1]);
+       
+       if (column.size() > 0)
+         outfile << GetAnnotationChar (column);        
+      }
+
+      outfile << endl;
+      writtenChars += numColumns;
+    }
+    outfile << endl;
+  }
+
+  ////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteWEB();
+  //
+  // Write ALN to the outfile.  Allows the user to specify the
+  // number of columns for the output.  
+  ///////////////////////////////////////////////////////////////
+   void WriteWEB (ostream &outfile, string *ssCons = NULL, int numColumns = 60, bool useIndices = false){
+    if (!sequences) return;
+
+    // loop through all sequences and write them out
+    for (SafeVector<Sequence *>::iterator iter = sequences->begin(); iter != sequences->end(); ++iter){
+      (*iter)->WriteWEB (outfile, numColumns, useIndices);
+    }
+    
+    // write conservation 
+    outfile << "<conservation>" << endl;
+        int longestComment = 0;
+    SafeVector<SafeVector<char>::iterator> ptrs (GetNumSequences());
+    SafeVector<int> lengths (GetNumSequences());
+    for (int i = 0; i < GetNumSequences(); i++){
+      ptrs[i] = GetSequence (i)->GetDataPtr();
+      lengths[i] = GetSequence (i)->GetLength();
+      longestComment = max (longestComment, (int) GetSequence(i)->GetName().length());
+    }
+    longestComment += 4;
+
+    int writtenChars = 0;    
+    bool allDone = false;
+
+    while (!allDone){
+//      outfile << endl;
+      allDone = true;
+
+      // loop through all sequences and write them out
+      for (int i = 0; i < GetNumSequences(); i++){
+
+       if (writtenChars < lengths[i]){
+//       outfile << GetSequence(i)->GetName();
+         for (int j = 0; j < longestComment - (int) GetSequence(i)->GetName().length(); j++)
+//         outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++){
+             if (writtenChars + j < lengths[i]);
+//           outfile << ptrs[i][writtenChars + j + 1];
+           else
+             break;
+         }
+         
+//       outfile << endl;
+         
+         if (writtenChars + numColumns < lengths[i]) allDone = false;
+       }
+      }
+
+      // write annotation line
+//      for (int j = 0; j < longestComment; j++)
+//     outfile << ' ';
+
+      for (int j = 0; j < numColumns; j++){
+       SafeVector<char> column;
+
+       for (int i = 0; i < GetNumSequences(); i++)
+         if (writtenChars + j < lengths[i])
+           column.push_back (ptrs[i][writtenChars + j + 1]);
+       
+       if (column.size() > 0)
+         outfile << GetAnnotationChar (column);        
+      }
+
+//      outfile << endl;
+      writtenChars += numColumns;
+    }
+    outfile << endl;
+    outfile << "</conservation>" << endl;
+
+    // write structure information
+    if (ssCons != NULL) {
+      outfile << "<structure>" << endl;
+      int length = ssCons->length();
+      for (int i = 1; i < length; i++ ) {
+       outfile << ssCons->at(i);
+      }
+      outfile << endl;
+      outfile << "</structure>" << endl;
+
+      // add coordinate information 06/09/14
+      outfile << "<coordinate>" << endl;
+    
+      int segmentPos = 1;
+      for (int i = 1; i < length; i++) {
+       int count = 0;
+       
+       if ( ssCons->at(i) == '(' ) {
+         ++count;
+         
+         int j = i;
+         while (count != 0) {
+           char ch = ssCons->at(++j);
+           if      (ch == '(')
+             ++count;
+           else if (ch == ')')
+             --count;
+         }
+           
+         outfile << "<segment position=\"" << segmentPos++ << "\" starts=\"" 
+                 << i << "\"" << " ends=\"" << j << "\"/>" << endl;
+           
+       }
+      }
+    }
+    outfile << "</coordinate>" << endl;
+
+    outfile << "<mxscarna>" << endl;
+    WriteMXSCARNA (outfile, ssCons);
+    outfile << "</mxscarna>" << endl;
+    
+    outfile << "<aln>" << endl;
+    WriteALN (outfile);
+    outfile << "</aln>" << endl;
+
+    outfile << "<mfa>" << endl;
+    WriteMFA (outfile, ssCons);
+    outfile << "</mfa>" << endl;
+
+    outfile << "<stockholm>" << endl;
+    WriteWebSTOCKHOLM (outfile, ssCons);
+    outfile << "</stockholm>" << endl;
+  }
+  
+  ////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteSTOCKHOLM();
+  //
+  // Write STOCKHOLM to the outfile.  Allows the user to specify the
+  // number of columns for the output.  
+  ///////////////////////////////////////////////////////////////
+  void WriteSTOCKHOLM (ostream &outfile, string *ssCons = NULL, int numColumns = 60) {
+    if (!sequences) return;
+    
+        outfile << "# STOCKHOLM 1.0" << endl;
+
+    int longestComment = 0;
+    SafeVector<SafeVector<char>::iterator> ptrs (GetNumSequences());
+    SafeVector<int> lengths (GetNumSequences());
+    for (int i = 0; i < GetNumSequences(); i++){
+      ptrs[i] = GetSequence (i)->GetDataPtr();
+      lengths[i] = GetSequence (i)->GetLength();
+      longestComment = max (longestComment, (int) GetSequence(i)->GetName().length());
+    }
+    longestComment += 4;
+
+    int writtenChars = 0;    
+    bool allDone = false;
+
+    while (!allDone){
+      outfile << endl;
+      allDone = true;
+
+      // loop through all sequences and write them out
+      for (int i = 0; i < GetNumSequences(); i++){
+
+       if (writtenChars < lengths[i]){
+         outfile << GetSequence(i)->GetName();
+         for (int j = 0; j < longestComment - (int) GetSequence(i)->GetName().length(); j++)
+           outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++){
+           if (writtenChars + j < lengths[i])
+               if (ptrs[i][writtenChars + j + 1] != '-')
+                 outfile << ptrs[i][writtenChars + j + 1];
+               else 
+                 outfile << ".";
+           else
+             break;
+         }
+         
+         outfile << endl;
+         
+         if (writtenChars + numColumns < lengths[i]) allDone = false;
+       }
+      }
+
+      // write ssCons
+
+      if (ssCons != NULL) {
+         outfile << "#=GC SS_cons";
+         int lengthSScons = 12;
+         for (int j = 0; j < longestComment - lengthSScons; j++)
+             outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++) {
+             if (ssCons->at(writtenChars + j + 1) == '(')
+               outfile << "<";
+             else if (ssCons->at(writtenChars + j + 1) == ')')
+               outfile << ">";
+             else 
+               outfile << ".";
+             if ((unsigned int)writtenChars + j + 1 >= ssCons->length() - 1) 
+                 break;
+         }
+         outfile << endl;
+      }
+
+      writtenChars += numColumns;
+    }
+    outfile << "//";
+    outfile << endl;
+  }
+  
+    ////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteSTOCKHOLM();
+  //
+  // Write STOCKHOLM to the outfile.  Allows the user to specify the
+  // number of columns for the output.  
+  ///////////////////////////////////////////////////////////////
+  void WriteWebSTOCKHOLM (ostream &outfile, string *ssCons = NULL, int numColumns = 60) {
+    if (!sequences) return;
+    
+        outfile << "# STOCKHOLM 1.0" << endl;
+
+    int longestComment = 0;
+    SafeVector<SafeVector<char>::iterator> ptrs (GetNumSequences());
+    SafeVector<int> lengths (GetNumSequences());
+    for (int i = 0; i < GetNumSequences(); i++){
+      ptrs[i] = GetSequence (i)->GetDataPtr();
+      lengths[i] = GetSequence (i)->GetLength();
+      longestComment = max (longestComment, (int) GetSequence(i)->GetName().length());
+    }
+    longestComment += 4;
+
+    int writtenChars = 0;    
+    bool allDone = false;
+
+    while (!allDone){
+      outfile << endl;
+      allDone = true;
+
+      // loop through all sequences and write them out
+      for (int i = 0; i < GetNumSequences(); i++){
+
+       if (writtenChars < lengths[i]){
+         outfile << GetSequence(i)->GetName();
+         for (int j = 0; j < longestComment - (int) GetSequence(i)->GetName().length(); j++)
+           outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++){
+           if (writtenChars + j < lengths[i])
+               if (ptrs[i][writtenChars + j + 1] != '-')
+                 outfile << ptrs[i][writtenChars + j + 1];
+               else 
+                 outfile << ".";
+           else
+             break;
+         }
+         
+         outfile << endl;
+         
+         if (writtenChars + numColumns < lengths[i]) allDone = false;
+       }
+      }
+
+      // write ssCons
+
+      if (ssCons != NULL) {
+         outfile << "#=GC SS_cons";
+         int lengthSScons = 12;
+         for (int j = 0; j < longestComment - lengthSScons; j++)
+             outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++) {
+             outfile << ssCons->at(writtenChars + j + 1);
+
+             if ((unsigned int)writtenChars + j + 1 >= ssCons->length() - 1) 
+                 break;
+         }
+         outfile << endl;
+      }
+
+      writtenChars += numColumns;
+    }
+    outfile << "//";
+    outfile << endl;
+  }
+
+  ////////////////////////////////////////////////////////////////
+  // MultiSequence::WriteMXSCARNA();
+  //
+  // Write MXSCARNA to the outfile.  Allows the user to specify the
+  // number of columns for the output.  
+  ///////////////////////////////////////////////////////////////
+  void WriteMXSCARNA (ostream &outfile, string *ssCons = NULL, int numColumns = 60){
+    if (!sequences) return;
+
+   outfile << "Multplex SCARNA version " << VERSION << " multiple sequence alignment"  << endl;
+
+    int longestComment = 0;
+    SafeVector<SafeVector<char>::iterator> ptrs (GetNumSequences());
+    SafeVector<int> lengths (GetNumSequences());
+    for (int i = 0; i < GetNumSequences(); i++){
+      ptrs[i] = GetSequence (i)->GetDataPtr();
+      lengths[i] = GetSequence (i)->GetLength();
+      longestComment = max (longestComment, (int) GetSequence(i)->GetName().length());
+    }
+    longestComment += 4;
+
+    int writtenChars = 0;    
+    bool allDone = false;
+
+    while (!allDone){
+      outfile << endl;
+      allDone = true;
+
+      // loop through all sequences and write them out
+      for (int i = 0; i < GetNumSequences(); i++){
+
+       if (writtenChars < lengths[i]){
+         outfile << GetSequence(i)->GetName();
+         for (int j = 0; j < longestComment - (int) GetSequence(i)->GetName().length(); j++)
+           outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++){
+           if (writtenChars + j < lengths[i])
+             outfile << ptrs[i][writtenChars + j + 1];
+           else
+             break;
+         }
+         
+         outfile << endl;
+         
+         if (writtenChars + numColumns < lengths[i]) allDone = false;
+       }
+      }
+
+      // write ssCons
+      if (ssCons != NULL) {
+         outfile << "ss_cons";
+         int lengthSScons = 7;
+         for (int j = 0; j < longestComment - lengthSScons; j++)
+             outfile << ' ';
+
+         for (int j = 0; j < numColumns; j++) {
+             outfile << ssCons->at(writtenChars + j + 1);
+             if ((unsigned int)writtenChars + j + 1 >= ssCons->length() - 1) 
+                 break;
+         }
+         outfile << endl;
+      }
+
+      // write annotation line
+      for (int j = 0; j < longestComment; j++)
+       outfile << ' ';
+
+      for (int j = 0; j < numColumns; j++){
+       SafeVector<char> column;
+
+       for (int i = 0; i < GetNumSequences(); i++)
+         if (writtenChars + j < lengths[i])
+           column.push_back (ptrs[i][writtenChars + j + 1]);
+       
+       if (column.size() > 0)
+         outfile << GetAnnotationChar (column);        
+      }
+
+      outfile << endl;
+      writtenChars += numColumns;
+    }
+    outfile << endl;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::GetSequence()
+  //
+  // Retrieve a sequence from the MultiSequence object.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence* GetSequence (int i){
+    assert (sequences);
+    assert (0 <= i && i < (int) sequences->size());
+
+    return (*sequences)[i];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::GetSequence()
+  //
+  // Retrieve a sequence from the MultiSequence object
+  // (const version).
+  /////////////////////////////////////////////////////////////////
+
+  const Sequence* GetSequence (int i) const {
+    assert (sequences);
+    assert (0 <= i && i < (int) sequences->size());
+
+    return (*sequences)[i];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::GetNumSequences()
+  //
+  // Returns the number of sequences in the MultiSequence.
+  /////////////////////////////////////////////////////////////////
+
+  int GetNumSequences () const {
+    if (!sequences) return 0;
+    return (int) sequences->size();
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::SortByHeader()
+  //
+  // Organizes the sequences according to their sequence headers
+  // in ascending order.
+  /////////////////////////////////////////////////////////////////
+
+  void SortByHeader () {
+    assert (sequences);
+
+    // a quick and easy O(n^2) sort
+    for (int i = 0; i < (int) sequences->size()-1; i++){
+      for (int j = i+1; j < (int) sequences->size(); j++){
+        if ((*sequences)[i]->GetHeader() > (*sequences)[j]->GetHeader())
+          swap ((*sequences)[i], (*sequences)[j]);
+      }
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::SortByLabel()
+  //
+  // Organizes the sequences according to their sequence labels
+  // in ascending order.
+  /////////////////////////////////////////////////////////////////
+
+  void SortByLabel () {
+    assert (sequences);
+
+    // a quick and easy O(n^2) sort
+    for (int i = 0; i < (int) sequences->size()-1; i++){
+      for (int j = i+1; j < (int) sequences->size(); j++){
+        if ((*sequences)[i]->GetSortLabel() > (*sequences)[j]->GetSortLabel())
+          swap ((*sequences)[i], (*sequences)[j]);
+      }
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::SaveOrdering()
+  //
+  // Relabels sequences so as to preserve the current ordering.
+  /////////////////////////////////////////////////////////////////
+
+  void SaveOrdering () {
+    assert (sequences);
+    
+    for (int i = 0; i < (int) sequences->size(); i++)
+      (*sequences)[i]->SetSortLabel (i);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // MultiSequence::Project()
+  //
+  // Given a set of indices, extract all sequences from the current
+  // MultiSequence object whose index is included in the set.
+  // Then, project the multiple alignments down to the desired
+  // subset, and return the projection as a new MultiSequence
+  // object.
+  /////////////////////////////////////////////////////////////////
+
+  MultiSequence *Project (const set<int> &indices){
+    SafeVector<SafeVector<char>::iterator> oldPtrs (indices.size());
+    SafeVector<SafeVector<char> *> newPtrs (indices.size());
+
+    assert (indices.size() != 0);
+
+    // grab old data
+    int i = 0;
+    for (set<int>::const_iterator iter = indices.begin(); iter != indices.end(); ++iter){
+      oldPtrs[i++] = GetSequence (*iter)->GetDataPtr();
+    }
+
+    // compute new length
+    int oldLength = GetSequence (*indices.begin())->GetLength();
+    int newLength = 0;
+    for (i = 1; i <= oldLength; i++){
+
+      // check to see if there is a gap in every sequence of the set
+      bool found = false;
+      for (int j = 0; !found && j < (int) indices.size(); j++)
+        found = (oldPtrs[j][i] != '-');
+
+      // if not, then this column counts towards the sequence length
+      if (found) newLength++;
+    }
+
+    // build new alignments
+    for (i = 0; i < (int) indices.size(); i++){
+      newPtrs[i] = new SafeVector<char>(); assert (newPtrs[i]);
+      newPtrs[i]->push_back ('@');
+    }
+
+    // add all needed columns
+    for (i = 1; i <= oldLength; i++){
+
+      // make sure column is not gapped in all sequences in the set
+      bool found = false;
+      for (int j = 0; !found && j < (int) indices.size(); j++)
+        found = (oldPtrs[j][i] != '-');
+
+      // if not, then add it
+      if (found){
+        for (int j = 0; j < (int) indices.size(); j++)
+          newPtrs[j]->push_back (oldPtrs[j][i]);
+      }
+    }
+
+    // wrap sequences in MultiSequence object
+    MultiSequence *ret = new MultiSequence();
+    i = 0;
+    for (set<int>::const_iterator iter = indices.begin(); iter != indices.end(); ++iter){
+      ret->AddSequence (new Sequence (newPtrs[i++], GetSequence (*iter)->GetHeader(), newLength,
+                                      GetSequence (*iter)->GetSortLabel(), GetSequence (*iter)->GetLabel()));
+    }
+
+    return ret;
+  }
+};
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProbabilisticModel.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProbabilisticModel.h
new file mode 100644 (file)
index 0000000..cd9dae9
--- /dev/null
@@ -0,0 +1,1211 @@
+/////////////////////////////////////////////////////////////////
+// ProbabilisticModel.h
+//
+// Routines for (1) posterior probability computations
+//              (2) chained anchoring
+//              (3) maximum weight trace alignment
+/////////////////////////////////////////////////////////////////
+
+#ifndef PROBABILISTICMODEL_H
+#define PROBABILISTICMODEL_H
+
+#include <list>
+#include <cmath>
+#include <cstdio>
+#include "SafeVector.h"
+#include "ScoreType.h"
+#include "SparseMatrix.h"
+#include "MultiSequence.h"
+#include "StemCandidate.hpp"
+#include "scarna.hpp"
+#include "nrutil.h"
+#include <vector>
+
+using namespace std;
+
+const int NumMatchStates = 1;                                    // note that in this version the number
+                                                                 // of match states is fixed at 1...will
+                                                                 // change in future versions
+const int NumMatrixTypes = NumMatchStates + NumInsertStates * 2;
+
+/////////////////////////////////////////////////////////////////
+// ProbabilisticModel
+//
+// Class for storing the parameters of a probabilistic model and
+// performing different computations based on those parameters.
+// In particular, this class handles the computation of
+// posterior probabilities that may be used in alignment.
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+class ProbabilisticModel {
+
+  float initialDistribution[NumMatrixTypes];               // holds the initial probabilities for each state
+  float transProb[NumMatrixTypes][NumMatrixTypes];         // holds all state-to-state transition probabilities
+  float matchProb[256][256];                               // emission probabilities for match states
+  float insProb[256][NumMatrixTypes];                      // emission probabilities for insert states
+  NRMat<float> WM;
+
+ public:
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ProbabilisticModel()
+  //
+  // Constructor.  Builds a new probabilistic model using the
+  // given parameters.
+  /////////////////////////////////////////////////////////////////
+
+  ProbabilisticModel (const VF &initDistribMat, const VF &gapOpen, const VF &gapExtend,
+                      const VVF &emitPairs, const VF &emitSingle){
+
+    // build transition matrix
+    VVF transMat (NumMatrixTypes, VF (NumMatrixTypes, 0.0f));
+    transMat[0][0] = 1;
+    for (int i = 0; i < NumInsertStates; i++){
+      transMat[0][2*i+1] = gapOpen[2*i];
+      transMat[0][2*i+2] = gapOpen[2*i+1];
+      transMat[0][0] -= (gapOpen[2*i] + gapOpen[2*i+1]);
+      assert (transMat[0][0] > 0);
+      transMat[2*i+1][2*i+1] = gapExtend[2*i];
+      transMat[2*i+2][2*i+2] = gapExtend[2*i+1];
+      transMat[2*i+1][2*i+2] = 0;
+      transMat[2*i+2][2*i+1] = 0;
+      transMat[2*i+1][0] = 1 - gapExtend[2*i];
+      transMat[2*i+2][0] = 1 - gapExtend[2*i+1];
+    }
+
+    // create initial and transition probability matrices
+    for (int i = 0; i < NumMatrixTypes; i++){
+      initialDistribution[i] = LOG (initDistribMat[i]);
+      for (int j = 0; j < NumMatrixTypes; j++)
+        transProb[i][j] = LOG (transMat[i][j]);
+    }
+
+    // create insertion and match probability matrices
+    for (int i = 0; i < 256; i++){
+      for (int j = 0; j < NumMatrixTypes; j++)
+        insProb[i][j] = LOG (emitSingle[i]);
+      for (int j = 0; j < 256; j++)
+        matchProb[i][j] = LOG (emitPairs[i][j]);
+    }
+  }
+
+  NRMat<float> weightMatchScore(std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2,
+                       std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2, NRMat<float> WM) {
+      int len      = WORDLENGTH;
+      int size     = matchPSCS1->size();
+      float weight = 1000;
+
+      for(int iter = 0; iter < size; iter++) {
+         int i = matchPSCS1->at(iter);
+         int j = matchPSCS2->at(iter);
+
+         const StemCandidate &sc1 = pscs1->at(i);
+         const StemCandidate &sc2 = pscs2->at(j);
+       
+         for(int k = 0; k < len; k++) {
+             WM[sc1.GetPosition() + k][sc2.GetPosition() + k] += weight;
+//           sumWeight += weight;
+         }
+      }
+      return WM;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeForwardMatrix()
+  //
+  // Computes a set of forward probability matrices for aligning
+  // seq1 and seq2.
+  //
+  // For efficiency reasons, a single-dimensional floating-point
+  // array is used here, with the following indexing scheme:
+  //
+  //    forward[i + NumMatrixTypes * (j * (seq2Length+1) + k)]
+  //    refers to the probability of aligning through j characters
+  //    of the first sequence, k characters of the second sequence,
+  //    and ending in state i.
+  /////////////////////////////////////////////////////////////////
+
+  VF *ComputeForwardMatrix (Sequence *seq1, Sequence *seq2) const {
+
+    assert (seq1);
+    assert (seq2);
+
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+
+    // retrieve the points to the beginning of each sequence
+    SafeVector<char>::iterator iter1 = seq1->GetDataPtr();
+    SafeVector<char>::iterator iter2 = seq2->GetDataPtr();
+
+    // create matrix
+    VF *forwardPtr = new VF (NumMatrixTypes * (seq1Length+1) * (seq2Length+1), LOG_ZERO);
+    assert (forwardPtr);
+    VF &forward = *forwardPtr;
+
+    // initialization condition
+    forward[0 + NumMatrixTypes * (1 * (seq2Length+1) + 1)] = 
+      initialDistribution[0] + matchProb[(unsigned char) iter1[1]][(unsigned char) iter2[1]];
+   
+    for (int k = 0; k < NumInsertStates; k++){
+      forward[2*k+1 + NumMatrixTypes * (1 * (seq2Length+1) + 0)] = 
+       initialDistribution[2*k+1] + insProb[(unsigned char) iter1[1]][k];
+      forward[2*k+2 + NumMatrixTypes * (0 * (seq2Length+1) + 1)] = 
+       initialDistribution[2*k+2] + insProb[(unsigned char) iter2[1]][k]; 
+    }
+    
+    // remember offset for each index combination
+    int ij = 0;
+    int i1j = -seq2Length - 1;
+    int ij1 = -1;
+    int i1j1 = -seq2Length - 2;
+
+    ij *= NumMatrixTypes;
+    i1j *= NumMatrixTypes;
+    ij1 *= NumMatrixTypes;
+    i1j1 *= NumMatrixTypes;
+
+    // compute forward scores
+    for (int i = 0; i <= seq1Length; i++){
+      unsigned char c1 = (i == 0) ? '~' : (unsigned char) iter1[i];
+      for (int j = 0; j <= seq2Length; j++){
+        unsigned char c2 = (j == 0) ? '~' : (unsigned char) iter2[j];
+
+       if (i > 1 || j > 1){
+         if (i > 0 && j > 0){
+           forward[0 + ij] = forward[0 + i1j1] + transProb[0][0];
+           for (int k = 1; k < NumMatrixTypes; k++)
+             LOG_PLUS_EQUALS (forward[0 + ij], forward[k + i1j1] + transProb[k][0]);
+           forward[0 + ij] += matchProb[c1][c2];
+         }
+         if (i > 0){
+           for (int k = 0; k < NumInsertStates; k++)
+             forward[2*k+1 + ij] = insProb[c1][k] +
+               LOG_ADD (forward[0 + i1j] + transProb[0][2*k+1],
+                        forward[2*k+1 + i1j] + transProb[2*k+1][2*k+1]);
+         }
+         if (j > 0){
+           for (int k = 0; k < NumInsertStates; k++)
+             forward[2*k+2 + ij] = insProb[c2][k] +
+               LOG_ADD (forward[0 + ij1] + transProb[0][2*k+2],
+                        forward[2*k+2 + ij1] + transProb[2*k+2][2*k+2]);
+         }
+       }
+
+        ij += NumMatrixTypes;
+        i1j += NumMatrixTypes;
+        ij1 += NumMatrixTypes;
+        i1j1 += NumMatrixTypes;
+      }
+    }
+
+    return forwardPtr;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeBackwardMatrix()
+  //
+  // Computes a set of backward probability matrices for aligning
+  // seq1 and seq2.
+  //
+  // For efficiency reasons, a single-dimensional floating-point
+  // array is used here, with the following indexing scheme:
+  //
+  //    backward[i + NumMatrixTypes * (j * (seq2Length+1) + k)]
+  //    refers to the probability of starting in state i and
+  //    aligning from character j+1 to the end of the first
+  //    sequence and from character k+1 to the end of the second
+  //    sequence.
+  /////////////////////////////////////////////////////////////////
+
+  VF *ComputeBackwardMatrix (Sequence *seq1, Sequence *seq2) const {
+
+    assert (seq1);
+    assert (seq2);
+
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+    SafeVector<char>::iterator iter1 = seq1->GetDataPtr();
+    SafeVector<char>::iterator iter2 = seq2->GetDataPtr();
+
+    // create matrix
+    VF *backwardPtr = new VF (NumMatrixTypes * (seq1Length+1) * (seq2Length+1), LOG_ZERO);
+    assert (backwardPtr);
+    VF &backward = *backwardPtr;
+
+    // initialization condition
+    for (int k = 0; k < NumMatrixTypes; k++)
+      backward[NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1) + k] = initialDistribution[k];
+
+    // remember offset for each index combination
+    int ij = (seq1Length+1) * (seq2Length+1) - 1;
+    int i1j = ij + seq2Length + 1;
+    int ij1 = ij + 1;
+    int i1j1 = ij + seq2Length + 2;
+
+    ij *= NumMatrixTypes;
+    i1j *= NumMatrixTypes;
+    ij1 *= NumMatrixTypes;
+    i1j1 *= NumMatrixTypes;
+
+    // compute backward scores
+    for (int i = seq1Length; i >= 0; i--){
+      unsigned char c1 = (i == seq1Length) ? '~' : (unsigned char) iter1[i+1];
+      for (int j = seq2Length; j >= 0; j--){
+        unsigned char c2 = (j == seq2Length) ? '~' : (unsigned char) iter2[j+1];
+
+        if (i < seq1Length && j < seq2Length){
+          const float ProbXY = backward[0 + i1j1] + matchProb[c1][c2];
+          for (int k = 0; k < NumMatrixTypes; k++)
+            LOG_PLUS_EQUALS (backward[k + ij], ProbXY + transProb[k][0]);
+        }
+        if (i < seq1Length){
+          for (int k = 0; k < NumInsertStates; k++){
+            LOG_PLUS_EQUALS (backward[0 + ij], backward[2*k+1 + i1j] + insProb[c1][k] + transProb[0][2*k+1]);
+            LOG_PLUS_EQUALS (backward[2*k+1 + ij], backward[2*k+1 + i1j] + insProb[c1][k] + transProb[2*k+1][2*k+1]);
+          }
+        }
+        if (j < seq2Length){
+          for (int k = 0; k < NumInsertStates; k++){
+            LOG_PLUS_EQUALS (backward[0 + ij], backward[2*k+2 + ij1] + insProb[c2][k] + transProb[0][2*k+2]);
+            LOG_PLUS_EQUALS (backward[2*k+2 + ij], backward[2*k+2 + ij1] + insProb[c2][k] + transProb[2*k+2][2*k+2]);
+          }
+        }
+
+        ij -= NumMatrixTypes;
+        i1j -= NumMatrixTypes;
+        ij1 -= NumMatrixTypes;
+        i1j1 -= NumMatrixTypes;
+      }
+    }
+
+    return backwardPtr;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeTotalProbability()
+  //
+  // Computes the total probability of an alignment given
+  // the forward and backward matrices.
+  /////////////////////////////////////////////////////////////////
+
+  float ComputeTotalProbability (int seq1Length, int seq2Length,
+                                 const VF &forward, const VF &backward) const {
+
+    // compute total probability
+    float totalForwardProb = LOG_ZERO;
+    float totalBackwardProb = LOG_ZERO;
+    for (int k = 0; k < NumMatrixTypes; k++){
+      LOG_PLUS_EQUALS (totalForwardProb,
+                       forward[k + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)] + 
+                      backward[k + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)]);
+    }
+
+    totalBackwardProb = 
+      forward[0 + NumMatrixTypes * (1 * (seq2Length+1) + 1)] +
+      backward[0 + NumMatrixTypes * (1 * (seq2Length+1) + 1)];
+
+    for (int k = 0; k < NumInsertStates; k++){
+      LOG_PLUS_EQUALS (totalBackwardProb,
+                      forward[2*k+1 + NumMatrixTypes * (1 * (seq2Length+1) + 0)] +
+                      backward[2*k+1 + NumMatrixTypes * (1 * (seq2Length+1) + 0)]);
+      LOG_PLUS_EQUALS (totalBackwardProb,
+                      forward[2*k+2 + NumMatrixTypes * (0 * (seq2Length+1) + 1)] +
+                      backward[2*k+2 + NumMatrixTypes * (0 * (seq2Length+1) + 1)]);
+    }
+
+    //    cerr << totalForwardProb << " " << totalBackwardProb << endl;
+    
+    return (totalForwardProb + totalBackwardProb) / 2;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputePosteriorMatrix()
+  //
+  // Computes the posterior probability matrix based on
+  // the forward and backward matrices.
+  /////////////////////////////////////////////////////////////////
+
+  VF *ComputePosteriorMatrix (Sequence *seq1, Sequence *seq2,
+                              const VF &forward, const VF &backward) const {
+
+    assert (seq1);
+    assert (seq2);
+
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+
+    float totalProb = ComputeTotalProbability (seq1Length, seq2Length,
+                                               forward, backward);
+
+    // compute posterior matrices
+    VF *posteriorPtr = new VF((seq1Length+1) * (seq2Length+1)); assert (posteriorPtr);
+    VF &posterior = *posteriorPtr;
+
+    int ij = 0;
+    VF::iterator ptr = posterior.begin();
+
+    for (int i = 0; i <= seq1Length; i++){
+      for (int j = 0; j <= seq2Length; j++){
+        *(ptr++) = EXP (min (LOG_ONE, forward[ij] + backward[ij] - totalProb));
+        ij += NumMatrixTypes;
+      }
+    }
+
+    posterior[0] = 0;
+
+    return posteriorPtr;
+  }
+
+  /*
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeExpectedCounts()
+  //
+  // Computes the expected counts for the various transitions.
+  /////////////////////////////////////////////////////////////////
+
+  VVF *ComputeExpectedCounts () const {
+
+    assert (seq1);
+    assert (seq2);
+
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+    SafeVector<char>::iterator iter1 = seq1->GetDataPtr();
+    SafeVector<char>::iterator iter2 = seq2->GetDataPtr();
+
+    // compute total probability
+    float totalProb = ComputeTotalProbability (seq1Length, seq2Length,
+                                               forward, backward);
+
+    // initialize expected counts
+    VVF *countsPtr = new VVF(NumMatrixTypes + 1, VF(NumMatrixTypes, LOG_ZERO)); assert (countsPtr);
+    VVF &counts = *countsPtr;
+
+    // remember offset for each index combination
+    int ij = 0;
+    int i1j = -seq2Length - 1;
+    int ij1 = -1;
+    int i1j1 = -seq2Length - 2;
+
+    ij *= NumMatrixTypes;
+    i1j *= NumMatrixTypes;
+    ij1 *= NumMatrixTypes;
+    i1j1 *= NumMatrixTypes;
+
+    // compute expected counts
+    for (int i = 0; i <= seq1Length; i++){
+      unsigned char c1 = (i == 0) ? '~' : (unsigned char) iter1[i];
+      for (int j = 0; j <= seq2Length; j++){
+        unsigned char c2 = (j == 0) ? '~' : (unsigned char) iter2[j];
+
+        if (i > 0 && j > 0){
+          for (int k = 0; k < NumMatrixTypes; k++)
+            LOG_PLUS_EQUALS (counts[k][0],
+                             forward[k + i1j1] + transProb[k][0] +
+                             matchProb[c1][c2] + backward[0 + ij]);
+        }
+        if (i > 0){
+          for (int k = 0; k < NumInsertStates; k++){
+            LOG_PLUS_EQUALS (counts[0][2*k+1],
+                             forward[0 + i1j] + transProb[0][2*k+1] +
+                             insProb[c1][k] + backward[2*k+1 + ij]);
+            LOG_PLUS_EQUALS (counts[2*k+1][2*k+1],
+                             forward[2*k+1 + i1j] + transProb[2*k+1][2*k+1] +
+                             insProb[c1][k] + backward[2*k+1 + ij]);
+          }
+        }
+        if (j > 0){
+          for (int k = 0; k < NumInsertStates; k++){
+            LOG_PLUS_EQUALS (counts[0][2*k+2],
+                             forward[0 + ij1] + transProb[0][2*k+2] +
+                             insProb[c2][k] + backward[2*k+2 + ij]);
+            LOG_PLUS_EQUALS (counts[2*k+2][2*k+2],
+                             forward[2*k+2 + ij1] + transProb[2*k+2][2*k+2] +
+                             insProb[c2][k] + backward[2*k+2 + ij]);
+          }
+        }
+
+        ij += NumMatrixTypes;
+        i1j += NumMatrixTypes;
+        ij1 += NumMatrixTypes;
+        i1j1 += NumMatrixTypes;
+      }
+    }
+
+    // scale all expected counts appropriately
+    for (int i = 0; i < NumMatrixTypes; i++)
+      for (int j = 0; j < NumMatrixTypes; j++)
+        counts[i][j] -= totalProb;
+
+  }
+  */
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeNewParameters()
+  //
+  // Computes a new parameter set based on the expected counts
+  // given.
+  /////////////////////////////////////////////////////////////////
+
+  void ComputeNewParameters (Sequence *seq1, Sequence *seq2,
+                            const VF &forward, const VF &backward,
+                             VF &initDistribMat, VF &gapOpen,
+                             VF &gapExtend, VVF &emitPairs, VF &emitSingle, bool enableTrainEmissions) const {
+    
+    assert (seq1);
+    assert (seq2);
+
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+    SafeVector<char>::iterator iter1 = seq1->GetDataPtr();
+    SafeVector<char>::iterator iter2 = seq2->GetDataPtr();
+
+    // compute total probability
+    float totalProb = ComputeTotalProbability (seq1Length, seq2Length,
+                                               forward, backward);
+    
+    // initialize expected counts
+    VVF transCounts (NumMatrixTypes, VF (NumMatrixTypes, LOG_ZERO));
+    VF initCounts (NumMatrixTypes, LOG_ZERO);
+    VVF pairCounts (256, VF (256, LOG_ZERO));
+    VF singleCounts (256, LOG_ZERO);
+    
+    // remember offset for each index combination
+    int ij = 0;
+    int i1j = -seq2Length - 1;
+    int ij1 = -1;
+    int i1j1 = -seq2Length - 2;
+
+    ij *= NumMatrixTypes;
+    i1j *= NumMatrixTypes;
+    ij1 *= NumMatrixTypes;
+    i1j1 *= NumMatrixTypes;
+
+    // compute initial distribution posteriors
+    initCounts[0] = LOG_ADD (forward[0 + NumMatrixTypes * (1 * (seq2Length+1) + 1)] +
+                            backward[0 + NumMatrixTypes * (1 * (seq2Length+1) + 1)],
+                            forward[0 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)] + 
+                            backward[0 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)]);
+    for (int k = 0; k < NumInsertStates; k++){
+      initCounts[2*k+1] = LOG_ADD (forward[2*k+1 + NumMatrixTypes * (1 * (seq2Length+1) + 0)] +
+                                  backward[2*k+1 + NumMatrixTypes * (1 * (seq2Length+1) + 0)],
+                                  forward[2*k+1 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)] + 
+                                  backward[2*k+1 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)]);
+      initCounts[2*k+2] = LOG_ADD (forward[2*k+2 + NumMatrixTypes * (0 * (seq2Length+1) + 1)] +
+                                  backward[2*k+2 + NumMatrixTypes * (0 * (seq2Length+1) + 1)],
+                                  forward[2*k+2 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)] + 
+                                  backward[2*k+2 + NumMatrixTypes * ((seq1Length+1) * (seq2Length+1) - 1)]);
+    }
+
+    // compute expected counts
+    for (int i = 0; i <= seq1Length; i++){
+      unsigned char c1 = (i == 0) ? '~' : (unsigned char) toupper(iter1[i]);
+      for (int j = 0; j <= seq2Length; j++){
+        unsigned char c2 = (j == 0) ? '~' : (unsigned char) toupper(iter2[j]);
+
+       if (i > 0 && j > 0){
+         if (enableTrainEmissions && i == 1 && j == 1){
+           LOG_PLUS_EQUALS (pairCounts[c1][c2],
+                            initialDistribution[0] + matchProb[c1][c2] + backward[0 + ij]);
+           LOG_PLUS_EQUALS (pairCounts[c2][c1],
+                            initialDistribution[0] + matchProb[c2][c1] + backward[0 + ij]);
+         }
+
+         for (int k = 0; k < NumMatrixTypes; k++){
+           LOG_PLUS_EQUALS (transCounts[k][0],
+                            forward[k + i1j1] + transProb[k][0] +
+                            matchProb[c1][c2] + backward[0 + ij]);
+           if (enableTrainEmissions && i != 1 || j != 1){
+             LOG_PLUS_EQUALS (pairCounts[c1][c2],
+                              forward[k + i1j1] + transProb[k][0] +
+                              matchProb[c1][c2] + backward[0 + ij]);
+             LOG_PLUS_EQUALS (pairCounts[c2][c1],
+                              forward[k + i1j1] + transProb[k][0] +
+                              matchProb[c2][c1] + backward[0 + ij]);
+           }
+         }
+       }
+       if (i > 0){
+         for (int k = 0; k < NumInsertStates; k++){
+           LOG_PLUS_EQUALS (transCounts[0][2*k+1],
+                            forward[0 + i1j] + transProb[0][2*k+1] +
+                            insProb[c1][k] + backward[2*k+1 + ij]);
+           LOG_PLUS_EQUALS (transCounts[2*k+1][2*k+1],
+                            forward[2*k+1 + i1j] + transProb[2*k+1][2*k+1] +
+                            insProb[c1][k] + backward[2*k+1 + ij]);
+           if (enableTrainEmissions){
+             if (i == 1 && j == 0){
+               LOG_PLUS_EQUALS (singleCounts[c1],
+                                initialDistribution[2*k+1] + insProb[c1][k] + backward[2*k+1 + ij]);
+             }
+             else {
+               LOG_PLUS_EQUALS (singleCounts[c1],
+                                forward[0 + i1j] + transProb[0][2*k+1] +
+                                insProb[c1][k] + backward[2*k+1 + ij]);
+               LOG_PLUS_EQUALS (singleCounts[c1],
+                                forward[2*k+1 + i1j] + transProb[2*k+1][2*k+1] +
+                                insProb[c1][k] + backward[2*k+1 + ij]);
+             }
+           }
+         }
+       }
+       if (j > 0){
+         for (int k = 0; k < NumInsertStates; k++){
+           LOG_PLUS_EQUALS (transCounts[0][2*k+2],
+                            forward[0 + ij1] + transProb[0][2*k+2] +
+                            insProb[c2][k] + backward[2*k+2 + ij]);
+           LOG_PLUS_EQUALS (transCounts[2*k+2][2*k+2],
+                            forward[2*k+2 + ij1] + transProb[2*k+2][2*k+2] +
+                            insProb[c2][k] + backward[2*k+2 + ij]);
+           if (enableTrainEmissions){
+             if (i == 0 && j == 1){
+               LOG_PLUS_EQUALS (singleCounts[c2],
+                                initialDistribution[2*k+2] + insProb[c2][k] + backward[2*k+2 + ij]);
+             }
+             else {
+               LOG_PLUS_EQUALS (singleCounts[c2],
+                                forward[0 + ij1] + transProb[0][2*k+2] +
+                                insProb[c2][k] + backward[2*k+2 + ij]);
+               LOG_PLUS_EQUALS (singleCounts[c2],
+                                forward[2*k+2 + ij1] + transProb[2*k+2][2*k+2] +
+                                insProb[c2][k] + backward[2*k+2 + ij]);
+             }
+           }
+         }
+       }
+      
+        ij += NumMatrixTypes;
+        i1j += NumMatrixTypes;
+        ij1 += NumMatrixTypes;
+        i1j1 += NumMatrixTypes;
+      }
+    }
+
+    // scale all expected counts appropriately
+    for (int i = 0; i < NumMatrixTypes; i++){
+      initCounts[i] -= totalProb;
+      for (int j = 0; j < NumMatrixTypes; j++)
+        transCounts[i][j] -= totalProb;
+    }
+    if (enableTrainEmissions){
+      for (int i = 0; i < 256; i++){
+       for (int j = 0; j < 256; j++)
+         pairCounts[i][j] -= totalProb;
+       singleCounts[i] -= totalProb;
+      }
+    }
+
+    // compute new initial distribution
+    float totalInitDistribCounts = 0;
+    for (int i = 0; i < NumMatrixTypes; i++)
+      totalInitDistribCounts += exp (initCounts[i]); // should be 2
+    initDistribMat[0] = min (1.0f, max (0.0f, (float) exp (initCounts[0]) / totalInitDistribCounts));
+    for (int k = 0; k < NumInsertStates; k++){
+      float val = (exp (initCounts[2*k+1]) + exp (initCounts[2*k+2])) / 2;
+      initDistribMat[2*k+1] = initDistribMat[2*k+2] = min (1.0f, max (0.0f, val / totalInitDistribCounts));
+    }
+
+    // compute total counts for match state
+    float inMatchStateCounts = 0;
+    for (int i = 0; i < NumMatrixTypes; i++)
+      inMatchStateCounts += exp (transCounts[0][i]);
+    for (int i = 0; i < NumInsertStates; i++){
+
+      // compute total counts for gap state
+      float inGapStateCounts =
+        exp (transCounts[2*i+1][0]) +
+        exp (transCounts[2*i+1][2*i+1]) +
+        exp (transCounts[2*i+2][0]) +
+        exp (transCounts[2*i+2][2*i+2]);
+
+      gapOpen[2*i] = gapOpen[2*i+1] =
+        (exp (transCounts[0][2*i+1]) +
+         exp (transCounts[0][2*i+2])) /
+        (2 * inMatchStateCounts);
+
+      gapExtend[2*i] = gapExtend[2*i+1] =
+        (exp (transCounts[2*i+1][2*i+1]) +
+         exp (transCounts[2*i+2][2*i+2])) /
+        inGapStateCounts;
+    }
+
+    if (enableTrainEmissions){
+      float totalPairCounts = 0;
+      float totalSingleCounts = 0;
+      for (int i = 0; i < 256; i++){
+       for (int j = 0; j <= i; j++)
+         totalPairCounts += exp (pairCounts[j][i]);
+       totalSingleCounts += exp (singleCounts[i]);
+      }
+      
+      for (int i = 0; i < 256; i++) if (!islower ((char) i)){
+       int li = (int)((unsigned char) tolower ((char) i));
+       for (int j = 0; j <= i; j++) if (!islower ((char) j)){
+         int lj = (int)((unsigned char) tolower ((char) j));
+         emitPairs[i][j] = emitPairs[i][lj] = emitPairs[li][j] = emitPairs[li][lj] = 
+           emitPairs[j][i] = emitPairs[j][li] = emitPairs[lj][i] = emitPairs[lj][li] = exp(pairCounts[j][i]) / totalPairCounts;
+       }
+       emitSingle[i] = emitSingle[li] = exp(singleCounts[i]) / totalSingleCounts;
+      }
+    }
+  }
+    
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeAlignment()
+  //
+  // Computes an alignment based on the given posterior matrix.
+  // This is done by finding the maximum summing path (or
+  // maximum weight trace) through the posterior matrix.  The
+  // final alignment is returned as a pair consisting of:
+  //    (1) a string (e.g., XXXBBXXXBBBBBBYYYYBBB) where X's and
+  //        denote insertions in one of the two sequences and
+  //        B's denote that both sequences are present (i.e.
+  //        matches).
+  //    (2) a float indicating the sum achieved
+  /////////////////////////////////////////////////////////////////
+
+  pair<SafeVector<char> *, float> ComputeAlignment (int seq1Length, int seq2Length, const VF &posterior) const {
+
+    float *twoRows = new float[(seq2Length+1)*2]; assert (twoRows);
+    float *oldRow = twoRows;
+    float *newRow = twoRows + seq2Length + 1;
+
+    char *tracebackMatrix = new char[(seq1Length+1)*(seq2Length+1)]; assert (tracebackMatrix);
+    char *tracebackPtr = tracebackMatrix;
+
+    VF::const_iterator posteriorPtr = posterior.begin() + seq2Length + 1;
+
+    // initialization
+    for (int i = 0; i <= seq2Length; i++){
+      oldRow[i] = 0;
+      *(tracebackPtr++) = 'L';
+    }
+
+    // fill in matrix
+    for (int i = 1; i <= seq1Length; i++){
+
+      // initialize left column
+      newRow[0] = 0;
+      posteriorPtr++;
+      *(tracebackPtr++) = 'U';
+
+      // fill in rest of row
+      for (int j = 1; j <= seq2Length; j++){
+        ChooseBestOfThree (*(posteriorPtr++) + oldRow[j-1], newRow[j-1], oldRow[j],
+                           'D', 'L', 'U', &newRow[j], tracebackPtr++); // Match, insert, delete
+      }
+
+      // swap rows
+      float *temp = oldRow;
+      oldRow = newRow;
+      newRow = temp;
+    }
+
+    // store best score
+    float total = oldRow[seq2Length];
+    delete [] twoRows;
+
+    // compute traceback
+    SafeVector<char> *alignment = new SafeVector<char>; assert (alignment);
+    int r = seq1Length, c = seq2Length;
+    while (r != 0 || c != 0){
+      char ch = tracebackMatrix[r*(seq2Length+1) + c];
+      switch (ch){
+      case 'L': c--; alignment->push_back ('Y'); break;
+      case 'U': r--; alignment->push_back ('X'); break;
+      case 'D': c--; r--; alignment->push_back ('B'); break;
+      default: assert (false);
+      }
+    }
+
+    delete [] tracebackMatrix;
+
+    reverse (alignment->begin(), alignment->end());
+
+    return make_pair(alignment, total);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeAlignment2()
+  //
+  // Computes an alignment based on the given posterior matrix.
+  // This is done by finding the maximum summing path (or
+  // maximum weight trace) through the posterior matrix.  The
+  // final alignment is returned as a pair consisting of:
+  //    (1) a string (e.g., XXXBBXXXBBBBBBYYYYBBB) where X's and
+  //        denote insertions in one of the two sequences and
+  //        B's denote that both sequences are present (i.e.
+  //        matches).
+  //    (2) a float indicating the sum achieved
+  /////////////////////////////////////////////////////////////////
+
+  pair<SafeVector<char> *, float> ComputeAlignment2 (int seq1Length, int seq2Length,
+                                                    const VF &posterior, std::vector<StemCandidate> *pscs1, std::vector<StemCandidate> *pscs2,
+                                                    std::vector<int> *matchPSCS1, std::vector<int> *matchPSCS2) const {
+    NRMat<float> WM(seq1Length + 1, seq2Length + 1);
+    for (int i = 0; i <= seq1Length; i++) {
+       for (int j = 0; j <= seq2Length; j++) {
+           WM[i][j] = 0;
+       }
+    }
+
+    int len      = WORDLENGTH;
+    int size     = matchPSCS1->size();
+    float weight = 1000;
+
+    for(int iter = 0; iter < size; iter++) {
+       int i = matchPSCS1->at(iter);
+       int j = matchPSCS2->at(iter);
+
+       const StemCandidate &sc1 = pscs1->at(i);
+       const StemCandidate &sc2 = pscs2->at(j);
+       for(int k = 0; k < len; k++) {
+           WM[sc1.GetPosition() + k][sc2.GetPosition() + k] += weight;
+       }
+    }
+    float *twoRows = new float[(seq2Length+1)*2]; assert (twoRows);
+    float *oldRow = twoRows;
+    float *newRow = twoRows + seq2Length + 1;
+
+    char *tracebackMatrix = new char[(seq1Length+1)*(seq2Length+1)]; assert (tracebackMatrix);
+    char *tracebackPtr = tracebackMatrix;
+
+    VF::const_iterator posteriorPtr = posterior.begin() + seq2Length + 1;
+
+    // initialization
+    for (int i = 0; i <= seq2Length; i++){
+      oldRow[i] = 0;
+      *(tracebackPtr++) = 'L';
+    }
+
+    // fill in matrix
+    for (int i = 1; i <= seq1Length; i++){
+
+      // initialize left column
+      newRow[0] = 0;
+      posteriorPtr++;
+      *(tracebackPtr++) = 'U';
+
+      // fill in rest of row
+      for (int j = 1; j <= seq2Length; j++){
+        ChooseBestOfThree (*(posteriorPtr++) + oldRow[j-1] + WM[i][j], newRow[j-1], oldRow[j],
+                           'D', 'L', 'U', &newRow[j], tracebackPtr++);
+      }
+
+      // swap rows
+      float *temp = oldRow;
+      oldRow = newRow;
+      newRow = temp;
+    }
+
+    // store best score
+    float total = oldRow[seq2Length];
+    delete [] twoRows;
+
+    // compute traceback
+    SafeVector<char> *alignment = new SafeVector<char>; assert (alignment);
+    int r = seq1Length, c = seq2Length;
+    while (r != 0 || c != 0){
+      char ch = tracebackMatrix[r*(seq2Length+1) + c];
+      switch (ch){
+      case 'L': c--; alignment->push_back ('Y'); break;
+      case 'U': r--; alignment->push_back ('X'); break;
+      case 'D': c--; r--; alignment->push_back ('B'); break;
+      default: assert (false);
+      }
+    }
+
+    delete [] tracebackMatrix;
+
+    reverse (alignment->begin(), alignment->end());
+
+    return make_pair(alignment, total);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeAlignmentWithGapPenalties()
+  //
+  // Similar to ComputeAlignment() except with gap penalties.
+  /////////////////////////////////////////////////////////////////
+
+  pair<SafeVector<char> *, float> ComputeAlignmentWithGapPenalties (MultiSequence *align1,
+                                                                    MultiSequence *align2,
+                                                                    const VF &posterior, int numSeqs1,
+                                                                    int numSeqs2,
+                                                                    float gapOpenPenalty,
+                                                                    float gapContinuePenalty) const {
+    int seq1Length = align1->GetSequence(0)->GetLength();
+    int seq2Length = align2->GetSequence(0)->GetLength();
+    SafeVector<SafeVector<char>::iterator > dataPtrs1 (align1->GetNumSequences());
+    SafeVector<SafeVector<char>::iterator > dataPtrs2 (align2->GetNumSequences());
+
+    // grab character data
+    for (int i = 0; i < align1->GetNumSequences(); i++)
+      dataPtrs1[i] = align1->GetSequence(i)->GetDataPtr();
+    for (int i = 0; i < align2->GetNumSequences(); i++)
+      dataPtrs2[i] = align2->GetSequence(i)->GetDataPtr();
+
+    // the number of active sequences at any given column is defined to be the
+    // number of non-gap characters in that column; the number of gap opens at
+    // any given column is defined to be the number of gap characters in that
+    // column where the previous character in the respective sequence was not
+    // a gap
+    SafeVector<int> numActive1 (seq1Length+1), numGapOpens1 (seq1Length+1);
+    SafeVector<int> numActive2 (seq2Length+1), numGapOpens2 (seq2Length+1);
+
+    // compute number of active sequences and gap opens for each group
+    for (int i = 0; i < align1->GetNumSequences(); i++){
+      SafeVector<char>::iterator dataPtr = align1->GetSequence(i)->GetDataPtr();
+      numActive1[0] = numGapOpens1[0] = 0;
+      for (int j = 1; j <= seq1Length; j++){
+        if (dataPtr[j] != '-'){
+          numActive1[j]++;
+          numGapOpens1[j] += (j != 1 && dataPtr[j-1] != '-');
+        }
+      }
+    }
+    for (int i = 0; i < align2->GetNumSequences(); i++){
+      SafeVector<char>::iterator dataPtr = align2->GetSequence(i)->GetDataPtr();
+      numActive2[0] = numGapOpens2[0] = 0;
+      for (int j = 1; j <= seq2Length; j++){
+        if (dataPtr[j] != '-'){
+          numActive2[j]++;
+          numGapOpens2[j] += (j != 1 && dataPtr[j-1] != '-');
+        }
+      }
+    }
+
+    VVF openingPenalty1 (numSeqs1+1, VF (numSeqs2+1));
+    VF continuingPenalty1 (numSeqs1+1);
+    VVF openingPenalty2 (numSeqs1+1, VF (numSeqs2+1));
+    VF continuingPenalty2 (numSeqs2+1);
+
+    // precompute penalties
+    for (int i = 0; i <= numSeqs1; i++)
+      for (int j = 0; j <= numSeqs2; j++)
+        openingPenalty1[i][j] = i * (gapOpenPenalty * j + gapContinuePenalty * (numSeqs2 - j));
+    for (int i = 0; i <= numSeqs1; i++)
+      continuingPenalty1[i] = i * gapContinuePenalty * numSeqs2;
+    for (int i = 0; i <= numSeqs2; i++)
+      for (int j = 0; j <= numSeqs1; j++)
+        openingPenalty2[i][j] = i * (gapOpenPenalty * j + gapContinuePenalty * (numSeqs1 - j));
+    for (int i = 0; i <= numSeqs2; i++)
+      continuingPenalty2[i] = i * gapContinuePenalty * numSeqs1;
+
+    float *twoRows = new float[6*(seq2Length+1)]; assert (twoRows);
+    float *oldRowMatch = twoRows;
+    float *newRowMatch = twoRows + (seq2Length+1);
+    float *oldRowInsertX = twoRows + 2*(seq2Length+1);
+    float *newRowInsertX = twoRows + 3*(seq2Length+1);
+    float *oldRowInsertY = twoRows + 4*(seq2Length+1);
+    float *newRowInsertY = twoRows + 5*(seq2Length+1);
+
+    char *tracebackMatrix = new char[3*(seq1Length+1)*(seq2Length+1)]; assert (tracebackMatrix);
+    char *tracebackPtr = tracebackMatrix;
+
+    VF::const_iterator posteriorPtr = posterior.begin() + seq2Length + 1;
+
+    // initialization
+    for (int i = 0; i <= seq2Length; i++){
+      oldRowMatch[i] = oldRowInsertX[i] = (i == 0) ? 0 : LOG_ZERO;
+      oldRowInsertY[i] = (i == 0) ? 0 : oldRowInsertY[i-1] + continuingPenalty2[numActive2[i]];
+      *(tracebackPtr) = *(tracebackPtr+1) = *(tracebackPtr+2) = 'Y';
+      tracebackPtr += 3;
+    }
+
+    // fill in matrix
+    for (int i = 1; i <= seq1Length; i++){
+
+      // initialize left column
+      newRowMatch[0] = newRowInsertY[0] = LOG_ZERO;
+      newRowInsertX[0] = oldRowInsertX[0] + continuingPenalty1[numActive1[i]];
+      posteriorPtr++;
+      *(tracebackPtr) = *(tracebackPtr+1) = *(tracebackPtr+2) = 'X';
+      tracebackPtr += 3;
+
+      // fill in rest of row
+      for (int j = 1; j <= seq2Length; j++){
+
+        // going to MATCH state
+        ChooseBestOfThree (oldRowMatch[j-1],
+                           oldRowInsertX[j-1],
+                           oldRowInsertY[j-1],
+                           'M', 'X', 'Y', &newRowMatch[j], tracebackPtr++);
+        newRowMatch[j] += *(posteriorPtr++);
+
+        // going to INSERT X state
+        ChooseBestOfThree (oldRowMatch[j] + openingPenalty1[numActive1[i]][numGapOpens2[j]],
+                           oldRowInsertX[j] + continuingPenalty1[numActive1[i]],
+                           oldRowInsertY[j] + openingPenalty1[numActive1[i]][numGapOpens2[j]],
+                           'M', 'X', 'Y', &newRowInsertX[j], tracebackPtr++);
+
+        // going to INSERT Y state
+        ChooseBestOfThree (newRowMatch[j-1] + openingPenalty2[numActive2[j]][numGapOpens1[i]],
+                           newRowInsertX[j-1] + openingPenalty2[numActive2[j]][numGapOpens1[i]],
+                           newRowInsertY[j-1] + continuingPenalty2[numActive2[j]],
+                           'M', 'X', 'Y', &newRowInsertY[j], tracebackPtr++);
+      }
+
+      // swap rows
+      float *temp;
+      temp = oldRowMatch; oldRowMatch = newRowMatch; newRowMatch = temp;
+      temp = oldRowInsertX; oldRowInsertX = newRowInsertX; newRowInsertX = temp;
+      temp = oldRowInsertY; oldRowInsertY = newRowInsertY; newRowInsertY = temp;
+    }
+
+    // store best score
+    float total;
+    char matrix;
+    ChooseBestOfThree (oldRowMatch[seq2Length], oldRowInsertX[seq2Length], oldRowInsertY[seq2Length],
+                       'M', 'X', 'Y', &total, &matrix);
+
+    delete [] twoRows;
+
+    // compute traceback
+    SafeVector<char> *alignment = new SafeVector<char>; assert (alignment);
+    int r = seq1Length, c = seq2Length;
+    while (r != 0 || c != 0){
+
+      int offset = (matrix == 'M') ? 0 : (matrix == 'X') ? 1 : 2;
+      char ch = tracebackMatrix[(r*(seq2Length+1) + c) * 3 + offset];
+      switch (matrix){
+      case 'Y': c--; alignment->push_back ('Y'); break;
+      case 'X': r--; alignment->push_back ('X'); break;
+      case 'M': c--; r--; alignment->push_back ('B'); break;
+      default: assert (false);
+      }
+      matrix = ch;
+    }
+
+    delete [] tracebackMatrix;
+
+    reverse (alignment->begin(), alignment->end());
+
+    return make_pair(alignment, 1.0f);
+  }
+
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::ComputeViterbiAlignment()
+  //
+  // Computes the highest probability pairwise alignment using the
+  // probabilistic model.  The final alignment is returned as a
+  //  pair consisting of:
+  //    (1) a string (e.g., XXXBBXXXBBBBBBYYYYBBB) where X's and
+  //        denote insertions in one of the two sequences and
+  //        B's denote that both sequences are present (i.e.
+  //        matches).
+  //    (2) a float containing the log probability of the best
+  //        alignment (not used)
+  /////////////////////////////////////////////////////////////////
+
+  pair<SafeVector<char> *, float> ComputeViterbiAlignment (Sequence *seq1, Sequence *seq2) const {
+    
+    assert (seq1);
+    assert (seq2);
+    
+    const int seq1Length = seq1->GetLength();
+    const int seq2Length = seq2->GetLength();
+    
+    // retrieve the points to the beginning of each sequence
+    SafeVector<char>::iterator iter1 = seq1->GetDataPtr();
+    SafeVector<char>::iterator iter2 = seq2->GetDataPtr();
+    
+    // create viterbi matrix
+    VF *viterbiPtr = new VF (NumMatrixTypes * (seq1Length+1) * (seq2Length+1), LOG_ZERO);
+    assert (viterbiPtr);
+    VF &viterbi = *viterbiPtr;
+
+    // create traceback matrix
+    VI *tracebackPtr = new VI (NumMatrixTypes * (seq1Length+1) * (seq2Length+1), -1);
+    assert (tracebackPtr);
+    VI &traceback = *tracebackPtr;
+
+    // initialization condition
+    for (int k = 0; k < NumMatrixTypes; k++)
+      viterbi[k] = initialDistribution[k];
+
+    // remember offset for each index combination
+    int ij = 0;
+    int i1j = -seq2Length - 1;
+    int ij1 = -1;
+    int i1j1 = -seq2Length - 2;
+
+    ij *= NumMatrixTypes;
+    i1j *= NumMatrixTypes;
+    ij1 *= NumMatrixTypes;
+    i1j1 *= NumMatrixTypes;
+
+    // compute viterbi scores
+    for (int i = 0; i <= seq1Length; i++){
+      unsigned char c1 = (i == 0) ? '~' : (unsigned char) iter1[i];
+      for (int j = 0; j <= seq2Length; j++){
+        unsigned char c2 = (j == 0) ? '~' : (unsigned char) iter2[j];
+
+        if (i > 0 && j > 0){
+          for (int k = 0; k < NumMatrixTypes; k++){
+           float newVal = viterbi[k + i1j1] + transProb[k][0] + matchProb[c1][c2];
+           if (viterbi[0 + ij] < newVal){
+             viterbi[0 + ij] = newVal;
+             traceback[0 + ij] = k;
+           }
+         }
+        }
+        if (i > 0){
+          for (int k = 0; k < NumInsertStates; k++){
+           float valFromMatch = insProb[c1][k] + viterbi[0 + i1j] + transProb[0][2*k+1];
+           float valFromIns = insProb[c1][k] + viterbi[2*k+1 + i1j] + transProb[2*k+1][2*k+1];
+           if (valFromMatch >= valFromIns){
+             viterbi[2*k+1 + ij] = valFromMatch;
+             traceback[2*k+1 + ij] = 0;
+           }
+           else {
+             viterbi[2*k+1 + ij] = valFromIns;
+             traceback[2*k+1 + ij] = 2*k+1;
+           }
+         }
+       }
+        if (j > 0){
+          for (int k = 0; k < NumInsertStates; k++){
+           float valFromMatch = insProb[c2][k] + viterbi[0 + ij1] + transProb[0][2*k+2];
+           float valFromIns = insProb[c2][k] + viterbi[2*k+2 + ij1] + transProb[2*k+2][2*k+2];
+           if (valFromMatch >= valFromIns){
+             viterbi[2*k+2 + ij] = valFromMatch;
+             traceback[2*k+2 + ij] = 0;
+           }
+           else {
+             viterbi[2*k+2 + ij] = valFromIns;
+             traceback[2*k+2 + ij] = 2*k+2;
+           }
+         }
+        }
+
+        ij += NumMatrixTypes;
+        i1j += NumMatrixTypes;
+        ij1 += NumMatrixTypes;
+        i1j1 += NumMatrixTypes;
+      }
+    }
+
+    // figure out best terminating cell
+    float bestProb = LOG_ZERO;
+    int state = -1;
+    for (int k = 0; k < NumMatrixTypes; k++){
+      float thisProb = viterbi[k + NumMatrixTypes * ((seq1Length+1)*(seq2Length+1) - 1)] + initialDistribution[k];
+      if (bestProb < thisProb){
+       bestProb = thisProb;
+       state = k;
+      }
+    }
+    assert (state != -1);
+
+    delete viterbiPtr;
+
+    // compute traceback
+    SafeVector<char> *alignment = new SafeVector<char>; assert (alignment);
+    int r = seq1Length, c = seq2Length;
+    while (r != 0 || c != 0){
+      int newState = traceback[state + NumMatrixTypes * (r * (seq2Length+1) + c)];
+      
+      if (state == 0){ c--; r--; alignment->push_back ('B'); }
+      else if (state % 2 == 1){ r--; alignment->push_back ('X'); }
+      else { c--; alignment->push_back ('Y'); }
+      
+      state = newState;
+    }
+
+    delete tracebackPtr;
+
+    reverse (alignment->begin(), alignment->end());
+    
+    return make_pair(alignment, bestProb);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // ProbabilisticModel::BuildPosterior()
+  //
+  // Builds a posterior probability matrix needed to align a pair
+  // of alignments.  Mathematically, the returned matrix M is
+  // defined as follows:
+  //    M[i,j] =     sum          sum      f(s,t,i,j)
+  //             s in align1  t in align2
+  // where
+  //                  [  P(s[i'] <--> t[j'])
+  //                  [       if s[i'] is a letter in the ith column of align1 and
+  //                  [          t[j'] it a letter in the jth column of align2
+  //    f(s,t,i,j) =  [
+  //                  [  0    otherwise
+  //
+  /////////////////////////////////////////////////////////////////
+
+  VF *BuildPosterior (MultiSequence *align1, MultiSequence *align2,
+                      const SafeVector<SafeVector<SparseMatrix *> > &sparseMatrices,
+                     float cutoff = 0.0f) const {
+    const int seq1Length = align1->GetSequence(0)->GetLength();
+    const int seq2Length = align2->GetSequence(0)->GetLength();
+
+    VF *posteriorPtr = new VF((seq1Length+1) * (seq2Length+1), 0); assert (posteriorPtr);
+    VF &posterior = *posteriorPtr;
+    VF::iterator postPtr = posterior.begin();
+
+    // for each s in align1
+    for (int i = 0; i < align1->GetNumSequences(); i++){
+      int first = align1->GetSequence(i)->GetLabel();
+      SafeVector<int> *mapping1 = align1->GetSequence(i)->GetMapping();
+
+      // for each t in align2
+      for (int j = 0; j < align2->GetNumSequences(); j++){
+        int second = align2->GetSequence(j)->GetLabel();
+        SafeVector<int> *mapping2 = align2->GetSequence(j)->GetMapping();
+       if (first < second){
+
+         // get the associated sparse matrix
+         SparseMatrix *matrix = sparseMatrices[first][second];
+         
+         for (int ii = 1; ii <= matrix->GetSeq1Length(); ii++){
+           SafeVector<PIF>::iterator row = matrix->GetRowPtr(ii);
+           int base = (*mapping1)[ii] * (seq2Length+1);
+           int rowSize = matrix->GetRowSize(ii);
+           // add in all relevant values
+           for (int jj = 0; jj < rowSize; jj++) 
+             posterior[base + (*mapping2)[row[jj].first]] += row[jj].second;
+
+           // subtract cutoff 
+           for (int jj = 0; jj < matrix->GetSeq2Length(); jj++) {
+             posterior[base + (*mapping2)[jj]] -= cutoff;
+           }
+
+         }
+
+       } else {
+         // get the associated sparse matrix
+         SparseMatrix *matrix = sparseMatrices[second][first];
+         
+         for (int jj = 1; jj <= matrix->GetSeq1Length(); jj++){
+           SafeVector<PIF>::iterator row = matrix->GetRowPtr(jj);
+           int base = (*mapping2)[jj];
+           int rowSize = matrix->GetRowSize(jj);
+           
+           // add in all relevant values
+           for (int ii = 0; ii < rowSize; ii++)
+             posterior[base + (*mapping1)[row[ii].first] * (seq2Length + 1)] += row[ii].second;
+           
+           // subtract cutoff 
+           for (int ii = 0; ii < matrix->GetSeq2Length(); ii++)
+             posterior[base + (*mapping1)[ii] * (seq2Length + 1)] -= cutoff;
+         }
+
+       }
+       
+
+        delete mapping2;
+      }
+
+      delete mapping1;
+    }
+
+    return posteriorPtr;
+  }
+};
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProjectPairwise.cc b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ProjectPairwise.cc
new file mode 100644 (file)
index 0000000..4696ba1
--- /dev/null
@@ -0,0 +1,71 @@
+/////////////////////////////////////////////////////////////////
+// ProjectPairwise
+//
+// Program for projecting multiple alignments to all pairwise
+// alignments.
+/////////////////////////////////////////////////////////////////
+
+#include "SafeVector.h"
+#include "MultiSequence.h"
+#include <string>
+#include <sstream>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <set>
+#include <limits>
+#include <cstdio>
+#include <cstdlib>
+#include <cerrno>
+#include <iomanip>
+
+bool compressGaps = true;
+
+/////////////////////////////////////////////////////////////////
+// main()
+//
+// Main program.
+/////////////////////////////////////////////////////////////////
+
+int main (int argc, char **argv){
+
+  // check arguments
+  if (argc < 2){
+    cerr << "Usage: project ALIGNMENT [-nocompressgaps]" << endl;
+    exit (1);
+  }
+
+  for (int i = 2; i < argc; i++){
+    if (strcmp (argv[i], "-nocompressgaps") == 0)
+      compressGaps = false;
+    else {
+      cerr << "Unrecognized option: " << argv[i] << endl;
+      exit (1);
+    }
+  }
+
+  MultiSequence *align = new MultiSequence (string (argv[1])); assert (align);
+
+  int N = align->GetNumSequences();
+  for (int i = 0; i < N; i++){
+    for (int j = i+1; j < N; j++){
+      string name = align->GetSequence(i)->GetHeader() + "-" + align->GetSequence(j)->GetHeader() + ".fasta";
+      ofstream outfile (name.c_str());
+
+      if (compressGaps){
+       set<int> s;
+       s.insert (i); s.insert (j);
+       MultiSequence *proj = align->Project (s);
+       proj->WriteMFA (outfile);
+       delete proj;
+      }
+      else {
+       align->GetSequence(i)->WriteMFA (outfile, 60);
+       align->GetSequence(j)->WriteMFA (outfile, 60);
+      }
+      outfile.close();
+    }
+  }
+
+  delete align;
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/README b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/README
new file mode 100644 (file)
index 0000000..57087e1
--- /dev/null
@@ -0,0 +1,107 @@
+
+                          PROBCONS
+                          ~~~~~~~~                          
+
+   Probabilistic consistency-based multiple sequence alignment 
+
+-----------------------------------------------------------------
+                                                             
+PROBCONS is a novel tool for generating  multiple  alignments
+of protein sequences.  Using a combination  of  probabilistic 
+modeling and consistency-based alignment techniques, PROBCONS
+has achieved the highest accuracy of all alignment methods to
+date. 
+
+PROBCONS was developed by Chuong B. Do in collaboration  with 
+Michael Brudno in the research group  of  Serafim  Batzoglou,
+Department of Computer Science, Stanford University.
+
+For more information on the algorithms, please see
+
+     Do, C.B., Brudno, M., and Batzoglou, S. (2004) PROBCONS:
+     Probabilistic Consistency-based  Multiple  Alignment  of
+     Amino Acid Sequences.  12th International Conference  on
+     Intelligent Systems for Molecular Biology.  In press.
+
+and
+
+     Do, C.B., Brudno, M., and Batzoglou, S. (2004) PROBCONS:
+     Probabilistic Consistency-based  Multiple  Alignment  of
+     Amino Acid Sequences.  The 19th National  Conference  on
+     Artificial Intelligence (AAAI-04).  In press.
+
+-----------------------------------------------------------------
+
+PROBCONS has been made  freely  available  as  PUBLIC  DOMAIN
+software and hence is not subject to copyright in the  United
+States.  This system and/or any portion of  the  source  code
+may be used, modified, or redistributed without restrictions.  
+PROBCONS is distributed WITHOUT WARRANTY, express or implied.
+The authors accept NO LEGAL LIABILITY OR  RESPONSIBILITY  for
+loss due to reliance on the program.
+   
+-----------------------------------------------------------------
+
+Version History
+
+1.0, 3/23/2004 (Chuong Do)
+   -- initial release
+
+1.01, 3/25/2004 (Chuong Do)
+   -- fixed error in training procedure
+   -- retrained default parameters for 1 and 2 pairs of insert
+      states
+
+1.02, 4/17/2004 (Chuong Do)
+   -- replaced LOG_ADD and EXP routines
+   -- added support for reading MSF format files
+   -- added two extra utilities for scoring PROBCONS alignments
+      (for benchmarking purposes)
+      -- added the "compare" program for scoring alignments
+         according to a reference alignment with respect to 
+         sum-of-pairs and column scores
+      -- added the "fixref" program for adjusting PREFAB 
+        alignments to contain all letters of the input 
+        sequences; basically the main program for PROBCONS
+         "hacked" to get the job done
+
+1.03, 5/3/2004 (Chuong Do)
+   -- added option to do all-pairs pairwise alignments instead
+      of constructing a full multiple alignment
+   -- added support for reading DIALIGN style files
+   -- enabled support for using BAliBASE annotations for scoring
+      BAliBASE alignments
+   -- several minor bug fixes thanks to Bob Edgar
+   -- added "project" program to project multiple alignment to
+      pairwise alignments
+
+1.04, 5/9/2004 (Chuong Do)
+   -- switched over to default of one-insert state pair
+   -- retrained default parameters
+   -- added annotation scores
+   -- small changes to model topology to make end gaps symmetrical
+   -- added makegnuplot utility to plot annotation scores
+
+1.05, 5/26/2004 (Chuong Do)
+   -- added cutoff filtering for posterior scores
+   -- made small corrections to recurrences for computing alignments
+   -- added CLUSTALW output support
+
+1.06, 7/13/2004 (Chuong Do)
+   -- ProbCons is now PUBLIC DOMAIN software.
+
+1.07, 8/30/2004 (Chuong Do)
+   -- Fixed CLUSTALW output for sequence names (thanks to John Calley
+      for pointing this out)
+
+1.08, 8/31/2004 (Chuong Do)
+   -- Added option for alignment order output (-a).
+
+1.09, 9/1/2004 (Chuong Do)
+   -- PROBCONS now allows input files with existing gaps -- these are
+      automatically stripped before alignment.
+
+1.10, 3/16/2005 (Chuong Do)
+   -- Reduced memory consumption by
+      -- not storing posterior matrix transposes
+      -- restricting consistency-derived posterior matrices to original posterior matrix
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SafeVector.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SafeVector.h
new file mode 100644 (file)
index 0000000..7220316
--- /dev/null
@@ -0,0 +1,56 @@
+/////////////////////////////////////////////////////////////////
+// SafeVector.h
+//
+// STL vector with array bounds checking.  To enable bounds
+// checking, #define ENABLE_CHECKS.
+/////////////////////////////////////////////////////////////////
+
+#ifndef SAFEVECTOR_H
+#define SAFEVECTOR_H
+
+#include <cassert>
+#include <vector>
+
+/////////////////////////////////////////////////////////////////
+// SafeVector
+//
+// Class derived from the STL std::vector for bounds checking.
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+template<class TYPE>
+class SafeVector : public std::vector<TYPE>{
+ public:
+
+  // miscellaneous constructors
+  SafeVector() : std::vector<TYPE>() {}
+  SafeVector (size_t size) : std::vector<TYPE>(size) {}
+  SafeVector (size_t size, const TYPE &value) : std::vector<TYPE>(size, value) {}
+  SafeVector (const SafeVector &source) : std::vector<TYPE>(source) {}
+
+#ifdef ENABLE_CHECKS
+
+  // [] array bounds checking
+  TYPE &operator[](int index){
+    assert (index >= 0 && index < (int) size());
+    return std::vector<TYPE>::operator[] ((size_t) index);
+  }
+
+  // [] const array bounds checking
+  const TYPE &operator[] (int index) const {
+    assert (index >= 0 && index < (int) size());
+    return std::vector<TYPE>::operator[] ((size_t) index) ;
+  }
+
+#endif
+
+};
+
+// some commonly used vector types
+typedef SafeVector<int> VI;
+typedef SafeVector<VI> VVI;
+typedef SafeVector<VVI> VVVI;
+typedef SafeVector<float> VF;
+typedef SafeVector<VF> VVF;
+typedef SafeVector<VVF> VVVF;
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ScoreType.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/ScoreType.h
new file mode 100644 (file)
index 0000000..186d3fd
--- /dev/null
@@ -0,0 +1,340 @@
+/////////////////////////////////////////////////////////////////
+// ScoreType.h
+//
+// Routines for doing math operations in PROBCONS.
+/////////////////////////////////////////////////////////////////
+
+#ifndef SCORETYPE_H
+#define SCORETYPE_H
+
+#include <cmath>
+#include <algorithm>
+#include <cfloat>
+
+typedef float ScoreType;
+
+const float LOG_ZERO = -2e20;
+const float LOG_ONE = 0.0;
+
+/////////////////////////////////////////////////////////////////
+// LOG()
+//
+// Compute the logarithm of x.
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOG (ScoreType x){
+  return log (x);
+}
+
+/////////////////////////////////////////////////////////////////
+// EXP()
+//
+// Computes exp(x).
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType EXP (ScoreType x){
+  //return exp(x);
+  if (x > -2){
+    if (x > -0.5){
+      if (x > 0)
+       return exp(x);
+      return (((0.03254409303190190000*x + 0.16280432765779600000)*x + 0.49929760485974900000)*x + 0.99995149601363700000)*x + 0.99999925508501600000;
+    }
+    if (x > -1)
+      return (((0.01973899026052090000*x + 0.13822379685007000000)*x + 0.48056651562365000000)*x + 0.99326940370383500000)*x + 0.99906756856399500000;
+    return (((0.00940528203591384000*x + 0.09414963667859410000)*x + 0.40825793595877300000)*x + 0.93933625499130400000)*x + 0.98369508190545300000;
+  }
+  if (x > -8){
+    if (x > -4)
+      return (((0.00217245711583303000*x + 0.03484829428350620000)*x + 0.22118199801337800000)*x + 0.67049462206469500000)*x + 0.83556950223398500000;
+    return (((0.00012398771025456900*x + 0.00349155785951272000)*x + 0.03727721426017900000)*x + 0.17974997741536900000)*x + 0.33249299994217400000;
+  }
+  if (x > -16)
+    return (((0.00000051741713416603*x + 0.00002721456879608080)*x + 0.00053418601865636800)*x + 0.00464101989351936000)*x + 0.01507447981459420000;
+  return 0;
+}
+
+/*
+/////////////////////////////////////////////////////////////////
+// LOOKUP()
+//
+// Computes log (exp (x) + 1), for 0 <= x <= 7.5.
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOOKUP (ScoreType x){
+  //return log (exp(x) + 1);
+  if (x < 2){
+    if (x < 0.5){
+      if (x < 0)
+       return log (exp(x) + 1);
+      return (((-0.00486373205785640000*x - 0.00020245408813934800)*x + 0.12504222666029800000)*x + 0.49999685320563000000)*x + 0.69314723138948900000;
+    }
+    if (x < 1)
+      return (((-0.00278634205460548000*x - 0.00458097251248546000)*x + 0.12865849880472500000)*x + 0.49862228499205200000)*x + 0.69334810088688000000;
+    return (((0.00059633755154209200*x - 0.01918996666063320000)*x + 0.15288232492093800000)*x + 0.48039958825756900000)*x + 0.69857578503189200000;
+  }
+  if (x < 8){
+    if (x < 4)
+      return (((0.00135958539181047000*x - 0.02329807659316430000)*x + 0.15885799609532100000)*x + 0.48167498563270800000)*x + 0.69276185058669200000;
+    return (((0.00011992394456683500*x - 0.00338464503306568000)*x + 0.03622746366545470000)*x + 0.82481250248383700000)*x + 0.32507892994863100000;
+  }
+  if (x < 16)
+    return (((0.00000051726300753785*x - 0.00002720671238876090)*x + 0.00053403733818413500)*x + 0.99536021775747900000)*x + 0.01507065715532010000;
+  return x;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP_SLOW()
+//
+// Computes log (exp (x) + 1).
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOOKUP_SLOW (ScoreType x){
+  return log (exp (x) + 1);
+}
+
+/////////////////////////////////////////////////////////////////
+// MAX()
+//
+// Compute max of three numbers
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType MAX (ScoreType x, ScoreType y, ScoreType z){
+  if (x >= y){
+    if (x >= z)
+      return x;
+    return z;
+  }
+  if (y >= z)
+    return y;
+  return z;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS (ScoreType &x, ScoreType y){
+  if (x < y)
+    x = (x <= LOG_ZERO) ? y : LOOKUP(y-x) + x;
+  else
+    x = (y <= LOG_ZERO) ? x : LOOKUP(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS_SLOW()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS_SLOW (ScoreType &x, ScoreType y){
+  if (x < y)
+    x = (x <= LOG_ZERO) ? y : LOOKUP_SLOW(y-x) + x;
+  else
+    x = (y <= LOG_ZERO) ? x : LOOKUP_SLOW(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add two log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline ScoreType LOG_ADD (ScoreType x, ScoreType y){
+  if (x < y) return (x <= LOG_ZERO) ? y : LOOKUP(y-x) + x;
+  return (y <= LOG_ZERO) ? x : LOOKUP(x-y) + y;
+}
+*/
+
+/*
+/////////////////////////////////////////////////////////////////
+// LOG()
+//
+// Compute the logarithm of x.
+/////////////////////////////////////////////////////////////////
+
+inline float LOG (float x){
+  return log (x);
+}
+
+/////////////////////////////////////////////////////////////////
+// EXP()
+//
+// Computes exp(x), fr -4.6 <= x <= 0.
+/////////////////////////////////////////////////////////////////
+
+inline float EXP (float x){
+  assert (x <= 0.00f);
+  if (x < EXP_UNDERFLOW_THRESHOLD) return 0.0f;
+  return (((0.006349841068584 * x + 0.080775412572352) * x + 0.397982026296272) * x + 0.95279335963787f) * x + 0.995176455837312f;
+  //return (((0.00681169825657f * x + 0.08386267698832f) * x + 0.40413983195844f) * x + 0.95656674979767f) * x + 0.99556744049130f;
+}
+*/
+
+const float EXP_UNDERFLOW_THRESHOLD = -4.6;
+const float LOG_UNDERFLOW_THRESHOLD = 7.5;
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP()
+//
+// Computes log (exp (x) + 1), for 0 <= x <= 7.5.
+/////////////////////////////////////////////////////////////////
+
+inline float LOOKUP (float x){
+  assert (x >= 0.00f);
+  assert (x <= LOG_UNDERFLOW_THRESHOLD);
+  //return ((-0.00653779113685f * x + 0.09537236626558f) * x + 0.55317574459331f) * x + 0.68672959851568f;
+  if (x <= 1.00f) return ((-0.009350833524763f * x + 0.130659527668286f) * x + 0.498799810682272f) * x + 0.693203116424741f;
+  if (x <= 2.50f) return ((-0.014532321752540f * x + 0.139942324101744f) * x + 0.495635523139337f) * x + 0.692140569840976f;
+  if (x <= 4.50f) return ((-0.004605031767994f * x + 0.063427417320019f) * x + 0.695956496475118f) * x + 0.514272634594009f;
+  assert (x <= LOG_UNDERFLOW_THRESHOLD);
+  return ((-0.000458661602210f * x + 0.009695946122598f) * x + 0.930734667215156f) * x + 0.168037164329057f;
+
+  //return (((0.00089738532761f * x - 0.01859488697982f) * x + 0.14415772028626f) * x + 0.49515490689159f) * x + 0.69311928966454f;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOOKUP_SLOW()
+//
+// Computes log (exp (x) + 1).
+/////////////////////////////////////////////////////////////////
+
+inline float LOOKUP_SLOW (float x){
+  return log (exp (x) + 1);
+}
+
+/////////////////////////////////////////////////////////////////
+// MAX()
+//
+// Compute max of three numbers
+/////////////////////////////////////////////////////////////////
+
+inline float MAX (float x, float y, float z){
+  if (x >= y){
+    if (x >= z)
+      return x;
+    return z;
+  }
+  if (y >= z)
+    return y;
+  return z;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS (float &x, float y){
+  if (x < y)
+    x = (x == LOG_ZERO || y - x >= LOG_UNDERFLOW_THRESHOLD) ? y : LOOKUP(y-x) + x;
+  else
+    x = (y == LOG_ZERO || x - y >= LOG_UNDERFLOW_THRESHOLD) ? x : LOOKUP(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_PLUS_EQUALS_SLOW()
+//
+// Add two log probabilities and store in the first argument
+/////////////////////////////////////////////////////////////////
+
+inline void LOG_PLUS_EQUALS_SLOW (float &x, float y){
+  if (x < y)
+    x = (x == LOG_ZERO) ? y : LOOKUP_SLOW(y-x) + x;
+  else
+    x = (y == LOG_ZERO) ? x : LOOKUP_SLOW(x-y) + y;
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add two log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x, float y){
+  if (x < y) return (x == LOG_ZERO || y - x >= LOG_UNDERFLOW_THRESHOLD) ? y : LOOKUP(y-x) + x;
+  return (y == LOG_ZERO || x - y >= LOG_UNDERFLOW_THRESHOLD) ? x : LOOKUP(x-y) + y;
+}
+
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add three log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3){
+  return LOG_ADD (x1, LOG_ADD (x2, x3));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add four log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, x4)));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add five log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, x5))));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add siz log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5, float x6){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, LOG_ADD (x5, x6)))));
+}
+
+/////////////////////////////////////////////////////////////////
+// LOG_ADD()
+//
+// Add seven log probabilities
+/////////////////////////////////////////////////////////////////
+
+inline float LOG_ADD (float x1, float x2, float x3, float x4, float x5, float x6, float x7){
+  return LOG_ADD (x1, LOG_ADD (x2, LOG_ADD (x3, LOG_ADD (x4, LOG_ADD (x5, LOG_ADD (x6, x7))))));
+}
+
+/////////////////////////////////////////////////////////////////
+// ChooseBestOfThree()
+//
+// Store the largest of three values x1, x2, and x3 in *x.  Also
+// if xi is the largest value, then store bi in *b.
+/////////////////////////////////////////////////////////////////
+
+inline void ChooseBestOfThree (float x1, float x2, float x3, char b1, char b2, char b3, float *x, char *b){
+  if (x1 >= x2){
+    if (x1 >= x3){
+      *x = x1;
+      *b = b1;
+      return;
+    }
+    *x = x3;
+    *b = b3;
+    return;
+  }
+  if (x2 >= x3){
+    *x = x2;
+    *b = b2;
+    return;
+  }
+  *x = x3;
+  *b = b3;
+}
+
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Sequence.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/Sequence.h
new file mode 100644 (file)
index 0000000..ffc6ead
--- /dev/null
@@ -0,0 +1,515 @@
+/////////////////////////////////////////////////////////////////
+// Sequence.h
+//
+// Class for reading/manipulating single sequence character data.
+/////////////////////////////////////////////////////////////////
+
+#ifndef __SEQUENCE_H__
+#define __SEQUENCE_H__
+
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <cctype>
+#include <cstdlib>
+#include "SafeVector.h"
+#include "FileBuffer.h"
+
+/////////////////////////////////////////////////////////////////
+// Sequence
+//
+// Class for storing sequence information.
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+class Sequence {
+
+  bool isValid;                // a boolean indicating whether the sequence data is valid or not
+  string header;               // string containing the comment line of the FASTA file
+  SafeVector<char> *data;      // pointer to character data
+  int length;                  // length of the sequence
+  int sequenceLabel;           // integer sequence label, typically to indicate the ordering of sequences
+                               //   in a Multi-FASTA file
+  int inputLabel;              // position of sequence in original input
+  float weight;
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Sequence()
+  //
+  // Default constructor.  Does nothing.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence () : isValid (false), header (""), data (NULL), length (0), sequenceLabel (0), inputLabel (0) {}
+
+ public:
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Sequence()
+  //
+  // Constructor.  Reads the sequence from a FileBuffer.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence (FileBuffer &infile, bool stripGaps = false) : isValid (false), header ("~"), data (NULL), length(0), sequenceLabel (0), inputLabel (0) {
+
+    // read until the first non-blank line
+    while (!infile.eof()){
+      infile.GetLine (header);
+      if (header.length() != 0) break;
+    }
+
+    // check to make sure that it is a correct header line
+    if (header[0] == '>'){
+
+      // if so, remove the leading ">"
+      header = header.substr (1);
+
+      // remove any leading or trailing white space in the header comment
+      while (header.length() > 0 && isspace (header[0])) header = header.substr (1);
+      while (header.length() > 0 && isspace (header[header.length() - 1])) header = header.substr(0, header.length() - 1);
+
+      // get ready to read the data[] array; note that data[0] is always '@'
+      char ch;
+      data = new SafeVector<char>; assert (data);
+      data->push_back ('@');
+
+      // get a character from the file
+      while (infile.Get(ch)){
+
+        // if we've reached a new comment line, put the character back and stop
+        if (ch == '>'){ infile.UnGet(); break; }
+
+        // skip whitespace
+        if (isspace (ch)) continue;
+
+        // substitute gap character
+        if (ch == '.') ch = '-';
+       if (stripGaps && ch == '-') continue;
+
+        // check for known characters
+        if (!((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || ch == '*' || ch == '-')){
+          cerr << "ERROR: Unknown character encountered: " << ch << endl;
+          exit (1);
+        }
+
+        // everything's ok so far, so just store this character.
+       data->push_back(ch);
+       ++length;
+      }
+
+      // sequence must contain data in order to be valid
+      isValid = length > 0;
+      if (!isValid){
+        delete data;
+        data = NULL;
+      }
+    }
+  }
+
+  
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Sequence()
+  //
+  // Constructor.  Builds a sequence from existing data.  Note
+  // that the data must use one-based indexing where data[0] should
+  // be set to '@'.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence (SafeVector<char> *data, string header, int length, int sequenceLabel, int inputLabel) :
+    isValid (data != NULL), header(header), data(data), length (length), sequenceLabel (sequenceLabel), inputLabel (inputLabel) {
+      assert (data);
+      assert ((*data)[0] == '@');
+  }
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Sequence()
+  //
+  // Destructor.  Release allocated memory.
+  /////////////////////////////////////////////////////////////////
+
+  ~Sequence (){
+    if (data){
+      assert (isValid);
+      delete data;
+      data = NULL;
+      isValid = false;
+    }
+  }
+
+    void SetWeight(float myWeight) {
+      weight = myWeight;
+  }
+  float GetWeight() const {
+      return weight;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetHeader()
+  //
+  // Return the string comment associated with this sequence.
+  /////////////////////////////////////////////////////////////////
+
+  string GetHeader () const {
+    return header;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetName()
+  //
+  // Return the first word of the string comment associated with this sequence.
+  /////////////////////////////////////////////////////////////////
+
+  string GetName () const {
+    char name[1024];
+    sscanf (header.c_str(), "%s", name);
+    return string(name);
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetDataPtr()
+  //
+  // Return the iterator to data associated with this sequence.
+  /////////////////////////////////////////////////////////////////
+
+  SafeVector<char>::iterator GetDataPtr(){
+    assert (isValid);
+    assert (data);
+    return data->begin();
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetPosition()
+  //
+  // Return the character at position i.  Recall that the character
+  // data is stored with one-based indexing.
+  /////////////////////////////////////////////////////////////////
+
+  char GetPosition (int i) const {
+    assert (isValid);
+    assert (data);
+    assert (i >= 0 && i <= length);
+    return (*data)[i];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::SetLabel()
+  //
+  // Sets the sequence label to i.
+  /////////////////////////////////////////////////////////////////
+
+  void SetLabel (int i){
+    assert (isValid);
+    sequenceLabel = i;
+    inputLabel = i;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::SetSortLabel()
+  //
+  // Sets the sequence sorting label to i.
+  /////////////////////////////////////////////////////////////////
+
+  void SetSortLabel (int i){
+    assert (isValid);
+    sequenceLabel = i;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetLabel()
+  //
+  // Retrieves the input label.
+  /////////////////////////////////////////////////////////////////
+
+  int GetLabel () const {
+    assert (isValid);
+    return inputLabel;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetSortLabel()
+  //
+  // Retrieves the sorting label.
+  /////////////////////////////////////////////////////////////////
+
+  int GetSortLabel () const {
+    assert (isValid);
+    return sequenceLabel;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Fail()
+  //
+  // Checks to see if the sequence successfully loaded.
+  /////////////////////////////////////////////////////////////////
+
+  bool Fail () const {
+    return !isValid;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Length()
+  //
+  // Returns the length of the sequence.
+  /////////////////////////////////////////////////////////////////
+
+  int GetLength () const {
+    assert (isValid);
+    assert (data);
+    return length;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::WriteMFA()
+  //
+  // Writes the sequence to outfile in MFA format.  Uses numColumns
+  // columns per line.  If useIndex is set to false, then the
+  // header is printed as normal, but if useIndex is true, then
+  // ">S###" is printed where ### represents the sequence label.
+  /////////////////////////////////////////////////////////////////
+
+  void WriteMFA (ostream &outfile, int numColumns, bool useIndex = false) const {
+    assert (isValid);
+    assert (data);
+    assert (!outfile.fail());
+
+    // print out heading
+    if (useIndex)
+      outfile << ">S" << GetLabel() << endl;
+    else
+      outfile << ">" << header << endl;
+
+    // print out character data
+    int ct = 1;
+    for (; ct <= length; ct++){
+      outfile << (*data)[ct];
+      if (ct % numColumns == 0) outfile << endl;
+    }
+    if ((ct-1) % numColumns != 0) outfile << endl;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::WriteWEB()
+  //
+  // output for web interfase based on Sequence::WriteMFA()
+  /////////////////////////////////////////////////////////////////
+
+  void WriteWEB (ostream &outfile, int numColumns, bool useIndex = false) const {
+    assert (isValid);
+    assert (data);
+    assert (!outfile.fail());
+
+    outfile << "<php ref=\"" << GetLabel() << "\">" << endl;
+    outfile << "<name>" << endl;
+    // print out heading
+    if (useIndex)
+      outfile << "S" << GetLabel() << endl;
+    else
+      outfile << "" << header << endl;
+
+    outfile << "</name>" << endl;
+
+    // print out character data
+    outfile << "<sequence>" << endl;
+    int ct = 1;
+    for (; ct <= length; ct++){
+      outfile << (*data)[ct];
+      if (ct % numColumns == 0) outfile << endl;
+    }
+    if ((ct-1) % numColumns != 0) outfile << endl;
+
+    outfile << "</sequence>" << endl;
+    outfile << "</php>" << endl;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Clone()
+  //
+  // Returns a new deep copy of the seqeuence.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence *Clone () const {
+    Sequence *ret = new Sequence();
+    assert (ret);
+
+    ret->isValid = isValid;
+    ret->header = header;
+    ret->data = new SafeVector<char>; assert (ret->data);
+    *(ret->data) = *data;
+    ret->length = length;
+    ret->sequenceLabel = sequenceLabel;
+    ret->inputLabel = inputLabel;
+    ret->weight = weight;
+
+    return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetRange()
+  //
+  // Returns a new sequence object consisting of a range of
+  // characters from the current seuquence.
+  /////////////////////////////////////////////////////////////////
+
+  Sequence *GetRange (int start, int end) const {
+    Sequence *ret = new Sequence();
+    assert (ret);
+
+    assert (start >= 1 && start <= length);
+    assert (end >= 1 && end <= length);
+    assert (start <= end);
+
+    ret->isValid = isValid;
+    ret->header = header;
+    ret->data = new SafeVector<char>; assert (ret->data);
+    ret->data->push_back ('@');
+    for (int i = start; i <= end; i++)
+      ret->data->push_back ((*data)[i]);
+    ret->length = end - start + 1;
+    ret->sequenceLabel = sequenceLabel;
+    ret->inputLabel = inputLabel;
+
+    return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::AddGaps()
+  //
+  // Given an SafeVector<char> containing the skeleton for an
+  // alignment and the identity of the current character, this
+  // routine will create a new sequence with all necesssary gaps added.
+  // For instance,
+  //    alignment = "XXXBBYYYBBYYXX"
+  //    id = 'X'
+  // will perform the transformation
+  //    "ATGCAGTCA" --> "ATGCC---GT--CA"
+  //                    (XXXBBYYYBBYYXX)
+  /////////////////////////////////////////////////////////////////
+
+  Sequence *AddGaps (SafeVector<char> *alignment, char id){
+    Sequence *ret = new Sequence();
+    assert (ret);
+
+    ret->isValid = isValid;
+    ret->header = header;
+    ret->data = new SafeVector<char>; assert (ret->data);
+    ret->length = (int) alignment->size();
+    ret->sequenceLabel = sequenceLabel;
+    ret->inputLabel = inputLabel;
+    ret->data->push_back ('@');
+
+    SafeVector<char>::iterator dataIter = data->begin() + 1;
+    for (SafeVector<char>::iterator iter = alignment->begin(); iter != alignment->end(); ++iter){
+      if (*iter == 'B' || *iter == id){
+        ret->data->push_back (*dataIter);
+        ++dataIter;
+      }
+      else
+        ret->data->push_back ('-');
+    }
+
+    return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::AddGaps()
+  //
+  // Given an SafeVector<char> containing the skeleton for an
+  // alignment and the identity of the current character, this
+  // routine will create a new sequence with all necesssary gaps added.
+  // For instance,
+  //    alignment = "XXXBBYYYBBYYXX"
+  //    id = 'X'
+  // will perform the transformation
+  //    "ATGCAGTCA" --> "ATGCC---GT--CA"
+  //                    (XXXBBYYYBBYYXX)
+  /////////////////////////////////////////////////////////////////
+  Sequence *AddGapsReverse (SafeVector<char> *alignment, char id){
+    Sequence *ret = new Sequence();
+    assert (ret);
+
+    ret->isValid = isValid;
+    ret->header = header;
+    ret->data = new SafeVector<char>; assert (ret->data);
+    ret->length = (int) alignment->size();
+    ret->sequenceLabel = sequenceLabel;
+    ret->inputLabel = inputLabel;
+    ret->data->push_back ('@');
+
+    SafeVector<char>::iterator dataIter = data->begin() + 1;
+    for (SafeVector<char>::reverse_iterator iter = alignment->rbegin(); iter != alignment->rend(); ++iter){
+      if (*iter == 'B' || *iter == id){
+        ret->data->push_back (*dataIter);
+        ++dataIter;
+      }
+      else
+        ret->data->push_back ('-');
+    }
+
+    return ret;
+  }
+
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetString()
+  //
+  // Returns the sequence as a string with gaps removed.
+  /////////////////////////////////////////////////////////////////
+
+  string GetString (){
+    string s = " ";
+    for (int i = 1; i <= length; i++){
+      if ((*data)[i] != '-') s += (*data)[i];
+    }
+    return s;
+  }
+
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetMapping()
+  //
+  // Returns a SafeVector<int> containing the indices of every
+  // character in the sequence.  For instance, if the data is
+  // "ATGCC---GT--CA", the method returns {1,2,3,4,5,9,10,13,14}.
+  /////////////////////////////////////////////////////////////////
+
+  SafeVector<int> *GetMapping () const {
+    SafeVector<int> *ret = new SafeVector<int>(1, 0);
+    for (int i = 1; i <= length; i++){
+      if ((*data)[i] != '-') ret->push_back (i);
+    }
+    return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::GetMappingNumber()
+  //
+  // Returns a SafeVector<int> containing the indices of every
+  // character in the sequence.  For instance, if the data is
+  // "ATGCC---GT--CA", the method returns {1,2,3,4,5,0,0,0,6,7,0,0,8,9}.
+  /////////////////////////////////////////////////////////////////
+  SafeVector<int> *GetMappingNumber () const {
+      SafeVector<int> *ret = new SafeVector<int>(1, 0);
+      int count = 0;
+      for(int i = 1; i <= length; i++) {
+         if((*data)[i] != '-') ret->push_back(++count);
+         else                  ret->push_back(0);
+      }
+      return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // Sequence::Highlight()
+  //
+  // Changes all positions with score >= cutoff to upper case and
+  // all positions with score < cutoff to lower case.
+  /////////////////////////////////////////////////////////////////
+
+  void Highlight (const SafeVector<float> &scores, const float cutoff){
+    for (int i = 1; i <= length; i++){
+      if (scores[i-1] >= cutoff)
+        (*data)[i] = toupper ((*data)[i]);
+      else
+        (*data)[i] = tolower ((*data)[i]);
+    }
+  }
+};
+}
+#endif // __SQUENCE_HPP__
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SparseMatrix.h b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/SparseMatrix.h
new file mode 100644 (file)
index 0000000..f722642
--- /dev/null
@@ -0,0 +1,341 @@
+/////////////////////////////////////////////////////////////////
+// SparseMatrix.h
+//
+// Sparse matrix computations
+/////////////////////////////////////////////////////////////////
+
+#ifndef SPARSEMATRIX_H
+#define SPARSEMATRIX_H
+
+#include <iostream>
+#include "SafeVector.h"
+#include "nrutil.h"
+
+using namespace std;
+
+const float POSTERIOR_CUTOFF = 0.01;         // minimum posterior probability
+                                             // value that is maintained in the
+                                             // sparse matrix representation
+
+typedef pair<int,float> PIF;                 // Sparse matrix entry type
+                                             //   first --> column
+                                             //   second --> value
+
+namespace MXSCARNA {
+struct PIF2 {        // Sparse matrix entry type
+    int i;
+    int j;
+    float prob;
+};
+}
+
+/////////////////////////////////////////////////////////////////
+// SparseMatrix
+//
+// Class for sparse matrix computations
+/////////////////////////////////////////////////////////////////
+namespace MXSCARNA {
+class SparseMatrix {
+
+  int seq1Length, seq2Length;                     // dimensions of matrix
+  VI rowSize;                                     // rowSize[i] = # of cells in row i
+  SafeVector<PIF> data;                           // data values
+  SafeVector<SafeVector<PIF>::iterator> rowPtrs;  // pointers to the beginning of each row
+
+ public:
+  SafeVector<PIF2> data2;
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::SparseMatrix()
+  //
+  // Private constructor.1
+  /////////////////////////////////////////////////////////////////
+  SparseMatrix() { }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::SparseMatrix()
+  //
+  // Constructor.  Builds a sparse matrix from a posterior matrix.
+  // Note that the expected format for the posterior matrix is as
+  // a (seq1Length+1) x (seq2Length+1) matrix where the 0th row
+  // and 0th column are ignored (they should contain all zeroes).
+  /////////////////////////////////////////////////////////////////
+
+  SparseMatrix (int seq1Length, int seq2Length, const VF &posterior) :
+    seq1Length (seq1Length), seq2Length (seq2Length) {
+
+    int numCells = 0;
+
+    assert (seq1Length > 0);
+    assert (seq2Length > 0);
+
+    // calculate memory required; count the number of cells in the
+    // posterior matrix above the threshold
+    VF::const_iterator postPtr = posterior.begin();
+    for (int i = 0; i <= seq1Length; i++){
+      for (int j = 0; j <= seq2Length; j++){
+        if (*(postPtr++) >= POSTERIOR_CUTOFF){
+          assert (i != 0 && j != 0);
+          numCells++;
+        }
+      }
+    }
+    
+    // allocate memory
+    data.resize(numCells);
+    rowSize.resize (seq1Length + 1); rowSize[0] = -1;
+    rowPtrs.resize (seq1Length + 1); rowPtrs[0] = data.end();
+
+    // build sparse matrix
+    postPtr = posterior.begin() + seq2Length + 1;           // note that we're skipping the first row here
+    SafeVector<PIF>::iterator dataPtr = data.begin();
+    for (int i = 1; i <= seq1Length; i++){
+      postPtr++;                                            // and skipping the first column of each row
+      rowPtrs[i] = dataPtr;
+      for (int j = 1; j <= seq2Length; j++){
+        if (*postPtr >= POSTERIOR_CUTOFF){
+          dataPtr->first = j;
+          dataPtr->second = *postPtr;
+          dataPtr++;
+        }
+        postPtr++;
+      }
+      rowSize[i] = dataPtr - rowPtrs[i];
+    }
+  }
+
+  //////////////////////////////////////////////////////////////////////////
+  // SparseMatrix::SetSparseMatrix()
+  // 
+  // Constructor. 
+  //////////////////////////////////////////////////////////////////////////
+  void SetSparseMatrix(int inseq1Length, int inseq2Length, const Trimat<float> &bppMat, float cutoff = 0.01) {
+      seq1Length = inseq1Length;
+      seq2Length = inseq2Length;
+
+      int numCells = 0;
+
+      assert (seq1Length > 0);
+      assert (seq2Length > 0);
+
+      data.clear();
+      rowSize.clear();
+      rowPtrs.clear();
+      for (int i = 1; i <= seq1Length; i++) {
+         for (int j = i; j <= seq2Length; j++) {
+             if (bppMat.ref(i, j) >= cutoff ) {
+                 numCells++;
+             }
+         }
+      }
+
+      // allocate memory
+      data.resize(numCells);
+      for (int i = 0; i < numCells; i++) {
+         data[i].first  = 0;
+         data[i].second = 0;
+      }
+      rowSize.resize (seq1Length + 1); rowSize[0] = -1;
+      rowPtrs.resize (seq1Length + 1); rowPtrs[0] = data.end();
+
+      SafeVector<PIF>::iterator dataPtr = data.begin();
+      for (int i = 1; i <= seq1Length; i++) {
+         rowPtrs[i] = dataPtr;
+         for (int j = i; j <= seq2Length; j++) {
+             if ( bppMat.ref(i, j) >= cutoff ) {
+                 dataPtr->first = j;
+                 dataPtr->second = bppMat.ref(i, j);
+                 dataPtr++;
+             }
+         }
+         rowSize[i] = dataPtr - rowPtrs[i];
+      }
+
+      float tmp;
+      for(int k = 1; k <= seq1Length; k++) {
+         for(int m = k, n = k; n <= k + 300 && m >= 1 && n <= seq2Length; m--, n++) {
+             if ((tmp = GetValue(m, n)) > 0) {
+                 PIF2 p;
+                 p.i    = m;
+                 p.j    = n;
+                 p.prob = tmp;
+                 data2.push_back(p);
+             }
+         }
+    
+         for(int m = k, n = k + 1; n <= k + 300 && m >= 1 && n <= seq2Length; m--, n++) {
+             if ((tmp = GetValue(m, n)) > 0) {
+                 PIF2 p;
+                 p.i    = m;
+                 p.j    = n;
+                 p.prob = tmp;
+                 data2.push_back(p);
+             }
+         }
+      }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetRowPtr()
+  //
+  // Returns the pointer to a particular row in the sparse matrix.
+  /////////////////////////////////////////////////////////////////
+
+  SafeVector<PIF>::iterator GetRowPtr (int row) const {
+    assert (row >= 1 && row <= seq1Length);
+    return rowPtrs[row];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetValue()
+  //
+  // Returns value at a particular row, column.
+  /////////////////////////////////////////////////////////////////
+
+  float GetValue (int row, int col){
+    assert (row >= 1 && row <= seq1Length);
+    assert (col >= 1 && col <= seq2Length);
+    for (int i = 0; i < rowSize[row]; i++){
+      if (rowPtrs[row][i].first == col) return rowPtrs[row][i].second;
+    }
+    return 0;
+  }
+
+  void SetValue(int row, int col, float value) {
+    assert (row >= 1 && row <= seq1Length);
+    assert (col >= 1 && col <= seq2Length);
+    for (int i = 0; i < rowSize[row]; i++){
+      if (rowPtrs[row][i].first == col) rowPtrs[row][i].second = value;
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetRowSize()
+  //
+  // Returns the number of entries in a particular row.
+  /////////////////////////////////////////////////////////////////
+
+  int GetRowSize (int row) const {
+    assert (row >= 1 && row <= seq1Length);
+    return rowSize[row];
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetSeq1Length()
+  //
+  // Returns the first dimension of the matrix.
+  /////////////////////////////////////////////////////////////////
+
+  int GetSeq1Length () const {
+    return seq1Length;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetSeq2Length()
+  //
+  // Returns the second dimension of the matrix.
+  /////////////////////////////////////////////////////////////////
+
+  int GetSeq2Length () const {
+    return seq2Length;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetRowPtr
+  //
+  // Returns the pointer to a particular row in the sparse matrix.
+  /////////////////////////////////////////////////////////////////
+
+  int GetNumCells () const {
+    return data.size();
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::Print()
+  //
+  // Prints out a sparse matrix.
+  /////////////////////////////////////////////////////////////////
+
+  void Print (ostream &outfile) const {
+    outfile << "Sparse Matrix:" << endl;
+    for (int i = 1; i <= seq1Length; i++){
+      outfile << "  " << i << ":";
+      for (int j = 0; j < rowSize[i]; j++){
+        outfile << " (" << rowPtrs[i][j].first << "," << rowPtrs[i][j].second << ")";
+      }
+      outfile << endl;
+    }
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::ComputeTranspose()
+  //
+  // Returns a new sparse matrix containing the transpose of the
+  // current matrix.
+  /////////////////////////////////////////////////////////////////
+
+  SparseMatrix *ComputeTranspose () const {
+
+    // create a new sparse matrix
+    SparseMatrix *ret = new SparseMatrix();
+    int numCells = data.size();
+
+    ret->seq1Length = seq2Length;
+    ret->seq2Length = seq1Length;
+
+    // allocate memory
+    ret->data.resize (numCells);
+    ret->rowSize.resize (seq2Length + 1); ret->rowSize[0] = -1;
+    ret->rowPtrs.resize (seq2Length + 1); ret->rowPtrs[0] = ret->data.end();
+
+    // compute row sizes
+    for (int i = 1; i <= seq2Length; i++) ret->rowSize[i] = 0;
+    for (int i = 0; i < numCells; i++)
+      ret->rowSize[data[i].first]++;
+
+    // compute row ptrs
+    for (int i = 1; i <= seq2Length; i++){
+      ret->rowPtrs[i] = (i == 1) ? ret->data.begin() : ret->rowPtrs[i-1] + ret->rowSize[i-1];
+    }
+
+    // now fill in data
+    SafeVector<SafeVector<PIF>::iterator> currPtrs = ret->rowPtrs;
+
+    for (int i = 1; i <= seq1Length; i++){
+      SafeVector<PIF>::iterator row = rowPtrs[i];
+      for (int j = 0; j < rowSize[i]; j++){
+        currPtrs[row[j].first]->first = i;
+        currPtrs[row[j].first]->second = row[j].second;
+        currPtrs[row[j].first]++;
+      }
+    }
+
+    return ret;
+  }
+
+  /////////////////////////////////////////////////////////////////
+  // SparseMatrix::GetPosterior()
+  //
+  // Return the posterior representation of the sparse matrix.
+  /////////////////////////////////////////////////////////////////
+
+  VF *GetPosterior () const {
+
+    // create a new posterior matrix
+    VF *posteriorPtr = new VF((seq1Length+1) * (seq2Length+1)); assert (posteriorPtr);
+    VF &posterior = *posteriorPtr;
+
+    // build the posterior matrix
+    for (int i = 0; i < (seq1Length+1) * (seq2Length+1); i++) posterior[i] = 0;
+    for (int i = 1; i <= seq1Length; i++){
+      VF::iterator postPtr = posterior.begin() + i * (seq2Length+1);
+      for (int j = 0; j < rowSize[i]; j++){
+        postPtr[rowPtrs[i][j].first] = rowPtrs[i][j].second;
+      }
+    }
+
+    return posteriorPtr;
+  }
+
+};
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/mlparams0 b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/mlparams0
new file mode 100644 (file)
index 0000000..43e501f
--- /dev/null
@@ -0,0 +1,11 @@
+0.96 0.02 0.02
+0.01 0.01
+0.4 0.4
+ACGUTN
+0.148724
+0.0184143 0.158392
+0.0361397 0.0275537 0.197932
+0.0238474 0.0389291 0.0244289 0.155748
+0.0238474 0.0389291 0.0244289 0.155748 0.155748
+3.75308e-05 8.15823e-05 8.24765e-05 7.43985e-05 7.43985e-05 2.63252e-05
+0.227079 0.242208 0.283932 0.246468 0.246468 0.000312465
diff --git a/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/train-script b/binaries/src/mafft/extensions/mxscarna_src/probconsRNA/train-script
new file mode 100644 (file)
index 0000000..de909da
--- /dev/null
@@ -0,0 +1,30 @@
+./probcons -p mlparams0 -t params1 ../bralibase/*
+./probcons -p params1 -t params2 ../bralibase/*
+./probcons -p params2 -t params3 ../bralibase/*
+./probcons -p params3 -t params4 ../bralibase/*
+./probcons -p params4 -t params5 ../bralibase/*
+./probcons -p params5 -t params6 ../bralibase/*
+./probcons -p params6 -t params7 ../bralibase/*
+./probcons -p params7 -t params8 ../bralibase/*
+./probcons -p params8 -t params9 ../bralibase/*
+./probcons -p params9 -t params10 ../bralibase/*
+./probcons -p params10 -t params11 ../bralibase/*
+./probcons -p params11 -t params12 ../bralibase/*
+./probcons -p params12 -t params13 ../bralibase/*
+./probcons -p params13 -t params14 ../bralibase/*
+./probcons -p params14 -t params15 ../bralibase/*
+./probcons -p params15 -t params16 ../bralibase/*
+./probcons -p params16 -t params17 ../bralibase/*
+./probcons -p params17 -t params18 ../bralibase/*
+./probcons -p params18 -t params19 ../bralibase/*
+./probcons -p params19 -t params20 ../bralibase/*
+./probcons -p params20 -t params21 ../bralibase/*
+./probcons -p params21 -t params22 ../bralibase/*
+./probcons -p params22 -t params23 ../bralibase/*
+./probcons -p params23 -t params24 ../bralibase/*
+./probcons -p params24 -t params25 ../bralibase/*
+./probcons -p params25 -t params26 ../bralibase/*
+./probcons -p params26 -t params27 ../bralibase/*
+./probcons -p params27 -t params28 ../bralibase/*
+./probcons -p params28 -t params29 ../bralibase/*
+./probcons -p params29 -t params30 ../bralibase/*
diff --git a/binaries/src/mafft/extensions/mxscarna_src/scarna.hpp b/binaries/src/mafft/extensions/mxscarna_src/scarna.hpp
new file mode 100644 (file)
index 0000000..ac58548
--- /dev/null
@@ -0,0 +1,124 @@
+
+#ifndef __SCARNA_HPP__
+#define __SCARNA_HPP__
+
+#include <iostream>
+using namespace std;
+
+#define WORDLENGTH 2        /* default word length in stem candidates (SCs) */
+
+#define THR 0.01
+
+// the parameter trained by maximazing the sps of tRNA
+//#define MULTISCORE    9.870619  //multiple score with the constant.
+//#define MULTIRIBOSUM  0.452626  //multiple ribosum_score with the constant
+//#define MULTIPENALTY  24.263776 //multiple penalty with the constatnt
+//#define MULTISTACKING 45.208927 //multiple stacking energy with the constatnt
+
+/*
+#define MULTIRIBOSUM       1
+#define MULTIPENALTY       3.1
+#define MULTISCORE         3.7
+#define MULTISTACKING      0.1
+#define MULTIDELTASCORE    9.4
+#define MULTIDELTASTACKING 8.6
+*/
+/*
+#define MULTIRIBOSUM       1
+#define MULTIPENALTY       1.1162
+#define MULTISCORE         0.53299
+#define MULTISTACKING      4.25669
+#define MULTIDELTASCORE    1.17805
+#define MULTIDELTASTACKING 4.2016
+*/
+// new CRF DATA 550 sigma 1
+
+#define MULTIRIBOSUM       1
+#define MULTIPENALTY       1.82294
+#define MULTISCORE         0.250631
+#define MULTISTACKING      2.35517
+#define MULTIDELTASCORE    1.1781
+#define MULTIDELTASTACKING 2.45417
+
+/*
+#define MULTIRIBOSUM       1
+#define MULTIPENALTY       0.478054
+#define MULTISCORE         1.36322
+#define MULTISTACKING      4.96635
+#define MULTIDELTASCORE    1.14239
+#define MULTIDELTASTACKING 7.32992
+*/
+// CRF DATA 900 sigma 1
+/*
+#define  MULTIRIBOSUM       1
+#define  MULTIPENALTY       2.28364
+#define  MULTISCORE         0.00945681
+#define  MULTISTACKING      2.25357
+#define  MULTIDELTASCORE    1.02201
+#define  MULTIDELTASTACKING 2.21293
+*/
+
+/*
+#define RNAMATCHAA    506159
+#define RNAMATCHAT    359916
+#define RNAMATCHAG    451319
+#define RNAMATCHAC    390720
+#define RNAMATCHTT    398658
+#define RNAMATCHTG    377069
+#define RNAMATCHTC    378456
+#define RNAMATCHGG    554695
+#define RNAMATCHGC    419950
+#define RNAMATCHCC    479030
+#define GAPPENALTY    190947
+#define GAPEXTENTIONPENALTY -118817
+*/
+// RIBOSUM 
+#define RNAMATCHAA    2.22
+#define RNAMATCHAT    -1.39
+#define RNAMATCHAG    -1.46
+#define RNAMATCHAC    -1.86
+#define RNAMATCHTT     1.65
+#define RNAMATCHTG    -1.74
+#define RNAMATCHTC    -1.05
+#define RNAMATCHGG     1.03
+#define RNAMATCHGC    -2.48
+#define RNAMATCHCC     1.16
+//#define GAPPENALTY     9.42   // 3default linear gap penalry in RNA sequence alignment
+//#define GAPPENALTY    9.18743
+//#define GAPPENALTY     5.00
+//#define GAPEXTENTIONPENALTY 7.15
+//#define GAPEXTENTIONPENALTY 9.62003
+
+#define GAPPENALTY 5
+#define GAPEXTENTIONPENALTY 2.5
+//#define GAPPENALTY 8.08875
+//#define GAPEXTENTIONPENALTY 3.89655
+
+#define REFINEMENTREPS 0
+#define SCSLENGTH 2
+#define BASEPROBTHRESHOLD 0.01
+#define BASEPAIRCONST 6
+#define BANDWIDTH 500
+#define USERFOLD false
+
+extern float  RNA_Match_AA;
+extern float  RNA_Match_AT;
+extern float  RNA_Match_AG;
+extern float  RNA_Match_AC;
+extern float  RNA_Match_TT;
+extern float  RNA_Match_TG;
+extern float  RNA_Match_TC;
+extern float  RNA_Match_GG;
+extern float  RNA_Match_GC;
+extern float  RNA_Match_CC;
+extern float  RNA_Gap_Penalty;
+extern float  RNA_Gap_Extension;
+
+extern int numIterativeRefinementReps;
+extern bool PostProcessAlignment;
+extern int scsLength;
+extern float BaseProbThreshold;
+extern float BasePairConst;
+
+#endif /*__SCARNA_HPP__*/
+
diff --git a/binaries/src/mafft/extensions/mxscarna_src/seq2scs.cpp b/binaries/src/mafft/extensions/mxscarna_src/seq2scs.cpp
new file mode 100644 (file)
index 0000000..24d99f7
--- /dev/null
@@ -0,0 +1,620 @@
+///////////////////////////////////////////////////////////////
+// seq2scs.cpp
+//
+// make SCS(Stem Candidate Sequence) from the profile
+//////////////////////////////////////////////////////////////
+
+#include "scarna.hpp"
+#include "SafeVector.h"
+#include "StemCandidate.hpp"
+#include "Sequence.h"
+#include "MultiSequence.h"
+#include "BPPMatrix.hpp"
+#include "nrutil.h"
+#include <vector>
+#include <algorithm>
+#include <stdio.h>
+#include <cstring>
+#include <stdio.h>
+#include <math.h>
+
+using namespace std;
+using namespace::MXSCARNA;
+
+// for alipfold
+/*
+#include "utils.h"
+#include "fold_vars.h"
+#include "fold.h"
+#include "part_func.h"
+#include "inverse.h"
+#include "RNAstruct.h"
+#include "treedist.h"
+#include "stringdist.h"
+#include "profiledist.h"
+#include "alifold.h"
+#include "aln_util.h"
+#include "dist_vars.h"
+*/
+double Stacking_Energy[36] ={
+ -0.9,-2.1,-1.7,-0.5,-0.9,-1.0,
+ -1.8,-2.9,-2.0,-1.2,-1.7,-1.9,
+ -2.3,-3.4,-2.9,-1.4,-2.1,-2.1,
+ -1.1,-2.1,-1.9,-0.4,-1.0,1.5,
+ -1.1,-2.3,-1.8,-0.8,-0.9,-1.1,
+ -0.8,-1.4,-1.2,-0.2,-0.5,-0.4 };
+
+static Trimat<float>* makeProfileBPPMatrix(MultiSequence *Sequences, SafeVector<BPPMatrix*> &BPPMatrices);
+static int countSCS(MultiSequence *Sequences, Trimat<float>* consBppMat, int BandWidth);
+static std::vector<StemCandidate>* makeProfileScs(std::vector<StemCandidate> *pscs, MultiSequence *Sequences, Trimat<float>* consBppMat, int BandWidth);
+static void printScs(std::vector<StemCandidate> *pscs);
+static std::vector<StemCandidate>* doubleScs(std::vector<StemCandidate> *pscs);
+static std::vector<StemCandidate>* findRelations(std::vector<StemCandidate> *pscs);
+static std::vector<StemCandidate>* findCorresponding(std::vector<StemCandidate>* pscs);
+static std::vector<StemCandidate>* calculateStackingEnergy(std::vector<StemCandidate>* pscs);
+
+//float alipf_fold(char **sequences, char *structure, pair_info **pi);
+
+struct SortCmp {
+    bool operator()(const StemCandidate &sc1, const StemCandidate &sc2) const {
+       if      (sc1.GetPosition() > sc2.GetPosition()) return false;
+       else if (sc1.GetPosition() < sc2.GetPosition()) return true;
+       else if (sc1.GetDistance() > sc2.GetDistance()) return false;
+       else return true;
+    }
+};
+
+
+vector<StemCandidate>*
+seq2scs(MultiSequence *Sequences, SafeVector<BPPMatrix*> &BPPMatrices, int BandWidth)
+{
+
+    Trimat<float> *consBppMat = makeProfileBPPMatrix(Sequences, BPPMatrices);
+
+    int numberScs = countSCS(Sequences, consBppMat, BandWidth);
+
+    std::vector<StemCandidate> *pscs = new std::vector<StemCandidate>(); // Profile Stem Candidate Sequence
+//    cout << "numberScs=" << numberScs << endl;
+    pscs->resize(numberScs+1);
+
+    pscs = makeProfileScs(pscs, Sequences, consBppMat, BandWidth);
+
+    pscs = doubleScs(pscs);
+
+    std::vector<StemCandidate>::iterator startIter = pscs->begin();
+    std::vector<StemCandidate>::iterator endIter   = pscs->end();
+    ++startIter;
+    std::sort(startIter, endIter, SortCmp());
+    
+//    printScs(pscs);
+    pscs = findRelations(pscs);
+
+    pscs = findCorresponding(pscs);
+
+    pscs = calculateStackingEnergy(pscs);
+
+//    findStemRelation()
+    
+//    exit(1);
+    delete consBppMat;
+
+    return pscs;
+}
+
+static Trimat<float>*
+makeProfileBPPMatrix(MultiSequence *Sequences, SafeVector<BPPMatrix*> &BPPMatrices)
+{
+    int length = Sequences->GetSequence(0)->GetLength();
+//    float thr  = BaseProbThreshold;
+    Trimat<float> *consBppMat = new Trimat<float>(length + 1);
+    fill(consBppMat->begin(), consBppMat->end(), 0);
+
+// gabage
+//    for(int i = 0; i <= length; i++) 
+//     for(int j = i; j <= length; j++) 
+//         cout << "i=" << i << " j=" << j << " " << consBppMat->ref(i,j) << endl;
+//         consBppMat->ref(i,j) = 0;
+
+
+    int number = Sequences->GetNumSequences();
+//    if( number == 1) {
+    for(int seqNum = 0; seqNum < number; seqNum++) {
+       SafeVector<int> *tmpMap = Sequences->GetSequence(seqNum)->GetMappingNumber();
+       int label = Sequences->GetSequence(seqNum)->GetLabel();
+       BPPMatrix *tmpBppMatrix = BPPMatrices[label];
+           
+       for(int i = 1; i <= length ; i++) {
+           int originI = tmpMap->at(i);
+           for(int j = i + 3; j <= length; j++) {
+               int originJ = tmpMap->at(j);
+               if(originI != 0 && originJ != 0) {
+                   float tmpProb = tmpBppMatrix->GetProb(originI, originJ);
+
+//                 if(tmpProb >= thr) {
+                       consBppMat->ref(i, j) += tmpProb;
+//                     cout << i << " " << j << " " << consBppMat->ref(i,j) << endl;
+//                 }
+               }
+           }
+       }
+    }
+
+       /* compute the mean of base pairing probability  */
+    for(int i = 1; i <= length; i++) {
+       for(int j = i + 3; j <= length; j++) {
+           consBppMat->ref(i,j) = consBppMat->ref(i,j)/(float)number;
+           //consBppMat->ref(i,j) = std::sqrt[number](consBppMat->ref(i,j));
+           //      cout << i << " " << j <<  " " << consBppMat->ref(i,j) << endl;
+       }
+    }
+
+
+/*
+    else {
+       char **Seqs;
+       Seqs = (char **) malloc(sizeof(char*) * number);
+
+       for(int i = 0; i < number; i++) {
+           Seqs[i] = (char *) malloc(sizeof(char) * (length + 1));
+           for(int j = 1; j <= length; j++) {
+               Seqs[i][j-1] = Sequences->GetSequence(i)->GetPosition(j);
+           }
+           Seqs[i][length] = '\0';
+       }
+
+       
+       char *structure = NULL;
+       pair_info *pi;
+           
+       alipf_fold(Seqs, structure, &pi, number);
+
+       for(int iter = 0; iter < length; iter++) {
+           if(pi[iter].i == 0) break;
+           consBppMat->ref(pi[iter].i, pi[iter].j) = pi[iter].p;
+       }
+
+       for(int i = 0; i < number; i++) {
+           free (Seqs[i]);
+       }
+       free (Seqs);
+       
+//     free_alifold_arrays(void);
+    }
+*/  
+
+    return consBppMat;
+}
+static int 
+countSCS(MultiSequence *Sequences, Trimat<float> *consBppMat, int BandWidth)
+{
+
+    int length = Sequences->GetSequence(0)->GetLength();
+    int Word_Length = scsLength;
+
+    int i, j, k, s;
+    int count;
+    int sum;
+
+    sum = 0;
+    for(k = 1; k <= length; k++) {
+        count = 0;
+
+        for(i = k, j = k; i >= 1 && j <= (k + BandWidth - 1) && j <= length; i--, j++) {
+           if(consBppMat->ref(i, j) >= BaseProbThreshold) {
+               count++;
+           }
+           else if(count >= Word_Length) {
+               for(s = 0; s <= count - Word_Length; s++) 
+                 sum++;
+
+               count = 0;
+           }
+           else {
+               count = 0;
+           }
+           if(consBppMat->ref(i, j) >= BaseProbThreshold && count >= Word_Length && (i == 1 || j == length || j == (k + BandWidth - 1))) {
+               for(s = 0; s <= count - Word_Length; s++) 
+                   sum++;
+
+               count = 0;
+           }
+       }
+    
+       count = 0;
+       for(i = k, j = k + 1; i >= 1 && j <= (k + BandWidth - 1) && j <= length; i--, j++) {
+           if(consBppMat->ref(i, j) >= BaseProbThreshold) {
+               count++;
+           }
+           else if(count >= Word_Length) {
+               for(s = 0; s <= count - Word_Length; s++) sum++;
+
+               count = 0;
+           }
+           else {
+               count = 0;
+           }
+
+           if(consBppMat->ref(i, j) >= BaseProbThreshold && count >= Word_Length && (i == 1 || j == length || j == (k + BandWidth - 1))) {
+               for(s = 0; s <= count - Word_Length; s++) sum++;
+
+               count = 0;
+           }
+       }
+    }
+
+    return 2 * sum;
+}
+
+static std::vector<StemCandidate>* 
+makeProfileScs(std::vector<StemCandidate> *pscs, MultiSequence *Sequences, Trimat<float>* consBppMat, int BandWidth)
+{
+
+    int length = Sequences->GetSequence(0)->GetLength();
+    int Word_Length = scsLength;
+    float Thr = BaseProbThreshold;
+    int i, j, k, s, t, m, n, l;
+    int count;
+    int sum;
+    
+    sum = 0;
+    for(k = 1; k <= length; k++) {
+        count = 0;
+        for(i = k, j = k; i >= 1 && j <= (k + BandWidth - 1) && j <= length; i--, j++) {
+            if(consBppMat->ref(i,j) >= Thr) {
+               count++;
+           }
+           else if(count >= Word_Length) {
+               for(s = 0; s <= count- Word_Length; s++) {
+                   sum++;
+                   pscs->at(sum).SetLength(Word_Length);
+                   pscs->at(sum).SetPosition(i+1+s);
+                   pscs->at(sum).SetRvposition(j-count+(count-Word_Length-s));
+                   pscs->at(sum).SetDistance((j-count+count-Word_Length-s) - (i+1+s+Word_Length));
+                   pscs->at(sum).SetNumSeq(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumSubstr(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumRvstr(Sequences->GetNumSequences());
+                   for(m = i + 1 + s, n = j - count + (count-Word_Length-s), l = j - 1 - s, t = 0; n < j-s; m++, n++, l--, t++) {
+                       for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                           Sequence *seq = Sequences->GetSequence(num);
+//                         cout << num << "; " << m << ":" << seq->GetPosition(m) << " " << n << ":" << seq->GetPosition(n) << endl;
+                           pscs->at(sum).AddSubstr(num, seq->GetPosition(m));
+                           pscs->at(sum).AddRvstr(num, seq->GetPosition(n));
+                       }
+                       //          assert(pr[iindx[m]-l] > Thr);
+//                     cout << "prob=" << consBppMat->ref(m,l) << endl;
+                       pscs->at(sum).AddScore(consBppMat->ref(m,l));
+                       pscs->at(sum).AddBaseScore(consBppMat->ref(m, l));
+                   }
+                   for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                       pscs->at(sum).AddSubstr(num, '\0'); 
+                       pscs->at(sum).AddRvstr(num, '\0');
+                   }
+               }
+               count = 0;
+           }
+           else {
+               count = 0;
+           }
+           if(consBppMat->ref(i,j) >= Thr && count >= Word_Length && (i == 1 || j == length || j == (k + BandWidth - 1))) {
+               for(s = 0; s <= count- Word_Length; s++) {
+                   sum++;
+                   pscs->at(sum).SetLength(Word_Length);
+                   pscs->at(sum).SetPosition(i+s);
+                   pscs->at(sum).SetRvposition(j-count+1+(count-Word_Length-s));
+                   pscs->at(sum).SetDistance((j-count+1+count-Word_Length-s) - (i+s+Word_Length));
+                   pscs->at(sum).SetNumSeq(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumSubstr(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumRvstr(Sequences->GetNumSequences());
+                   for(m = i + s, n = j - count + 1 + (count-Word_Length-s), l = j - s, t = 0; n <= j-s; m++, n++, l--, t++) {
+                       for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                           Sequence *seq = Sequences->GetSequence(num);
+                           pscs->at(sum).AddSubstr(num, seq->GetPosition(m));
+                           pscs->at(sum).AddRvstr(num, seq->GetPosition(n));
+                       }
+
+                       pscs->at(sum).AddScore(consBppMat->ref(m,l));
+                       pscs->at(sum).AddBaseScore(consBppMat->ref(m, l));
+                   }
+                   for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                       pscs->at(sum).AddSubstr(num, '\0'); 
+                       pscs->at(sum).AddRvstr(num, '\0');
+                   }
+               }
+               count = 0;
+           }
+       }
+       count = 0;
+       for(i = k, j = k + 1; i >= 1 && j <= (k + BandWidth - 1) && j <= length; i--, j++) {
+           if(consBppMat->ref(i,j) >= Thr) {
+               count++;
+           }
+           else if(count >= Word_Length) {
+               for(s = 0; s <= count- Word_Length; s++) {
+                   sum++;
+                   pscs->at(sum).SetLength(Word_Length);
+                   pscs->at(sum).SetPosition(i+1+s);
+                   pscs->at(sum).SetRvposition( j-count+(count-Word_Length-s));
+                   pscs->at(sum).SetDistance((j-count+count-Word_Length-s) - (i+1+s+Word_Length));
+                   pscs->at(sum).SetNumSeq(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumSubstr(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumRvstr(Sequences->GetNumSequences());
+                   for(m = i + 1 + s, n = j - count + (count-Word_Length-s), l = j - 1 - s, t = 0; n < j-s; m++, n++, l--, t++) {
+                       for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                           Sequence *seq = Sequences->GetSequence(num);
+                           pscs->at(sum).AddSubstr(num, seq->GetPosition(m));
+                           pscs->at(sum).AddRvstr(num, seq->GetPosition(n));
+                       }
+
+                       pscs->at(sum).AddScore(consBppMat->ref(m,l));
+                       pscs->at(sum).AddBaseScore(consBppMat->ref(m, l));
+                   }
+                   for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                       pscs->at(sum).AddSubstr(num, '\0'); 
+                       pscs->at(sum).AddRvstr(num, '\0');
+                   }
+               }
+               count = 0;
+           }
+           else {
+               count = 0;
+           }
+           if(consBppMat->ref(i,j) >= Thr && count >= Word_Length && (i == 1 || j == length || j == (k + BandWidth - 1))) {
+               for(s = 0; s <= count - Word_Length; s++) {
+                   sum++;
+                   pscs->at(sum).SetLength(Word_Length);
+                   pscs->at(sum).SetPosition(i+s);
+                   pscs->at(sum).SetRvposition(j-count+1+(count-Word_Length-s));
+                   pscs->at(sum).SetDistance((j-count+1+count-Word_Length-s) - (i+s+Word_Length));
+//                 pscs->at(sum).SetDistance((j-count+count-Word_Length-s) - (i+1+s+Word_Length));
+                   pscs->at(sum).SetNumSeq(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumSubstr(Sequences->GetNumSequences());
+                   pscs->at(sum).SetNumRvstr(Sequences->GetNumSequences());
+                   for(m = i + s, n = j - count + 1 + (count-Word_Length-s), l = j - s, t=0; n <= j-s; m++, n++, l--, t++) {
+                       for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                           Sequence *seq = Sequences->GetSequence(num);
+                           pscs->at(sum).AddSubstr(num, seq->GetPosition(m));
+                           pscs->at(sum).AddRvstr(num, seq->GetPosition(n));
+                       }
+
+                       pscs->at(sum).AddScore(consBppMat->ref(m,l));
+                       pscs->at(sum).AddBaseScore(consBppMat->ref(m, l));
+                   }
+                   for(int num = 0; num < Sequences->GetNumSequences(); num++) {
+                       pscs->at(sum).AddSubstr(num, '\0'); 
+                       pscs->at(sum).AddRvstr(num, '\0');
+                   }
+               }
+               count = 0;
+           }
+       }
+    }
+
+    return pscs;
+}
+
+static std::vector<StemCandidate>* 
+doubleScs(std::vector<StemCandidate> *pscs)
+{
+    int num = pscs->size()/2;
+    
+    for(int i = 1; i <= num; i++) {
+       int latter = num + i;
+       //cout << i << " " << latter << endl;
+       StemCandidate &tmpScs = pscs->at(i);
+       pscs->at(latter).SetLength(tmpScs.GetLength());
+       pscs->at(latter).SetPosition(tmpScs.GetRvposition());
+       pscs->at(latter).SetRvposition(tmpScs.GetPosition());
+       pscs->at(latter).SetDistance(-tmpScs.GetDistance());
+       pscs->at(latter).SetNumSeq(tmpScs.GetNumSeq());
+       pscs->at(latter).SetNumSubstr(tmpScs.GetNumSeq());
+       pscs->at(latter).SetNumRvstr(tmpScs.GetNumSeq());
+
+       pscs->at(latter).SetScore(tmpScs.GetScore());
+       for(int num = 0; num < tmpScs.GetNumSeq(); num++) {
+           string tmpSubstr = tmpScs.GetSubstr(num);
+           string tmpRvstr  = tmpScs.GetRvstr(num);
+
+           for(int k = 0; k < tmpScs.GetLength(); k++) {
+               pscs->at(latter).AddSubstr(num, tmpSubstr[k]);
+               pscs->at(latter).AddRvstr(num, tmpRvstr[k]);
+           }
+       }
+       for(int k = 0; k < tmpScs.GetLength(); k++) {
+           pscs->at(latter).AddBaseScore(tmpScs.GetBaseScore(k));
+       }
+    }
+    return pscs;
+}
+
+
+static void 
+printScs(std::vector<StemCandidate> *pscs)
+{
+    int num = pscs->size();
+//    std::cout << "size = " << num << endl;
+    for(int i = 1; i < num; i++) {
+        StemCandidate &sc = pscs->at(i);
+       
+       std::cout << i << "\t" << sc.GetLength() << "\t" << sc.GetPosition() << "\t" << 
+           sc.GetRvposition() << "\t" << sc.GetDistance() << "\t" << sc.GetNumSeq() << 
+           "\t" << sc.GetScore() << "\t" << sc.GetContPos() << "\t" << sc.GetBeforePos() << 
+           "\t" << sc.GetRvscnumber() << "\t" << sc.GetStacking() << "\t" << sc.GetStemStacking() << 
+           "\t" << sc.GetBaseScore(0) << "\t" << sc.GetBaseScore(1) << endl;
+       cout << "substr:" << endl;
+       for(int k = 0; k < sc.GetNumSeq(); k++) {
+           cout << k << "\t" << sc.GetSubstr(k) << "\t" << sc.GetRvstr(k) << "\t" << endl;
+       }
+       
+    }
+
+}
+
+static std::vector<StemCandidate>*
+findRelations(std::vector<StemCandidate> *pscs)
+{
+    int num = pscs->size();
+    
+    for(int i = 1; i < num; i++) {
+       int pt = i-1; 
+       StemCandidate &sc = pscs->at(i);
+       sc.SetContPos(-1);
+       while(sc.GetPosition() == pscs->at(pt).GetPosition()) { pt--; }
+       
+       while((sc.GetPosition() == pscs->at(pt).GetPosition() + 1) && (pt > 0)) {
+           if(sc.GetRvposition() == pscs->at(pt).GetRvposition() - 1) {
+               sc.SetContPos(pt);
+               break;
+           }
+           --pt;
+       }
+       while((sc.GetPosition() < pscs->at(pt).GetPosition() + pscs->at(pt).GetLength())&&(pt > 0)) { pt--; }
+       sc.SetBeforePos(pt);
+    }
+    
+    return pscs;
+}
+
+static std::vector<StemCandidate>*
+findCorresponding(std::vector<StemCandidate>* pscs)
+{
+    int num = pscs->size();
+    
+    for(int i = 1; i < num; i++) { pscs->at(i).SetRvscnumber(0); }
+    
+    for(int i = 1; i < num; i++) {
+       if(pscs->at(i).GetDistance() > 0) {
+           for(int j = i + 1; j < num; j++) {
+               if ( (pscs->at(j).GetPosition() == pscs->at(i).GetRvposition())
+                    && (pscs->at(i).GetPosition() == pscs->at(j).GetRvposition()) ) {
+                   pscs->at(i).SetRvscnumber(j);
+                   pscs->at(j).SetRvscnumber(i);
+                   break;
+               }
+           }
+       }
+       if(pscs->at(i).GetRvscnumber() == 0) {
+           std::cerr << "error in findCorresponding" << " i=" << i << endl;
+//         exit(1);
+       }
+    }
+
+    return pscs;
+}
+
+static std::vector<StemCandidate>*
+calculateStackingEnergy(std::vector<StemCandidate>* pscs)
+{
+    int num = pscs->size();
+    int wordLength = scsLength;
+
+    for(int i = 1; i < num; i++) {
+       StemCandidate &scI = pscs->at(i);
+       int j = pscs->at(i).GetContPos();
+       
+       if(j > 0) {
+
+           StemCandidate &scJ = pscs->at(j);
+           float stacking = 0;
+           int profNum =  scJ.GetNumSeq();
+           for(int k = 0; k < profNum; k++) {
+               string substr = scJ.GetSubstr(k);
+               string rvstr  = scJ.GetRvstr(k);
+               int index = 0;
+               switch(substr[wordLength - 1]) {
+                       case 'A': if(     rvstr[0]=='U' ) {index += 0;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'C': if(     rvstr[0]=='G' ) {index += 6;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'G': if(     rvstr[0]=='C'){index += 12;}
+                                 else if(rvstr[0]=='U'){index += 18;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'U': if(     rvstr[0]=='A'){index += 24;}
+                                 else if(rvstr[0]=='G'){index += 30;}
+                                 else{ index = - 1000; }
+                                 break;
+               }
+               substr = scI.GetSubstr(k);
+               rvstr  = scI.GetRvstr(k);
+               switch(substr[wordLength - 1]){
+                       case 'A': if(     rvstr[0]=='U'){index += 0;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'C': if(     rvstr[0]=='G'){index += 1;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'G': if(     rvstr[0]=='C'){index += 2;}
+                                 else if(rvstr[0]=='U'){index += 3;}
+                                 else{ index = -1000; }
+                                 break;
+                       case 'U': if(     rvstr[0]=='A'){index += 4;}
+                                 else if(rvstr[0]=='G'){index += 5;}
+                                 else{ index = -1000; }
+                                 break;
+               }
+               if(index > 0) {
+                   stacking += Stacking_Energy[index];
+               }
+           }
+           scI.SetStacking(stacking/(float)profNum);
+       }
+       else {
+           scI.SetStacking(1000);
+       }
+    }
+
+    for(int i = 1; i < num; i++) {
+       StemCandidate &sc = pscs->at(i);
+       float stemStacking = 0;
+       int profNum = sc.GetNumSeq();
+       for(int k = 0; k < profNum; k++) {
+           string substr = sc.GetSubstr(k);
+           string rvstr  = sc.GetRvstr(k);
+           for(int j = 0; j < wordLength-1; j++) {
+               int index = 0;
+
+               switch(substr[j]) {
+                   case 'A': if(   rvstr[wordLength-1-j]=='U'){index += 0;}
+                             else{ index = -1000; }
+                             break;
+                   case 'C': if(   rvstr[wordLength-1-j]=='G'){index += 6;}
+                             else{ index = -1000; }
+                             break;
+                   case 'G': if(   rvstr[wordLength-1-j]=='C'){index += 12;}
+                              else if(rvstr[wordLength-1-j]=='U'){index += 18;}
+                             else{ index = -1000; }
+                             break;
+                   case 'U': if(   rvstr[wordLength-1-j]=='A'){index += 24;}
+                             else if(rvstr[wordLength-1-j]=='G'){index += 30;}
+                             else{ index = -1000; }
+                             break;
+               }
+               switch(substr[j+1]){
+                   case 'A': if(   rvstr[wordLength-1-(j+1)]=='U'){index += 0;}
+                             else{ index = -1000; }
+                             break;
+                   case 'C': if(   rvstr[wordLength-1-(j+1)]=='G'){index += 1;}
+                             else{ index = -1000; }
+                             break;
+                   case 'G': if(     rvstr[wordLength-1-(j+1)]=='C'){index += 2;}
+                             else if(rvstr[wordLength-1-(j+1)]=='U'){index += 3;}
+                             else{ index = -1000; }
+                             break;
+                   case 'U': if(     rvstr[wordLength-1-(j+1)]=='A'){index += 4;}
+                             else if(rvstr[wordLength-1-(j+1)]=='G'){index += 5;}
+                             else{ index = -1000; }
+                             break;
+               }
+               if(index > 0) {
+                   stemStacking += Stacking_Energy[index];
+               }
+           }
+           sc.SetStemStacking(stemStacking/(float)profNum);
+       }
+    }
+    return pscs;
+}
+
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/COPYING b/binaries/src/mafft/extensions/mxscarna_src/vienna/COPYING
new file mode 100644 (file)
index 0000000..42607ac
--- /dev/null
@@ -0,0 +1,15 @@
+                        Disclaimer and Copyright
+
+The programs, library and source code of the Vienna RNA Package are free
+software. They are distributed in the hope that they will be useful
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+
+Permission is granted for research, educational, and commercial use
+and modification so long as 1) the package and any derived works are not
+redistributed for any fee, other than media costs, 2) proper credit is
+given to the authors and the Institute for Theoretical Chemistry of the 
+University of Vienna.
+
+If you want to include this software in a commercial product, please contact 
+the authors. 
\ No newline at end of file
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_const.h b/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_const.h
new file mode 100644 (file)
index 0000000..04892da
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+
+   energy constants, formerly defined in
+             energy_par.h
+
+   customized for use with RNAedit by
+   S.Kopp, IMB-Jena, Germany, Mar 1996
+   
+*/
+
+#ifndef _ENERGY_CONST_H
+#define _ENERGY_CONST_H 1
+
+#define GASCONST 1.98717  /* in [cal/K] */
+#define K0  273.15
+#define INF 1000000
+#define FORBIDDEN 9999
+#define BONUS 10000
+#define NBPAIRS 7
+#define TURN 3
+#define MAXLOOP 30
+
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_par.h b/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_par.h
new file mode 100644 (file)
index 0000000..48b2737
--- /dev/null
@@ -0,0 +1,61 @@
+/* 
+   prototypes for energy_par.c
+*/
+
+#include "energy_const.h"
+namespace MXSCARNA {
+extern double lxc37;   /* parameter for logarithmic loop
+                         energy extrapolation            */
+
+extern int stack37[NBPAIRS+1][NBPAIRS+1];
+extern int enthalpies[NBPAIRS+1][NBPAIRS+1]; /* stack enthalpies */
+extern int entropies[NBPAIRS+1][NBPAIRS+1];  /* not used anymore */
+
+extern int hairpin37[31];
+extern int bulge37[31];
+extern int internal_loop37[31];
+extern int internal2_energy;
+extern int old_mismatch_37[NBPAIRS+1][5][5];
+extern int mismatchI37[NBPAIRS+1][5][5];  /* interior loop mismatches */
+extern int mismatchH37[NBPAIRS+1][5][5];  /* same for hairpins */
+extern int mismatchM37[NBPAIRS+1][5][5];  /* same for multiloops */
+extern int mism_H[NBPAIRS+1][5][5];       /* mismatch enthalpies */
+
+extern int dangle5_37[NBPAIRS+1][5];      /* 5' dangle exterior of pair */
+extern int dangle3_37[NBPAIRS+1][5];      /* 3' dangle */
+extern int dangle3_H[NBPAIRS+1][5];       /* corresponding enthalpies */
+extern int dangle5_H[NBPAIRS+1][5];
+
+extern int int11_37[NBPAIRS+1][NBPAIRS+1][5][5]; /* 1x1 interior loops */
+extern int int11_H[NBPAIRS+1][NBPAIRS+1][5][5];
+
+extern int int21_37[NBPAIRS+1][NBPAIRS+1][5][5][5]; /* 2x1 interior loops */
+extern int int21_H[NBPAIRS+1][NBPAIRS+1][5][5][5];
+
+extern int int22_37[NBPAIRS+1][NBPAIRS+1][5][5][5][5]; /* 2x2 interior loops */
+extern int int22_H[NBPAIRS+1][NBPAIRS+1][5][5][5][5];
+
+/* constants for linearly destabilizing contributions for multi-loops
+   F = ML_closing + ML_intern*(k-1) + ML_BASE*u  */
+extern int ML_BASE37;
+extern int ML_closing37;
+extern int ML_intern37;
+
+/* Ninio-correction for asymmetric internal loops with branches n1 and n2 */
+/*    ninio_energy = min{max_ninio, |n1-n2|*F_ninio[min{4.0, n1, n2}] } */
+extern int         MAX_NINIO;                   /* maximum correction */
+extern int F_ninio37[5];
+
+/* penalty for helices terminated by AU (actually not GC) */
+extern int TerminalAU;
+/* penalty for forming bi-molecular duplex */
+extern int DuplexInit;
+/* stabilizing contribution due to special hairpins of size 4 (tetraloops) */
+extern char Tetraloops[];  /* string containing the special tetraloops */
+extern int  TETRA_ENERGY37[];  /* Bonus energy for special tetraloops */
+extern int  TETRA_ENTH37;
+extern char Triloops[];    /* string containing the special triloops */
+extern int  Triloop_E37[]; /* Bonus energy for special Triloops */  
+
+extern double Tmeasure;       /* temperature of param measurements */
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.cpp b/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.cpp
new file mode 100644 (file)
index 0000000..6834c6e
--- /dev/null
@@ -0,0 +1,11600 @@
+#include "energy_param.hpp"
+
+
+
+namespace MXSCARNA {
+const int    energy_param::INF       = 10000;
+const int    energy_param::NST       = 0;
+const int    energy_param::DEF       = -50;
+const double energy_param::lxc37     = 107.856;
+const int 
+energy_param::
+stack37[8][8] =
+/*          CG     GC     GU     UG     AU     UA  */
+{ {  INF,   INF,   INF,   INF,   INF,   INF,   INF, INF},
+  {  INF,  -240,  -330,  -210,  -140,  -210,  -210, NST}, // CG
+  {  INF,  -330,  -340,  -250,  -150,  -220,  -240, NST}, // GC
+  {  INF,  -210,  -250,   130,   -50,  -140,  -130, NST}, // GU
+  {  INF,  -140,  -150,   -50,    30,   -60,  -100, NST}, // UG
+  {  INF,  -210,  -220,  -140,   -60,  -110,   -90, NST}, // AU
+  {  INF,  -210,  -240,  -130,  -100,   -90,  -130, NST}, // UA
+  {  INF,   NST,   NST,   NST,   NST,   NST,   NST, NST}};
+
+/* enthalpies (0.01*kcal/mol at 37 C) for stacked pairs */
+/* different from mfold-2.3, which uses values from mfold-2.2 */
+const int 
+energy_param::
+enthalpies[8][8] = 
+/*          CG     GC     GU     UG     AU     UA  */
+{ {  INF,   INF,   INF,   INF,   INF,   INF,   INF, INF}, 
+  {  INF, -1060, -1340, -1210,  -560, -1050, -1040, NST},
+  {  INF, -1340, -1490, -1260,  -830, -1140, -1240, NST},
+  {  INF, -1210, -1260, -1460, -1350,  -880, -1280, NST},
+  {  INF,  -560,  -830, -1350,  -930,  -320,  -700, NST},
+  {  INF, -1050, -1140,  -880,  -320,  -940,  -680, NST},
+  {  INF, -1040, -1240, -1280,  -700,  -680,  -770, NST},
+  {  INF,   NST,   NST,   NST,   NST,   NST,   NST, NST}};
+
+/* old values are here just for comparison */
+const int energy_param::oldhairpin37[31] = { /* from ViennaRNA 1.3 */
+  INF, INF, INF, 410, 490, 440, 470, 500, 510, 520, 531,
+       542, 551, 560, 568, 575, 582, 589, 595, 601, 606,
+       611, 616, 621, 626, 630, 634, 638, 642, 646, 650};
+
+const int energy_param::hairpin37[31] = {
+  INF, INF, INF, 570, 560, 560, 540, 590, 560, 640, 650,
+       660, 670, 678, 686, 694, 701, 707, 713, 719, 725,
+       730, 735, 740, 744, 749, 753, 757, 761, 765, 769};
+
+const int energy_param::oldbulge37[31] = {
+  INF, 390, 310, 350, 420, 480, 500, 516, 531, 543, 555,
+       565, 574, 583, 591, 598, 605, 612, 618, 624, 630,
+       635, 640, 645, 649, 654, 658, 662, 666, 670, 673};
+
+const int energy_param::bulge37[31] = {
+  INF, 380, 280, 320, 360, 400, 440, 459, 470, 480, 490,
+       500, 510, 519, 527, 534, 541, 548, 554, 560, 565,
+  571, 576, 580, 585, 589, 594, 598, 602, 605, 609};
+
+const int energy_param::oldinternal_loop37[31] = {
+  INF, INF, 410, 510, 490, 530, 570, 587, 601, 614, 625,
+       635, 645, 653, 661, 669, 676, 682, 688, 694, 700,
+       705, 710, 715, 720, 724, 728, 732, 736, 740, 744};
+
+const int energy_param::internal_loop37[31] = {
+  INF, INF, 410, 510, 170, 180, 200, 220, 230, 240, 250,
+       260, 270, 278, 286, 294, 301, 307, 313, 319, 325,
+       330, 335, 340, 345, 349, 353, 357, 361, 365, 369};
+  
+/* terminal mismatches */
+/* mismatch free energies for interior loops at 37C */
+const int energy_param::mismatchI37[8][5][5] =
+{ /* @@ */
+  {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
+  { /* CG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,    0,    0, -110,    0}, /* A@  AA  AC  AG  AU */
+   {   0,    0,    0,    0,    0}, /* C@  CA  CC  CG  CU */
+   {   0, -110,    0,    0,    0}, /* G@  GA  GC  GG  GU */
+   {   0,    0,    0,    0,  -70}},/* U@  UA  UC  UG  UU */
+  { /* GC */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,    0,    0, -110,    0}, /* A@  AA  AC  AG  AU */
+   {   0,    0,    0,    0,    0}, /* C@  CA  CC  CG  CU */
+   {   0, -110,    0,    0,    0}, /* G@  GA  GC  GG  GU */
+   {   0,    0,    0,    0,  -70}},/* U@  UA  UC  UG  UU */
+  { /* GU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,   70,   70,  -40,   70}, /* A@  AA  AC  AG  AU */
+   {   0,   70,   70,   70,   70}, /* C@  CA  CC  CG  CU */
+   {   0,  -40,   70,   70,   70}, /* G@  GA  GC  GG  GU */
+   {   0,   70,   70,   70,    0}},/* U@  UA  UC  UG  UU */
+  { /* UG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,   70,   70,  -40,   70}, /* A@  AA  AC  AG  AU */
+   {   0,   70,   70,   70,   70}, /* C@  CA  CC  CG  CU */
+   {   0,  -40,   70,   70,   70}, /* G@  GA  GC  GG  GU */
+   {   0,   70,   70,   70,    0}},/* U@  UA  UC  UG  UU */
+  { /* AU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,   70,   70,  -40,   70}, /* A@  AA  AC  AG  AU */
+   {   0,   70,   70,   70,   70}, /* C@  CA  CC  CG  CU */
+   {   0,  -40,   70,   70,   70}, /* G@  GA  GC  GG  GU */
+   {   0,   70,   70,   70,    0}},/* U@  UA  UC  UG  UU */
+  { /* UA */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,   70,   70,  -40,   70}, /* A@  AA  AC  AG  AU */
+   {   0,   70,   70,   70,   70}, /* C@  CA  CC  CG  CU */
+   {   0,  -40,   70,   70,   70}, /* G@  GA  GC  GG  GU */
+   {   0,   70,   70,   70,    0}},/* U@  UA  UC  UG  UU */
+  { /* @@ */
+   { 90, 90, 90, 90, 90},{ 90, 90, 90, 90,-20},{ 90, 90, 90, 90, 90},
+   { 90,-20, 90, 90, 90},{ 90, 90, 90, 90, 20}}
+};
+
+/* mismatch free energies for hairpins at 37C */
+const int energy_param::mismatchH37[8][5][5] =
+{ /* @@ */
+  {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
+  { /* CG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { -90, -150, -150, -140, -180}, /* A@  AA  AC  AG  AU */
+   { -90, -100,  -90, -290,  -80}, /* C@  CA  CC  CG  CU */
+   { -90, -220, -200, -160, -110}, /* G@  GA  GC  GG  GU */
+   { -90, -170, -140, -180, -200}},/* U@  UA  UC  UG  UU */
+  { /* GC */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { -70, -110, -150, -130, -210}, /* A@  AA  AC  AG  AU */
+   { -70, -110,  -70, -240,  -50}, /* C@  CA  CC  CG  CU */
+   { -70, -240, -290, -140, -120}, /* G@  GA  GC  GG  GU */
+   { -70, -190, -100, -220, -150}},/* U@  UA  UC  UG  UU */
+  { /* GU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,   20,  -50,  -30,  -30}, /* A@  AA  AC  AG  AU */
+   {   0,  -10,  -20, -150,  -20}, /* C@  CA  CC  CG  CU */
+   {   0,  -90, -110,  -30,    0}, /* G@  GA  GC  GG  GU */
+   {   0,  -30,  -30,  -40, -110}},/* U@  UA  UC  UG  UU */
+  { /* UG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,  -50,  -30,  -60,  -50}, /* A@  AA  AC  AG  AU */
+   {   0,  -20,  -10, -170,    0}, /* C@  CA  CC  CG  CU */
+   {   0,  -80, -120,  -30,  -70}, /* G@  GA  GC  GG  GU */
+   {   0,  -60,  -10,  -60,  -80}},/* U@  UA  UC  UG  UU */
+  { /* AU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,  -30,  -50,  -30,  -30}, /* A@  AA  AC  AG  AU */
+   {   0,  -10,  -20, -150,  -20}, /* C@  CA  CC  CG  CU */
+   {   0, -110, -120,  -20,   20}, /* G@  GA  GC  GG  GU */
+   {   0,  -30,  -30,  -60, -110}},/* U@  UA  UC  UG  UU */
+  { /* UA */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   {   0,  -50,  -30,  -60,  -50}, /* A@  AA  AC  AG  AU */
+   {   0,  -20,  -10, -120,   -0}, /* C@  CA  CC  CG  CU */
+   {   0, -140, -120,  -70,  -20}, /* G@  GA  GC  GG  GU */
+   {   0,  -30,  -10,  -50,  -80}},/* U@  UA  UC  UG  UU */
+  { /* @@ */
+   {  0,  0,  0,  0,  0},{  0,  0,  0,  0,  0},{  0,  0,  0,  0,  0},
+   {  0,  0,  0,  0,  0},{  0,  0,  0,  0,  0}}
+};
+
+/* mismatch energies in multiloops */
+
+/* these are probably junk */
+/* mismatch enthalpies for temperature scaling */
+const int energy_param::mism_H[8][5][5] =
+{ /* no pair */
+  {{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}},
+  { /* CG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF,-1030, -950,-1030,-1030}, /* A@  AA  AC  AG  AU */
+   { DEF, -520, -450, -520, -670}, /* C@  CA  CC  CG  CU */
+   { DEF, -940, -940, -940, -940}, /* G@  GA  GC  GG  GU */
+   { DEF, -810, -740, -810, -860}},/* U@  UA  UC  UG  UU */
+  { /* GC */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF, -520, -880, -560, -880}, /* A@  AA  AC  AG  AU */
+   { DEF, -720, -310, -310, -390}, /* C@  CA  CC  CG  CU */
+   { DEF, -710, -740, -620, -740}, /* G@  GA  GC  GG  GU */
+   { DEF, -500, -500, -500, -570}},/* U@  UA  UC  UG  UU */
+  { /* GU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF, -430, -600, -600, -600}, /* A@  AA  AC  AG  AU */
+   { DEF, -260, -240, -240, -240}, /* C@  CA  CC  CG  CU */
+   { DEF, -340, -690, -690, -690}, /* G@  GA  GC  GG  GU */
+   { DEF, -330, -330, -330, -330}},/* U@  UA  UC  UG  UU */
+  { /* UG */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF, -720, -790, -960, -810}, /* A@  AA  AC  AG  AU */
+   { DEF, -480, -480, -360, -480}, /* C@  CA  CC  CG  CU */
+   { DEF, -660, -810, -920, -810}, /* G@  GA  GC  GG  GU */
+   { DEF, -550, -440, -550, -360}},/* U@  UA  UC  UG  UU */
+  { /* AU */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF, -430, -600, -600, -600}, /* A@  AA  AC  AG  AU */
+   { DEF, -260, -240, -240, -240}, /* C@  CA  CC  CG  CU */
+   { DEF, -340, -690, -690, -690}, /* G@  GA  GC  GG  GU */
+   { DEF, -330, -330, -330, -330}},/* U@  UA  UC  UG  UU */
+  { /* UA */
+   {   0,    0,    0,    0,    0}, /* @@  @A  @C  @G  @U */
+   { DEF, -400, -630, -890, -590}, /* A@  AA  AC  AG  AU */
+   { DEF, -430, -510, -200, -180}, /* C@  CA  CC  CG  CU */
+   { DEF, -380, -680, -890, -680}, /* G@  GA  GC  GG  GU */
+   { DEF, -280, -140, -280, -140}},/* U@  UA  UC  UG  UU */
+  { /* nonstandard pair */
+   {DEF,DEF,DEF,DEF,DEF},{DEF,DEF,DEF,DEF,DEF},{DEF,DEF,DEF,DEF,DEF},
+   {DEF,DEF,DEF,DEF,DEF},{DEF,DEF,DEF,DEF,DEF}}
+};
+
+/* 5' dangling ends (unpaird base stacks on first paired base) */
+const int energy_param::dangle5_37[8][5]=
+{/*   @     A     C     G     U   */
+   { INF,  INF,  INF,  INF,  INF}, /* no pair */
+   { INF,  -50,  -30,  -20,  -10}, /* CG  (stacks on C) */
+   { INF,  -20,  -30,   -0,   -0}, /* GC  (stacks on G) */
+   { INF,  -30,  -30,  -40,  -20}, /* GU */
+   { INF,  -30,  -10,  -20,  -20}, /* UG */
+   { INF,  -30,  -30,  -40,  -20}, /* AU */
+   { INF,  -30,  -10,  -20,  -20}, /* UA */
+   {   0,    0,     0,    0,   0}  /*  @ */
+};
+
+/* 3' dangling ends (unpaired base stacks on second paired base */
+const int energy_param::dangle3_37[8][5]=
+{/*   @     A     C     G     U   */
+   { INF,  INF,  INF,  INF,  INF},  /* no pair */
+   { INF, -110,  -40, -130,  -60},  /* CG  (stacks on G) */
+   { INF, -170,  -80, -170, -120},  /* GC */
+   { INF,  -70,  -10,  -70,  -10},  /* GU */
+   { INF,  -80,  -50,  -80,  -60},  /* UG */
+   { INF,  -70,  -10,  -70,  -10},  /* AU */
+   { INF,  -80,  -50,  -80,  -60},  /* UA */
+   {   0,    0,     0,    0,   0}   /*  @ */
+};
+
+/* enthalpies for temperature scaling */
+const int energy_param::dangle3_H[8][5] =
+{/*   @     A     C     G     U   */
+   { INF,  INF,  INF,  INF,  INF},  /* no pair */
+   {   0, -740, -280, -640, -360},
+   {   0, -900, -410, -860, -750},
+   {   0, -740, -240, -720, -490},
+   {   0, -490,  -90, -550, -230},
+   {   0, -570,  -70, -580, -220},
+   {   0, -490,  -90, -550, -230},
+   {   0,    0,    0,    0,   0}
+};
+
+const int energy_param::dangle5_H[8][5] =
+{/*   @     A     C     G     U   */
+   { INF,  INF,  INF,  INF,  INF},  /* no pair */
+   {   0, -240,  330,   80, -140},
+   {   0, -160,   70, -460,  -40},
+   {   0,  160,  220,   70,  310},
+   {   0, -150,  510,   10,  100},
+   {   0,  160,  220,   70,  310},
+   {   0,  -50,  690,  -60,  -60},
+   {   0,    0,    0,    0,   0}
+};
+
+
+/* constants for linearly destabilizing contributions for multi-loops
+   F = ML_closing + ML_intern*k + ML_BASE*u  */
+/* old versions erroneously used ML_intern*(k-1) */
+
+const int energy_param::ML_BASE37 = 0;
+const int energy_param::ML_closing37 = 340;
+const int energy_param::ML_intern37 =  40;
+
+
+/* Ninio-correction for asymmetric internal loops with branches n1 and n2 */
+/*    ninio_energy = min{max_ninio, |n1-n2|*F_ninio[min{4.0, n1, n2}] } */
+const int energy_param::MAX_NINIO = 300;                   /* maximum correction */
+const int energy_param::F_ninio37[5] = { 0, 40, 50, 20, 10 };      /* only F[2] used */
+
+/* stabilizing contribution due to special hairpins of size 4 (tetraloops) */
+
+const char energy_param::Tetraloops[1400] =  /* place for up to 200 tetra loops */
+  "GGGGAC "
+  "GGUGAC "
+  "CGAAAG "
+  "GGAGAC "
+  "CGCAAG "
+  "GGAAAC "
+  "CGGAAG "
+  "CUUCGG "
+  "CGUGAG "
+  "CGAAGG "
+  "CUACGG "
+  "GGCAAC "
+  "CGCGAG "
+  "UGAGAG "
+  "CGAGAG "
+  "AGAAAU "
+  "CGUAAG "
+  "CUAACG "
+  "UGAAAG "
+  "GGAAGC "
+  "GGGAAC "
+  "UGAAAA "
+  "AGCAAU "
+  "AGUAAU "
+  "CGGGAG "
+  "AGUGAU "
+  "GGCGAC "
+  "GGGAGC "
+  "GUGAAC "
+  "UGGAAA "
+;
+
+const char energy_param::Tetrastrings[30][7] = {
+    "GGGGAC",
+    "GGUGAC",
+    "CGAAAG",
+    "GGAGAC",
+    "CGCAAG",
+    "GGAAAC",
+    "CGGAAG",
+    "CUUCGG",
+    "CGUGAG",
+    "CGAAGG",
+    "CUACGG",
+    "GGCAAC",
+    "CGCGAG",
+    "UGAGAG",
+    "CGAGAG",
+    "AGAAAU",
+    "CGUAAG",
+    "CUAACG",
+    "UGAAAG",
+    "GGAAGC",
+    "GGGAAC",
+    "UGAAAA",
+    "AGCAAU",
+    "AGUAAU",
+    "CGGGAG",
+    "AGUGAU",
+    "GGCGAC",
+    "GGGAGC",
+    "GUGAAC",
+    "UGGAAA"
+};
+
+const int energy_param::TETRA_ENERGY37[200] = {
+  -300, -300, -300, -300, -300, -300, -300, -300, -300, -250, -250, -250,
+  -250, -250, -200, -200, -200, -200, -200, -150, -150, -150, -150, -150,
+  -150, -150, -150, -150, -150, -150};
+
+const int energy_param::TETRA_ENTH37   = -400;
+
+
+/* penalty for AU (or GU) terminating helix) */
+/* mismatches already contain these */
+const int energy_param::TerminalAU = 50;
+
+/* penalty for forming a bi-molecular duplex */
+const int energy_param::DuplexInit = 410;
+
+//#include "intloops.h"
+
+
+const int energy_param::int11_37[8][8][5][5] =
+{ /* noPair */ {{{0}}},
+  { /* noPair */ {{0}},
+/* CG..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110,  40,  40,  40},
+{ 110,  40,  40,  40,  40},
+{ 110,  40,  40, -140,  40},
+{ 110,  40,  40,  40,  40}
+},
+/* CG..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110,  40, -40,  40,  40},
+{ 110,  30,  50,  40,  50},
+{ 110, -10,  40, -170,  40},
+{ 110,  40,   0,  40, -30}
+},
+/* CG..GU */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* CG..UG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* CG..AU */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* CG..UA */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* CG..?? */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110}
+}
+},
+{ /* noPair */ {{0}},
+/* GC..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110,  40,  30, -10,  40},
+{ 110, -40,  50,  40,   0},
+{ 110,  40,  40, -170,  40},
+{ 110,  40,  50,  40, -30}
+},
+/* GC..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110,  80,  40,  40,  40},
+{ 110,  40,  40,  40,  40},
+{ 110,  40,  40, -210,  40},
+{ 110,  40,  40,  40, -70}
+},
+/* GC..GU */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* GC..UG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* GC..AU */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 100}
+},
+/* GC..UA */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* GC..?? */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110}
+}
+},
+{ /* noPair */ {{0}},
+/* GU..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* GU..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* GU..GU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* GU..UG */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* GU..AU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* GU..UA */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* GU..?? */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+}
+},
+{ /* noPair */ {{0}},
+/* UG..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* UG..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* UG..GU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UG..UG */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UG..AU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UG..UA */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UG..?? */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+}
+},
+{ /* noPair */ {{0}},
+/* AU..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* AU..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 100}
+},
+/* AU..GU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* AU..UG */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* AU..AU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 120}
+},
+/* AU..UA */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 150}
+},
+/* AU..?? */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+}
+},
+{ /* noPair */ {{0}},
+/* UA..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* UA..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, -100, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* UA..GU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UA..UG */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* UA..AU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 150}
+},
+/* UA..UA */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, -40, 170},
+{ 170, 170, 170, 170, 180}
+},
+/* UA..?? */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+}
+},
+{ /* noPair */ {{0}},
+/* ??..CG */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* ??..GC */
+{{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110},
+{ 110, 110, 110, 110, 110}
+},
+/* ??..GU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* ??..UG */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* ??..AU */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* ??..UA */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+},
+/* ??..?? */
+{{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170},
+{ 170, 170, 170, 170, 170}
+}
+}
+};
+
+const int energy_param::int11_H[8][8][5][5] = 
+ /* GC..GC */ 
+{ /* noPair */ {{{0}}},
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GC.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /* CG..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* CG.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /* GU..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* GU.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /* UG..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UG.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /* AU..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* AU.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /* UA..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /* UA.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}},
+ /*  @..GC */ 
+{ /* noPair */ {{0}},
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @..CG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @..GU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @..UG */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @..AU */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @..UA */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}},
+ /*  @.. @ */ 
+{ {  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0},
+{  0, 0, 0, 0, 0}}}};
+
+const int energy_param::int21_37[8][8][5][5][5] = 
+{ /* noPair */ {{{{0}}}},
+{ /* noPair */ {{{0}}},
+{
+/* CG.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 240, 220, 160, 400},{ 550, 210, 170, 160, 400},{ 550, 100,  60,  40, 400},{ 550, 400, 400, 400, 400}},
+/* CG.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 230, 220, 400, 220},{ 550, 220, 250, 400, 220},{ 550, 400, 400, 400, 400},{ 550, 250, 190, 400, 220}},
+/* CG.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 170, 400,  80, 400},{ 550, 400, 400, 400, 400},{ 550,  80, 400, 220, 400},{ 550, 400, 400, 400, 400}},
+/* CG.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 400, 400, 400, 400},{ 550, 400, 220, 400, 130},{ 550, 400, 400, 400, 400},{ 550, 400, 170, 400, 120}}
+},
+{
+/* CG.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 230, 220, 110, 400},{ 550, 210, 170, 160, 400},{ 550,  80,  60,  40, 400},{ 550, 400, 400, 400, 400}},
+/* CG.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 230, 220, 400, 220},{ 550, 220, 250, 400, 220},{ 550, 400, 400, 400, 400},{ 550, 250, 190, 400, 220}},
+/* CG.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 170, 400,  80, 400},{ 550, 400, 400, 400, 400},{ 550,  80, 400, 220, 400},{ 550, 400, 400, 400, 400}},
+/* CG.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 400, 400, 400, 400},{ 550, 400, 220, 400, 150},{ 550, 400, 400, 400, 400},{ 550, 400, 170, 400, 120}}
+},
+{
+/* CG.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* CG.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* CG.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* CG.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* CG.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* CG.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* CG.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* CG.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* CG.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* CG.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* CG.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* CG.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* CG.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* CG.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* CG.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* CG.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* CG.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* CG.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* GC.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 220, 210, 400},{ 550, 210, 170, 160, 400},{ 550, 120,  60,  40, 400},{ 550, 400, 400, 400, 400}},
+/* GC.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 230, 220, 400, 220},{ 550, 220, 250, 400, 220},{ 550, 400, 400, 400, 400},{ 550, 250, 190, 400, 220}},
+/* GC.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 170, 400,  80, 400},{ 550, 400, 400, 400, 400},{ 550,  80, 400, 220, 400},{ 550, 400, 400, 400, 400}},
+/* GC.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 400, 400, 400, 400},{ 550, 400, 220, 400, 120},{ 550, 400, 400, 400, 400},{ 550, 400, 170, 400, 120}}
+},
+{
+/* GC.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 240, 220, 160, 400},{ 550, 210, 170, 160, 400},{ 550, 100,  60,  40, 400},{ 550, 400, 400, 400, 400}},
+/* GC.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 230, 220, 400, 220},{ 550, 220, 250, 400, 220},{ 550, 400, 400, 400, 400},{ 550, 250, 190, 400, 220}},
+/* GC.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 170, 400,  80, 400},{ 550, 400, 400, 400, 400},{ 550,  80, 400, 220, 400},{ 550, 400, 400, 400, 400}},
+/* GC.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 400, 400, 400, 400},{ 550, 400, 220, 400, 130},{ 550, 400, 400, 400, 400},{ 550, 400, 170, 400, 120}}
+},
+{
+/* GC.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GC.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GC.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GC.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GC.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GC.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GC.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GC.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GC.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GC.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GC.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GC.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GC.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GC.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GC.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GC.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GC.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GC.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* GU.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GU.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GU.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GU.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GU.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* GU.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* GU.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* GU.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* GU.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* GU.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* GU.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* GU.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* GU.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* GU.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* GU.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* GU.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* GU.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* GU.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* GU.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* GU.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* GU.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* GU.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* GU.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* GU.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* GU.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* GU.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* UG.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* UG.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* UG.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* UG.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* UG.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* UG.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* UG.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* UG.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* UG.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UG.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UG.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UG.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UG.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UG.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UG.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UG.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UG.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UG.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UG.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UG.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UG.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UG.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UG.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UG.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UG.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UG.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* AU.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* AU.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* AU.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* AU.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* AU.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* AU.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* AU.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* AU.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* AU.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* AU.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* AU.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* AU.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* AU.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* AU.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* AU.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* AU.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* AU.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* AU.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* AU.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* AU.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* AU.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* AU.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* AU.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* AU.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* AU.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* AU.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* UA.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* UA.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* UA.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* UA.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* UA.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 300, 240, 480},{ 550, 290, 250, 240, 480},{ 550, 180, 140, 120, 480},{ 550, 480, 480, 480, 480}},
+/* UA.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 310, 300, 480, 300},{ 550, 300, 330, 480, 300},{ 550, 480, 480, 480, 480},{ 550, 330, 270, 480, 300}},
+/* UA.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 250, 480, 160, 480},{ 550, 480, 480, 480, 480},{ 550, 160, 480, 300, 480},{ 550, 480, 480, 480, 480}},
+/* UA.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 480, 480, 480, 480},{ 550, 480, 300, 480, 210},{ 550, 480, 480, 480, 480},{ 550, 480, 250, 480, 200}}
+},
+{
+/* UA.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UA.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UA.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UA.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UA.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UA.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UA.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UA.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UA.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UA.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UA.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UA.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UA.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 390, 370, 310, 550},{ 550, 360, 320, 310, 550},{ 550, 250, 210, 190, 550},{ 550, 550, 550, 550, 550}},
+/* UA.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 380, 370, 550, 370},{ 550, 370, 400, 550, 370},{ 550, 550, 550, 550, 550},{ 550, 400, 340, 550, 370}},
+/* UA.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 320, 550, 230, 550},{ 550, 550, 550, 550, 550},{ 550, 230, 550, 370, 550},{ 550, 550, 550, 550, 550}},
+/* UA.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 370, 550, 280},{ 550, 550, 550, 550, 550},{ 550, 550, 320, 550, 270}}
+},
+{
+/* UA.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* UA.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* ??.@..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..GC */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..CG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..UG */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..GU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..UA */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..AU */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+},
+{
+/* ??.@..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.A..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.C..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.G..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}},
+/* ??.U..?? */
+{{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550},{ 550, 550, 550, 550, 550}}
+}
+}
+};
+
+const int energy_param::int21_H[8][8][5][5][5] = 
+{ /* noPair */ {{{{0}}}},
+{ /* noPair */ {{{0}}},
+{
+/* CG.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..CG */
+{{  -50,-1029, -949,-1029,-1029},{-1079,-2058,-1978,-2058,-2058},{ -569,-1548,-1468,-1548,-1548},{ -989,-1968,-1888,-1968,-1968},{ -859,-1838,-1758,-1838,-1838}},
+/* CG.C..CG */
+{{  -50, -519, -449, -519, -669},{ -999,-1468,-1398,-1468,-1618},{ -499, -968, -898, -968,-1118},{ -989,-1458,-1388,-1458,-1608},{ -789,-1258,-1188,-1258,-1408}},
+/* CG.G..CG */
+{{  -50, -939, -939, -939, -939},{-1079,-1968,-1968,-1968,-1968},{ -569,-1458,-1458,-1458,-1458},{ -989,-1878,-1878,-1878,-1878},{ -859,-1748,-1748,-1748,-1748}},
+/* CG.U..CG */
+{{  -50, -809, -739, -809, -859},{-1079,-1838,-1768,-1838,-1888},{ -719,-1478,-1408,-1478,-1528},{ -989,-1748,-1678,-1748,-1798},{ -909,-1668,-1598,-1668,-1718}}
+},
+{
+/* CG.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..GC */
+{{  -50,-1029, -949,-1029,-1029},{ -569,-1548,-1468,-1548,-1548},{ -769,-1748,-1668,-1748,-1748},{ -759,-1738,-1658,-1738,-1738},{ -549,-1528,-1448,-1528,-1528}},
+/* CG.C..GC */
+{{  -50, -519, -449, -519, -669},{ -929,-1398,-1328,-1398,-1548},{ -359, -828, -758, -828, -978},{ -789,-1258,-1188,-1258,-1408},{ -549,-1018, -948,-1018,-1168}},
+/* CG.G..GC */
+{{  -50, -939, -939, -939, -939},{ -609,-1498,-1498,-1498,-1498},{ -359,-1248,-1248,-1248,-1248},{ -669,-1558,-1558,-1558,-1558},{ -549,-1438,-1438,-1438,-1438}},
+/* CG.U..GC */
+{{  -50, -809, -739, -809, -859},{ -929,-1688,-1618,-1688,-1738},{ -439,-1198,-1128,-1198,-1248},{ -789,-1548,-1478,-1548,-1598},{ -619,-1378,-1308,-1378,-1428}}
+},
+{
+/* CG.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..GU */
+{{  -50,-1029, -949,-1029,-1029},{ -479,-1458,-1378,-1458,-1458},{ -309,-1288,-1208,-1288,-1288},{ -389,-1368,-1288,-1368,-1368},{ -379,-1358,-1278,-1358,-1358}},
+/* CG.C..GU */
+{{  -50, -519, -449, -519, -669},{ -649,-1118,-1048,-1118,-1268},{ -289, -758, -688, -758, -908},{ -739,-1208,-1138,-1208,-1358},{ -379, -848, -778, -848, -998}},
+/* CG.G..GU */
+{{  -50, -939, -939, -939, -939},{ -649,-1538,-1538,-1538,-1538},{ -289,-1178,-1178,-1178,-1178},{ -739,-1628,-1628,-1628,-1628},{ -379,-1268,-1268,-1268,-1268}},
+/* CG.U..GU */
+{{  -50, -809, -739, -809, -859},{ -649,-1408,-1338,-1408,-1458},{ -289,-1048, -978,-1048,-1098},{ -739,-1498,-1428,-1498,-1548},{ -379,-1138,-1068,-1138,-1188}}
+},
+{
+/* CG.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..UG */
+{{  -50,-1029, -949,-1029,-1029},{ -769,-1748,-1668,-1748,-1748},{ -529,-1508,-1428,-1508,-1508},{ -709,-1688,-1608,-1688,-1688},{ -599,-1578,-1498,-1578,-1578}},
+/* CG.C..UG */
+{{  -50, -519, -449, -519, -669},{ -839,-1308,-1238,-1308,-1458},{ -529, -998, -928, -998,-1148},{ -859,-1328,-1258,-1328,-1478},{ -489, -958, -888, -958,-1108}},
+/* CG.G..UG */
+{{  -50, -939, -939, -939, -939},{-1009,-1898,-1898,-1898,-1898},{ -409,-1298,-1298,-1298,-1298},{ -969,-1858,-1858,-1858,-1858},{ -599,-1488,-1488,-1488,-1488}},
+/* CG.U..UG */
+{{  -50, -809, -739, -809, -859},{ -859,-1618,-1548,-1618,-1668},{ -529,-1288,-1218,-1288,-1338},{ -859,-1618,-1548,-1618,-1668},{ -409,-1168,-1098,-1168,-1218}}
+},
+{
+/* CG.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..AU */
+{{  -50,-1029, -949,-1029,-1029},{ -479,-1458,-1378,-1458,-1458},{ -309,-1288,-1208,-1288,-1288},{ -389,-1368,-1288,-1368,-1368},{ -379,-1358,-1278,-1358,-1358}},
+/* CG.C..AU */
+{{  -50, -519, -449, -519, -669},{ -649,-1118,-1048,-1118,-1268},{ -289, -758, -688, -758, -908},{ -739,-1208,-1138,-1208,-1358},{ -379, -848, -778, -848, -998}},
+/* CG.G..AU */
+{{  -50, -939, -939, -939, -939},{ -649,-1538,-1538,-1538,-1538},{ -289,-1178,-1178,-1178,-1178},{ -739,-1628,-1628,-1628,-1628},{ -379,-1268,-1268,-1268,-1268}},
+/* CG.U..AU */
+{{  -50, -809, -739, -809, -859},{ -649,-1408,-1338,-1408,-1458},{ -289,-1048, -978,-1048,-1098},{ -739,-1498,-1428,-1498,-1548},{ -379,-1138,-1068,-1138,-1188}}
+},
+{
+/* CG.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A..UA */
+{{  -50,-1029, -949,-1029,-1029},{ -449,-1428,-1348,-1428,-1428},{ -479,-1458,-1378,-1458,-1458},{ -429,-1408,-1328,-1408,-1408},{ -329,-1308,-1228,-1308,-1308}},
+/* CG.C..UA */
+{{  -50, -519, -449, -519, -669},{ -679,-1148,-1078,-1148,-1298},{ -559,-1028, -958,-1028,-1178},{ -729,-1198,-1128,-1198,-1348},{ -189, -658, -588, -658, -808}},
+/* CG.G..UA */
+{{  -50, -939, -939, -939, -939},{ -939,-1828,-1828,-1828,-1828},{ -249,-1138,-1138,-1138,-1138},{ -939,-1828,-1828,-1828,-1828},{ -329,-1218,-1218,-1218,-1218}},
+/* CG.U..UA */
+{{  -50, -809, -739, -809, -859},{ -639,-1398,-1328,-1398,-1448},{ -229, -988, -918, -988,-1038},{ -729,-1488,-1418,-1488,-1538},{ -190, -949, -879, -949, -999}}
+},
+{
+/* CG.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* CG.A.. @ */
+{{ -100,-1079, -999,-1079,-1079},{ -100,-1079, -999,-1079,-1079},{ -100,-1079, -999,-1079,-1079},{ -100,-1079, -999,-1079,-1079},{ -100,-1079, -999,-1079,-1079}},
+/* CG.C.. @ */
+{{ -100, -569, -499, -569, -719},{ -100, -569, -499, -569, -719},{ -100, -569, -499, -569, -719},{ -100, -569, -499, -569, -719},{ -100, -569, -499, -569, -719}},
+/* CG.G.. @ */
+{{ -100, -989, -989, -989, -989},{ -100, -989, -989, -989, -989},{ -100, -989, -989, -989, -989},{ -100, -989, -989, -989, -989},{ -100, -989, -989, -989, -989}},
+/* CG.U.. @ */
+{{ -100, -859, -789, -859, -909},{ -100, -859, -789, -859, -909},{ -100, -859, -789, -859, -909},{ -100, -859, -789, -859, -909},{ -100, -859, -789, -859, -909}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* GC.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..CG */
+{{  -50, -519, -879, -559, -879},{-1079,-1548,-1908,-1588,-1908},{ -569,-1038,-1398,-1078,-1398},{ -989,-1458,-1818,-1498,-1818},{ -859,-1328,-1688,-1368,-1688}},
+/* GC.C..CG */
+{{  -50, -719, -309, -309, -389},{ -999,-1668,-1258,-1258,-1338},{ -499,-1168, -758, -758, -838},{ -989,-1658,-1248,-1248,-1328},{ -789,-1458,-1048,-1048,-1128}},
+/* GC.G..CG */
+{{  -50, -709, -739, -619, -739},{-1079,-1738,-1768,-1648,-1768},{ -569,-1228,-1258,-1138,-1258},{ -989,-1648,-1678,-1558,-1678},{ -859,-1518,-1548,-1428,-1548}},
+/* GC.U..CG */
+{{  -50, -499, -499, -499, -569},{-1079,-1528,-1528,-1528,-1598},{ -719,-1168,-1168,-1168,-1238},{ -989,-1438,-1438,-1438,-1508},{ -909,-1358,-1358,-1358,-1428}}
+},
+{
+/* GC.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..GC */
+{{  -50, -519, -879, -559, -879},{ -569,-1038,-1398,-1078,-1398},{ -769,-1238,-1598,-1278,-1598},{ -759,-1228,-1588,-1268,-1588},{ -549,-1018,-1378,-1058,-1378}},
+/* GC.C..GC */
+{{  -50, -719, -309, -309, -389},{ -929,-1598,-1188,-1188,-1268},{ -359,-1028, -618, -618, -698},{ -789,-1458,-1048,-1048,-1128},{ -549,-1218, -808, -808, -888}},
+/* GC.G..GC */
+{{  -50, -709, -739, -619, -739},{ -609,-1268,-1298,-1178,-1298},{ -359,-1018,-1048, -928,-1048},{ -669,-1328,-1358,-1238,-1358},{ -549,-1208,-1238,-1118,-1238}},
+/* GC.U..GC */
+{{  -50, -499, -499, -499, -569},{ -929,-1378,-1378,-1378,-1448},{ -439, -888, -888, -888, -958},{ -789,-1238,-1238,-1238,-1308},{ -619,-1068,-1068,-1068,-1138}}
+},
+{
+/* GC.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..GU */
+{{  -50, -519, -879, -559, -879},{ -479, -948,-1308, -988,-1308},{ -309, -778,-1138, -818,-1138},{ -389, -858,-1218, -898,-1218},{ -379, -848,-1208, -888,-1208}},
+/* GC.C..GU */
+{{  -50, -719, -309, -309, -389},{ -649,-1318, -908, -908, -988},{ -289, -958, -548, -548, -628},{ -739,-1408, -998, -998,-1078},{ -379,-1048, -638, -638, -718}},
+/* GC.G..GU */
+{{  -50, -709, -739, -619, -739},{ -649,-1308,-1338,-1218,-1338},{ -289, -948, -978, -858, -978},{ -739,-1398,-1428,-1308,-1428},{ -379,-1038,-1068, -948,-1068}},
+/* GC.U..GU */
+{{  -50, -499, -499, -499, -569},{ -649,-1098,-1098,-1098,-1168},{ -289, -738, -738, -738, -808},{ -739,-1188,-1188,-1188,-1258},{ -379, -828, -828, -828, -898}}
+},
+{
+/* GC.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..UG */
+{{  -50, -519, -879, -559, -879},{ -769,-1238,-1598,-1278,-1598},{ -529, -998,-1358,-1038,-1358},{ -709,-1178,-1538,-1218,-1538},{ -599,-1068,-1428,-1108,-1428}},
+/* GC.C..UG */
+{{  -50, -719, -309, -309, -389},{ -839,-1508,-1098,-1098,-1178},{ -529,-1198, -788, -788, -868},{ -859,-1528,-1118,-1118,-1198},{ -489,-1158, -748, -748, -828}},
+/* GC.G..UG */
+{{  -50, -709, -739, -619, -739},{-1009,-1668,-1698,-1578,-1698},{ -409,-1068,-1098, -978,-1098},{ -969,-1628,-1658,-1538,-1658},{ -599,-1258,-1288,-1168,-1288}},
+/* GC.U..UG */
+{{  -50, -499, -499, -499, -569},{ -859,-1308,-1308,-1308,-1378},{ -529, -978, -978, -978,-1048},{ -859,-1308,-1308,-1308,-1378},{ -409, -858, -858, -858, -928}}
+},
+{
+/* GC.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..AU */
+{{  -50, -519, -879, -559, -879},{ -479, -948,-1308, -988,-1308},{ -309, -778,-1138, -818,-1138},{ -389, -858,-1218, -898,-1218},{ -379, -848,-1208, -888,-1208}},
+/* GC.C..AU */
+{{  -50, -719, -309, -309, -389},{ -649,-1318, -908, -908, -988},{ -289, -958, -548, -548, -628},{ -739,-1408, -998, -998,-1078},{ -379,-1048, -638, -638, -718}},
+/* GC.G..AU */
+{{  -50, -709, -739, -619, -739},{ -649,-1308,-1338,-1218,-1338},{ -289, -948, -978, -858, -978},{ -739,-1398,-1428,-1308,-1428},{ -379,-1038,-1068, -948,-1068}},
+/* GC.U..AU */
+{{  -50, -499, -499, -499, -569},{ -649,-1098,-1098,-1098,-1168},{ -289, -738, -738, -738, -808},{ -739,-1188,-1188,-1188,-1258},{ -379, -828, -828, -828, -898}}
+},
+{
+/* GC.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A..UA */
+{{  -50, -519, -879, -559, -879},{ -449, -918,-1278, -958,-1278},{ -479, -948,-1308, -988,-1308},{ -429, -898,-1258, -938,-1258},{ -329, -798,-1158, -838,-1158}},
+/* GC.C..UA */
+{{  -50, -719, -309, -309, -389},{ -679,-1348, -938, -938,-1018},{ -559,-1228, -818, -818, -898},{ -729,-1398, -988, -988,-1068},{ -189, -858, -448, -448, -528}},
+/* GC.G..UA */
+{{  -50, -709, -739, -619, -739},{ -939,-1598,-1628,-1508,-1628},{ -249, -908, -938, -818, -938},{ -939,-1598,-1628,-1508,-1628},{ -329, -988,-1018, -898,-1018}},
+/* GC.U..UA */
+{{  -50, -499, -499, -499, -569},{ -639,-1088,-1088,-1088,-1158},{ -229, -678, -678, -678, -748},{ -729,-1178,-1178,-1178,-1248},{ -190, -639, -639, -639, -709}}
+},
+{
+/* GC.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GC.A.. @ */
+{{ -100, -569, -929, -609, -929},{ -100, -569, -929, -609, -929},{ -100, -569, -929, -609, -929},{ -100, -569, -929, -609, -929},{ -100, -569, -929, -609, -929}},
+/* GC.C.. @ */
+{{ -100, -769, -359, -359, -439},{ -100, -769, -359, -359, -439},{ -100, -769, -359, -359, -439},{ -100, -769, -359, -359, -439},{ -100, -769, -359, -359, -439}},
+/* GC.G.. @ */
+{{ -100, -759, -789, -669, -789},{ -100, -759, -789, -669, -789},{ -100, -759, -789, -669, -789},{ -100, -759, -789, -669, -789},{ -100, -759, -789, -669, -789}},
+/* GC.U.. @ */
+{{ -100, -549, -549, -549, -619},{ -100, -549, -549, -549, -619},{ -100, -549, -549, -549, -619},{ -100, -549, -549, -549, -619},{ -100, -549, -549, -549, -619}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* GU.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..CG */
+{{  -50, -429, -599, -599, -599},{-1079,-1458,-1628,-1628,-1628},{ -569, -948,-1118,-1118,-1118},{ -989,-1368,-1538,-1538,-1538},{ -859,-1238,-1408,-1408,-1408}},
+/* GU.C..CG */
+{{  -50, -259, -239, -239, -239},{ -999,-1208,-1188,-1188,-1188},{ -499, -708, -688, -688, -688},{ -989,-1198,-1178,-1178,-1178},{ -789, -998, -978, -978, -978}},
+/* GU.G..CG */
+{{  -50, -339, -689, -689, -689},{-1079,-1368,-1718,-1718,-1718},{ -569, -858,-1208,-1208,-1208},{ -989,-1278,-1628,-1628,-1628},{ -859,-1148,-1498,-1498,-1498}},
+/* GU.U..CG */
+{{  -50, -329, -329, -329, -329},{-1079,-1358,-1358,-1358,-1358},{ -719, -998, -998, -998, -998},{ -989,-1268,-1268,-1268,-1268},{ -909,-1188,-1188,-1188,-1188}}
+},
+{
+/* GU.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..GC */
+{{  -50, -429, -599, -599, -599},{ -569, -948,-1118,-1118,-1118},{ -769,-1148,-1318,-1318,-1318},{ -759,-1138,-1308,-1308,-1308},{ -549, -928,-1098,-1098,-1098}},
+/* GU.C..GC */
+{{  -50, -259, -239, -239, -239},{ -929,-1138,-1118,-1118,-1118},{ -359, -568, -548, -548, -548},{ -789, -998, -978, -978, -978},{ -549, -758, -738, -738, -738}},
+/* GU.G..GC */
+{{  -50, -339, -689, -689, -689},{ -609, -898,-1248,-1248,-1248},{ -359, -648, -998, -998, -998},{ -669, -958,-1308,-1308,-1308},{ -549, -838,-1188,-1188,-1188}},
+/* GU.U..GC */
+{{  -50, -329, -329, -329, -329},{ -929,-1208,-1208,-1208,-1208},{ -439, -718, -718, -718, -718},{ -789,-1068,-1068,-1068,-1068},{ -619, -898, -898, -898, -898}}
+},
+{
+/* GU.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..GU */
+{{  -50, -429, -599, -599, -599},{ -479, -858,-1028,-1028,-1028},{ -309, -688, -858, -858, -858},{ -389, -768, -938, -938, -938},{ -379, -758, -928, -928, -928}},
+/* GU.C..GU */
+{{  -50, -259, -239, -239, -239},{ -649, -858, -838, -838, -838},{ -289, -498, -478, -478, -478},{ -739, -948, -928, -928, -928},{ -379, -588, -568, -568, -568}},
+/* GU.G..GU */
+{{  -50, -339, -689, -689, -689},{ -649, -938,-1288,-1288,-1288},{ -289, -578, -928, -928, -928},{ -739,-1028,-1378,-1378,-1378},{ -379, -668,-1018,-1018,-1018}},
+/* GU.U..GU */
+{{  -50, -329, -329, -329, -329},{ -649, -928, -928, -928, -928},{ -289, -568, -568, -568, -568},{ -739,-1018,-1018,-1018,-1018},{ -379, -658, -658, -658, -658}}
+},
+{
+/* GU.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..UG */
+{{  -50, -429, -599, -599, -599},{ -769,-1148,-1318,-1318,-1318},{ -529, -908,-1078,-1078,-1078},{ -709,-1088,-1258,-1258,-1258},{ -599, -978,-1148,-1148,-1148}},
+/* GU.C..UG */
+{{  -50, -259, -239, -239, -239},{ -839,-1048,-1028,-1028,-1028},{ -529, -738, -718, -718, -718},{ -859,-1068,-1048,-1048,-1048},{ -489, -698, -678, -678, -678}},
+/* GU.G..UG */
+{{  -50, -339, -689, -689, -689},{-1009,-1298,-1648,-1648,-1648},{ -409, -698,-1048,-1048,-1048},{ -969,-1258,-1608,-1608,-1608},{ -599, -888,-1238,-1238,-1238}},
+/* GU.U..UG */
+{{  -50, -329, -329, -329, -329},{ -859,-1138,-1138,-1138,-1138},{ -529, -808, -808, -808, -808},{ -859,-1138,-1138,-1138,-1138},{ -409, -688, -688, -688, -688}}
+},
+{
+/* GU.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..AU */
+{{  -50, -429, -599, -599, -599},{ -479, -858,-1028,-1028,-1028},{ -309, -688, -858, -858, -858},{ -389, -768, -938, -938, -938},{ -379, -758, -928, -928, -928}},
+/* GU.C..AU */
+{{  -50, -259, -239, -239, -239},{ -649, -858, -838, -838, -838},{ -289, -498, -478, -478, -478},{ -739, -948, -928, -928, -928},{ -379, -588, -568, -568, -568}},
+/* GU.G..AU */
+{{  -50, -339, -689, -689, -689},{ -649, -938,-1288,-1288,-1288},{ -289, -578, -928, -928, -928},{ -739,-1028,-1378,-1378,-1378},{ -379, -668,-1018,-1018,-1018}},
+/* GU.U..AU */
+{{  -50, -329, -329, -329, -329},{ -649, -928, -928, -928, -928},{ -289, -568, -568, -568, -568},{ -739,-1018,-1018,-1018,-1018},{ -379, -658, -658, -658, -658}}
+},
+{
+/* GU.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A..UA */
+{{  -50, -429, -599, -599, -599},{ -449, -828, -998, -998, -998},{ -479, -858,-1028,-1028,-1028},{ -429, -808, -978, -978, -978},{ -329, -708, -878, -878, -878}},
+/* GU.C..UA */
+{{  -50, -259, -239, -239, -239},{ -679, -888, -868, -868, -868},{ -559, -768, -748, -748, -748},{ -729, -938, -918, -918, -918},{ -189, -398, -378, -378, -378}},
+/* GU.G..UA */
+{{  -50, -339, -689, -689, -689},{ -939,-1228,-1578,-1578,-1578},{ -249, -538, -888, -888, -888},{ -939,-1228,-1578,-1578,-1578},{ -329, -618, -968, -968, -968}},
+/* GU.U..UA */
+{{  -50, -329, -329, -329, -329},{ -639, -918, -918, -918, -918},{ -229, -508, -508, -508, -508},{ -729,-1008,-1008,-1008,-1008},{ -190, -469, -469, -469, -469}}
+},
+{
+/* GU.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* GU.A.. @ */
+{{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649}},
+/* GU.C.. @ */
+{{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289}},
+/* GU.G.. @ */
+{{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739}},
+/* GU.U.. @ */
+{{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* UG.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..CG */
+{{  -50, -719, -789, -959, -809},{-1079,-1748,-1818,-1988,-1838},{ -569,-1238,-1308,-1478,-1328},{ -989,-1658,-1728,-1898,-1748},{ -859,-1528,-1598,-1768,-1618}},
+/* UG.C..CG */
+{{  -50, -479, -479, -359, -479},{ -999,-1428,-1428,-1308,-1428},{ -499, -928, -928, -808, -928},{ -989,-1418,-1418,-1298,-1418},{ -789,-1218,-1218,-1098,-1218}},
+/* UG.G..CG */
+{{  -50, -659, -809, -919, -809},{-1079,-1688,-1838,-1948,-1838},{ -569,-1178,-1328,-1438,-1328},{ -989,-1598,-1748,-1858,-1748},{ -859,-1468,-1618,-1728,-1618}},
+/* UG.U..CG */
+{{  -50, -549, -439, -549, -359},{-1079,-1578,-1468,-1578,-1388},{ -719,-1218,-1108,-1218,-1028},{ -989,-1488,-1378,-1488,-1298},{ -909,-1408,-1298,-1408,-1218}}
+},
+{
+/* UG.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..GC */
+{{  -50, -719, -789, -959, -809},{ -569,-1238,-1308,-1478,-1328},{ -769,-1438,-1508,-1678,-1528},{ -759,-1428,-1498,-1668,-1518},{ -549,-1218,-1288,-1458,-1308}},
+/* UG.C..GC */
+{{  -50, -479, -479, -359, -479},{ -929,-1358,-1358,-1238,-1358},{ -359, -788, -788, -668, -788},{ -789,-1218,-1218,-1098,-1218},{ -549, -978, -978, -858, -978}},
+/* UG.G..GC */
+{{  -50, -659, -809, -919, -809},{ -609,-1218,-1368,-1478,-1368},{ -359, -968,-1118,-1228,-1118},{ -669,-1278,-1428,-1538,-1428},{ -549,-1158,-1308,-1418,-1308}},
+/* UG.U..GC */
+{{  -50, -549, -439, -549, -359},{ -929,-1428,-1318,-1428,-1238},{ -439, -938, -828, -938, -748},{ -789,-1288,-1178,-1288,-1098},{ -619,-1118,-1008,-1118, -928}}
+},
+{
+/* UG.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..GU */
+{{  -50, -719, -789, -959, -809},{ -479,-1148,-1218,-1388,-1238},{ -309, -978,-1048,-1218,-1068},{ -389,-1058,-1128,-1298,-1148},{ -379,-1048,-1118,-1288,-1138}},
+/* UG.C..GU */
+{{  -50, -479, -479, -359, -479},{ -649,-1078,-1078, -958,-1078},{ -289, -718, -718, -598, -718},{ -739,-1168,-1168,-1048,-1168},{ -379, -808, -808, -688, -808}},
+/* UG.G..GU */
+{{  -50, -659, -809, -919, -809},{ -649,-1258,-1408,-1518,-1408},{ -289, -898,-1048,-1158,-1048},{ -739,-1348,-1498,-1608,-1498},{ -379, -988,-1138,-1248,-1138}},
+/* UG.U..GU */
+{{  -50, -549, -439, -549, -359},{ -649,-1148,-1038,-1148, -958},{ -289, -788, -678, -788, -598},{ -739,-1238,-1128,-1238,-1048},{ -379, -878, -768, -878, -688}}
+},
+{
+/* UG.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..UG */
+{{  -50, -719, -789, -959, -809},{ -769,-1438,-1508,-1678,-1528},{ -529,-1198,-1268,-1438,-1288},{ -709,-1378,-1448,-1618,-1468},{ -599,-1268,-1338,-1508,-1358}},
+/* UG.C..UG */
+{{  -50, -479, -479, -359, -479},{ -839,-1268,-1268,-1148,-1268},{ -529, -958, -958, -838, -958},{ -859,-1288,-1288,-1168,-1288},{ -489, -918, -918, -798, -918}},
+/* UG.G..UG */
+{{  -50, -659, -809, -919, -809},{-1009,-1618,-1768,-1878,-1768},{ -409,-1018,-1168,-1278,-1168},{ -969,-1578,-1728,-1838,-1728},{ -599,-1208,-1358,-1468,-1358}},
+/* UG.U..UG */
+{{  -50, -549, -439, -549, -359},{ -859,-1358,-1248,-1358,-1168},{ -529,-1028, -918,-1028, -838},{ -859,-1358,-1248,-1358,-1168},{ -409, -908, -798, -908, -718}}
+},
+{
+/* UG.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..AU */
+{{  -50, -719, -789, -959, -809},{ -479,-1148,-1218,-1388,-1238},{ -309, -978,-1048,-1218,-1068},{ -389,-1058,-1128,-1298,-1148},{ -379,-1048,-1118,-1288,-1138}},
+/* UG.C..AU */
+{{  -50, -479, -479, -359, -479},{ -649,-1078,-1078, -958,-1078},{ -289, -718, -718, -598, -718},{ -739,-1168,-1168,-1048,-1168},{ -379, -808, -808, -688, -808}},
+/* UG.G..AU */
+{{  -50, -659, -809, -919, -809},{ -649,-1258,-1408,-1518,-1408},{ -289, -898,-1048,-1158,-1048},{ -739,-1348,-1498,-1608,-1498},{ -379, -988,-1138,-1248,-1138}},
+/* UG.U..AU */
+{{  -50, -549, -439, -549, -359},{ -649,-1148,-1038,-1148, -958},{ -289, -788, -678, -788, -598},{ -739,-1238,-1128,-1238,-1048},{ -379, -878, -768, -878, -688}}
+},
+{
+/* UG.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A..UA */
+{{  -50, -719, -789, -959, -809},{ -449,-1118,-1188,-1358,-1208},{ -479,-1148,-1218,-1388,-1238},{ -429,-1098,-1168,-1338,-1188},{ -329, -998,-1068,-1238,-1088}},
+/* UG.C..UA */
+{{  -50, -479, -479, -359, -479},{ -679,-1108,-1108, -988,-1108},{ -559, -988, -988, -868, -988},{ -729,-1158,-1158,-1038,-1158},{ -189, -618, -618, -498, -618}},
+/* UG.G..UA */
+{{  -50, -659, -809, -919, -809},{ -939,-1548,-1698,-1808,-1698},{ -249, -858,-1008,-1118,-1008},{ -939,-1548,-1698,-1808,-1698},{ -329, -938,-1088,-1198,-1088}},
+/* UG.U..UA */
+{{  -50, -549, -439, -549, -359},{ -639,-1138,-1028,-1138, -948},{ -229, -728, -618, -728, -538},{ -729,-1228,-1118,-1228,-1038},{ -190, -689, -579, -689, -499}}
+},
+{
+/* UG.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UG.A.. @ */
+{{ -100, -769, -839,-1009, -859},{ -100, -769, -839,-1009, -859},{ -100, -769, -839,-1009, -859},{ -100, -769, -839,-1009, -859},{ -100, -769, -839,-1009, -859}},
+/* UG.C.. @ */
+{{ -100, -529, -529, -409, -529},{ -100, -529, -529, -409, -529},{ -100, -529, -529, -409, -529},{ -100, -529, -529, -409, -529},{ -100, -529, -529, -409, -529}},
+/* UG.G.. @ */
+{{ -100, -709, -859, -969, -859},{ -100, -709, -859, -969, -859},{ -100, -709, -859, -969, -859},{ -100, -709, -859, -969, -859},{ -100, -709, -859, -969, -859}},
+/* UG.U.. @ */
+{{ -100, -599, -489, -599, -409},{ -100, -599, -489, -599, -409},{ -100, -599, -489, -599, -409},{ -100, -599, -489, -599, -409},{ -100, -599, -489, -599, -409}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* AU.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..CG */
+{{  -50, -429, -599, -599, -599},{-1079,-1458,-1628,-1628,-1628},{ -569, -948,-1118,-1118,-1118},{ -989,-1368,-1538,-1538,-1538},{ -859,-1238,-1408,-1408,-1408}},
+/* AU.C..CG */
+{{  -50, -259, -239, -239, -239},{ -999,-1208,-1188,-1188,-1188},{ -499, -708, -688, -688, -688},{ -989,-1198,-1178,-1178,-1178},{ -789, -998, -978, -978, -978}},
+/* AU.G..CG */
+{{  -50, -339, -689, -689, -689},{-1079,-1368,-1718,-1718,-1718},{ -569, -858,-1208,-1208,-1208},{ -989,-1278,-1628,-1628,-1628},{ -859,-1148,-1498,-1498,-1498}},
+/* AU.U..CG */
+{{  -50, -329, -329, -329, -329},{-1079,-1358,-1358,-1358,-1358},{ -719, -998, -998, -998, -998},{ -989,-1268,-1268,-1268,-1268},{ -909,-1188,-1188,-1188,-1188}}
+},
+{
+/* AU.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..GC */
+{{  -50, -429, -599, -599, -599},{ -569, -948,-1118,-1118,-1118},{ -769,-1148,-1318,-1318,-1318},{ -759,-1138,-1308,-1308,-1308},{ -549, -928,-1098,-1098,-1098}},
+/* AU.C..GC */
+{{  -50, -259, -239, -239, -239},{ -929,-1138,-1118,-1118,-1118},{ -359, -568, -548, -548, -548},{ -789, -998, -978, -978, -978},{ -549, -758, -738, -738, -738}},
+/* AU.G..GC */
+{{  -50, -339, -689, -689, -689},{ -609, -898,-1248,-1248,-1248},{ -359, -648, -998, -998, -998},{ -669, -958,-1308,-1308,-1308},{ -549, -838,-1188,-1188,-1188}},
+/* AU.U..GC */
+{{  -50, -329, -329, -329, -329},{ -929,-1208,-1208,-1208,-1208},{ -439, -718, -718, -718, -718},{ -789,-1068,-1068,-1068,-1068},{ -619, -898, -898, -898, -898}}
+},
+{
+/* AU.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..GU */
+{{  -50, -429, -599, -599, -599},{ -479, -858,-1028,-1028,-1028},{ -309, -688, -858, -858, -858},{ -389, -768, -938, -938, -938},{ -379, -758, -928, -928, -928}},
+/* AU.C..GU */
+{{  -50, -259, -239, -239, -239},{ -649, -858, -838, -838, -838},{ -289, -498, -478, -478, -478},{ -739, -948, -928, -928, -928},{ -379, -588, -568, -568, -568}},
+/* AU.G..GU */
+{{  -50, -339, -689, -689, -689},{ -649, -938,-1288,-1288,-1288},{ -289, -578, -928, -928, -928},{ -739,-1028,-1378,-1378,-1378},{ -379, -668,-1018,-1018,-1018}},
+/* AU.U..GU */
+{{  -50, -329, -329, -329, -329},{ -649, -928, -928, -928, -928},{ -289, -568, -568, -568, -568},{ -739,-1018,-1018,-1018,-1018},{ -379, -658, -658, -658, -658}}
+},
+{
+/* AU.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..UG */
+{{  -50, -429, -599, -599, -599},{ -769,-1148,-1318,-1318,-1318},{ -529, -908,-1078,-1078,-1078},{ -709,-1088,-1258,-1258,-1258},{ -599, -978,-1148,-1148,-1148}},
+/* AU.C..UG */
+{{  -50, -259, -239, -239, -239},{ -839,-1048,-1028,-1028,-1028},{ -529, -738, -718, -718, -718},{ -859,-1068,-1048,-1048,-1048},{ -489, -698, -678, -678, -678}},
+/* AU.G..UG */
+{{  -50, -339, -689, -689, -689},{-1009,-1298,-1648,-1648,-1648},{ -409, -698,-1048,-1048,-1048},{ -969,-1258,-1608,-1608,-1608},{ -599, -888,-1238,-1238,-1238}},
+/* AU.U..UG */
+{{  -50, -329, -329, -329, -329},{ -859,-1138,-1138,-1138,-1138},{ -529, -808, -808, -808, -808},{ -859,-1138,-1138,-1138,-1138},{ -409, -688, -688, -688, -688}}
+},
+{
+/* AU.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..AU */
+{{  -50, -429, -599, -599, -599},{ -479, -858,-1028,-1028,-1028},{ -309, -688, -858, -858, -858},{ -389, -768, -938, -938, -938},{ -379, -758, -928, -928, -928}},
+/* AU.C..AU */
+{{  -50, -259, -239, -239, -239},{ -649, -858, -838, -838, -838},{ -289, -498, -478, -478, -478},{ -739, -948, -928, -928, -928},{ -379, -588, -568, -568, -568}},
+/* AU.G..AU */
+{{  -50, -339, -689, -689, -689},{ -649, -938,-1288,-1288,-1288},{ -289, -578, -928, -928, -928},{ -739,-1028,-1378,-1378,-1378},{ -379, -668,-1018,-1018,-1018}},
+/* AU.U..AU */
+{{  -50, -329, -329, -329, -329},{ -649, -928, -928, -928, -928},{ -289, -568, -568, -568, -568},{ -739,-1018,-1018,-1018,-1018},{ -379, -658, -658, -658, -658}}
+},
+{
+/* AU.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A..UA */
+{{  -50, -429, -599, -599, -599},{ -449, -828, -998, -998, -998},{ -479, -858,-1028,-1028,-1028},{ -429, -808, -978, -978, -978},{ -329, -708, -878, -878, -878}},
+/* AU.C..UA */
+{{  -50, -259, -239, -239, -239},{ -679, -888, -868, -868, -868},{ -559, -768, -748, -748, -748},{ -729, -938, -918, -918, -918},{ -189, -398, -378, -378, -378}},
+/* AU.G..UA */
+{{  -50, -339, -689, -689, -689},{ -939,-1228,-1578,-1578,-1578},{ -249, -538, -888, -888, -888},{ -939,-1228,-1578,-1578,-1578},{ -329, -618, -968, -968, -968}},
+/* AU.U..UA */
+{{  -50, -329, -329, -329, -329},{ -639, -918, -918, -918, -918},{ -229, -508, -508, -508, -508},{ -729,-1008,-1008,-1008,-1008},{ -190, -469, -469, -469, -469}}
+},
+{
+/* AU.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* AU.A.. @ */
+{{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649},{ -100, -479, -649, -649, -649}},
+/* AU.C.. @ */
+{{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289},{ -100, -309, -289, -289, -289}},
+/* AU.G.. @ */
+{{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739},{ -100, -389, -739, -739, -739}},
+/* AU.U.. @ */
+{{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379},{ -100, -379, -379, -379, -379}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/* UA.@..CG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..CG */
+{{  -50, -399, -629, -889, -589},{-1079,-1428,-1658,-1918,-1618},{ -569, -918,-1148,-1408,-1108},{ -989,-1338,-1568,-1828,-1528},{ -859,-1208,-1438,-1698,-1398}},
+/* UA.C..CG */
+{{  -50, -429, -509, -199, -179},{ -999,-1378,-1458,-1148,-1128},{ -499, -878, -958, -648, -628},{ -989,-1368,-1448,-1138,-1118},{ -789,-1168,-1248, -938, -918}},
+/* UA.G..CG */
+{{  -50, -379, -679, -889, -679},{-1079,-1408,-1708,-1918,-1708},{ -569, -898,-1198,-1408,-1198},{ -989,-1318,-1618,-1828,-1618},{ -859,-1188,-1488,-1698,-1488}},
+/* UA.U..CG */
+{{  -50, -279, -139, -279, -140},{-1079,-1308,-1168,-1308,-1169},{ -719, -948, -808, -948, -809},{ -989,-1218,-1078,-1218,-1079},{ -909,-1138, -998,-1138, -999}}
+},
+{
+/* UA.@..GC */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..GC */
+{{  -50, -399, -629, -889, -589},{ -569, -918,-1148,-1408,-1108},{ -769,-1118,-1348,-1608,-1308},{ -759,-1108,-1338,-1598,-1298},{ -549, -898,-1128,-1388,-1088}},
+/* UA.C..GC */
+{{  -50, -429, -509, -199, -179},{ -929,-1308,-1388,-1078,-1058},{ -359, -738, -818, -508, -488},{ -789,-1168,-1248, -938, -918},{ -549, -928,-1008, -698, -678}},
+/* UA.G..GC */
+{{  -50, -379, -679, -889, -679},{ -609, -938,-1238,-1448,-1238},{ -359, -688, -988,-1198, -988},{ -669, -998,-1298,-1508,-1298},{ -549, -878,-1178,-1388,-1178}},
+/* UA.U..GC */
+{{  -50, -279, -139, -279, -140},{ -929,-1158,-1018,-1158,-1019},{ -439, -668, -528, -668, -529},{ -789,-1018, -878,-1018, -879},{ -619, -848, -708, -848, -709}}
+},
+{
+/* UA.@..GU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..GU */
+{{  -50, -399, -629, -889, -589},{ -479, -828,-1058,-1318,-1018},{ -309, -658, -888,-1148, -848},{ -389, -738, -968,-1228, -928},{ -379, -728, -958,-1218, -918}},
+/* UA.C..GU */
+{{  -50, -429, -509, -199, -179},{ -649,-1028,-1108, -798, -778},{ -289, -668, -748, -438, -418},{ -739,-1118,-1198, -888, -868},{ -379, -758, -838, -528, -508}},
+/* UA.G..GU */
+{{  -50, -379, -679, -889, -679},{ -649, -978,-1278,-1488,-1278},{ -289, -618, -918,-1128, -918},{ -739,-1068,-1368,-1578,-1368},{ -379, -708,-1008,-1218,-1008}},
+/* UA.U..GU */
+{{  -50, -279, -139, -279, -140},{ -649, -878, -738, -878, -739},{ -289, -518, -378, -518, -379},{ -739, -968, -828, -968, -829},{ -379, -608, -468, -608, -469}}
+},
+{
+/* UA.@..UG */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..UG */
+{{  -50, -399, -629, -889, -589},{ -769,-1118,-1348,-1608,-1308},{ -529, -878,-1108,-1368,-1068},{ -709,-1058,-1288,-1548,-1248},{ -599, -948,-1178,-1438,-1138}},
+/* UA.C..UG */
+{{  -50, -429, -509, -199, -179},{ -839,-1218,-1298, -988, -968},{ -529, -908, -988, -678, -658},{ -859,-1238,-1318,-1008, -988},{ -489, -868, -948, -638, -618}},
+/* UA.G..UG */
+{{  -50, -379, -679, -889, -679},{-1009,-1338,-1638,-1848,-1638},{ -409, -738,-1038,-1248,-1038},{ -969,-1298,-1598,-1808,-1598},{ -599, -928,-1228,-1438,-1228}},
+/* UA.U..UG */
+{{  -50, -279, -139, -279, -140},{ -859,-1088, -948,-1088, -949},{ -529, -758, -618, -758, -619},{ -859,-1088, -948,-1088, -949},{ -409, -638, -498, -638, -499}}
+},
+{
+/* UA.@..AU */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..AU */
+{{  -50, -399, -629, -889, -589},{ -479, -828,-1058,-1318,-1018},{ -309, -658, -888,-1148, -848},{ -389, -738, -968,-1228, -928},{ -379, -728, -958,-1218, -918}},
+/* UA.C..AU */
+{{  -50, -429, -509, -199, -179},{ -649,-1028,-1108, -798, -778},{ -289, -668, -748, -438, -418},{ -739,-1118,-1198, -888, -868},{ -379, -758, -838, -528, -508}},
+/* UA.G..AU */
+{{  -50, -379, -679, -889, -679},{ -649, -978,-1278,-1488,-1278},{ -289, -618, -918,-1128, -918},{ -739,-1068,-1368,-1578,-1368},{ -379, -708,-1008,-1218,-1008}},
+/* UA.U..AU */
+{{  -50, -279, -139, -279, -140},{ -649, -878, -738, -878, -739},{ -289, -518, -378, -518, -379},{ -739, -968, -828, -968, -829},{ -379, -608, -468, -608, -469}}
+},
+{
+/* UA.@..UA */
+{{    0,    0,    0,    0,    0},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A..UA */
+{{  -50, -399, -629, -889, -589},{ -449, -798,-1028,-1288, -988},{ -479, -828,-1058,-1318,-1018},{ -429, -778,-1008,-1268, -968},{ -329, -678, -908,-1168, -868}},
+/* UA.C..UA */
+{{  -50, -429, -509, -199, -179},{ -679,-1058,-1138, -828, -808},{ -559, -938,-1018, -708, -688},{ -729,-1108,-1188, -878, -858},{ -189, -568, -648, -338, -318}},
+/* UA.G..UA */
+{{  -50, -379, -679, -889, -679},{ -939,-1268,-1568,-1778,-1568},{ -249, -578, -878,-1088, -878},{ -939,-1268,-1568,-1778,-1568},{ -329, -658, -958,-1168, -958}},
+/* UA.U..UA */
+{{  -50, -279, -139, -279, -140},{ -639, -868, -728, -868, -729},{ -229, -458, -318, -458, -319},{ -729, -958, -818, -958, -819},{ -190, -419, -279, -419, -280}}
+},
+{
+/* UA.@.. @ */
+{{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50},{  -50,  -50,  -50,  -50,  -50}},
+/* UA.A.. @ */
+{{ -100, -449, -679, -939, -639},{ -100, -449, -679, -939, -639},{ -100, -449, -679, -939, -639},{ -100, -449, -679, -939, -639},{ -100, -449, -679, -939, -639}},
+/* UA.C.. @ */
+{{ -100, -479, -559, -249, -229},{ -100, -479, -559, -249, -229},{ -100, -479, -559, -249, -229},{ -100, -479, -559, -249, -229},{ -100, -479, -559, -249, -229}},
+/* UA.G.. @ */
+{{ -100, -429, -729, -939, -729},{ -100, -429, -729, -939, -729},{ -100, -429, -729, -939, -729},{ -100, -429, -729, -939, -729},{ -100, -429, -729, -939, -729}},
+/* UA.U.. @ */
+{{ -100, -329, -189, -329, -190},{ -100, -329, -189, -329, -190},{ -100, -329, -189, -329, -190},{ -100, -329, -189, -329, -190},{ -100, -329, -189, -329, -190}}
+}
+},
+{ /* noPair */ {{{0}}},
+{
+/*  @.@..CG */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..CG */
+{{  -50,  -50,  -50,  -50,  -50},{-1079,-1079,-1079,-1079,-1079},{ -569, -569, -569, -569, -569},{ -989, -989, -989, -989, -989},{ -859, -859, -859, -859, -859}},
+/*  @.C..CG */
+{{  -50,  -50,  -50,  -50,  -50},{ -999, -999, -999, -999, -999},{ -499, -499, -499, -499, -499},{ -989, -989, -989, -989, -989},{ -789, -789, -789, -789, -789}},
+/*  @.G..CG */
+{{  -50,  -50,  -50,  -50,  -50},{-1079,-1079,-1079,-1079,-1079},{ -569, -569, -569, -569, -569},{ -989, -989, -989, -989, -989},{ -859, -859, -859, -859, -859}},
+/*  @.U..CG */
+{{  -50,  -50,  -50,  -50,  -50},{-1079,-1079,-1079,-1079,-1079},{ -719, -719, -719, -719, -719},{ -989, -989, -989, -989, -989},{ -909, -909, -909, -909, -909}}
+},
+{
+/*  @.@..GC */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..GC */
+{{  -50,  -50,  -50,  -50,  -50},{ -569, -569, -569, -569, -569},{ -769, -769, -769, -769, -769},{ -759, -759, -759, -759, -759},{ -549, -549, -549, -549, -549}},
+/*  @.C..GC */
+{{  -50,  -50,  -50,  -50,  -50},{ -929, -929, -929, -929, -929},{ -359, -359, -359, -359, -359},{ -789, -789, -789, -789, -789},{ -549, -549, -549, -549, -549}},
+/*  @.G..GC */
+{{  -50,  -50,  -50,  -50,  -50},{ -609, -609, -609, -609, -609},{ -359, -359, -359, -359, -359},{ -669, -669, -669, -669, -669},{ -549, -549, -549, -549, -549}},
+/*  @.U..GC */
+{{  -50,  -50,  -50,  -50,  -50},{ -929, -929, -929, -929, -929},{ -439, -439, -439, -439, -439},{ -789, -789, -789, -789, -789},{ -619, -619, -619, -619, -619}}
+},
+{
+/*  @.@..GU */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..GU */
+{{  -50,  -50,  -50,  -50,  -50},{ -479, -479, -479, -479, -479},{ -309, -309, -309, -309, -309},{ -389, -389, -389, -389, -389},{ -379, -379, -379, -379, -379}},
+/*  @.C..GU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}},
+/*  @.G..GU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}},
+/*  @.U..GU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}}
+},
+{
+/*  @.@..UG */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..UG */
+{{  -50,  -50,  -50,  -50,  -50},{ -769, -769, -769, -769, -769},{ -529, -529, -529, -529, -529},{ -709, -709, -709, -709, -709},{ -599, -599, -599, -599, -599}},
+/*  @.C..UG */
+{{  -50,  -50,  -50,  -50,  -50},{ -839, -839, -839, -839, -839},{ -529, -529, -529, -529, -529},{ -859, -859, -859, -859, -859},{ -489, -489, -489, -489, -489}},
+/*  @.G..UG */
+{{  -50,  -50,  -50,  -50,  -50},{-1009,-1009,-1009,-1009,-1009},{ -409, -409, -409, -409, -409},{ -969, -969, -969, -969, -969},{ -599, -599, -599, -599, -599}},
+/*  @.U..UG */
+{{  -50,  -50,  -50,  -50,  -50},{ -859, -859, -859, -859, -859},{ -529, -529, -529, -529, -529},{ -859, -859, -859, -859, -859},{ -409, -409, -409, -409, -409}}
+},
+{
+/*  @.@..AU */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..AU */
+{{  -50,  -50,  -50,  -50,  -50},{ -479, -479, -479, -479, -479},{ -309, -309, -309, -309, -309},{ -389, -389, -389, -389, -389},{ -379, -379, -379, -379, -379}},
+/*  @.C..AU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}},
+/*  @.G..AU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}},
+/*  @.U..AU */
+{{  -50,  -50,  -50,  -50,  -50},{ -649, -649, -649, -649, -649},{ -289, -289, -289, -289, -289},{ -739, -739, -739, -739, -739},{ -379, -379, -379, -379, -379}}
+},
+{
+/*  @.@..UA */
+{{  -50,  -50,  -50,  -50,  -50},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A..UA */
+{{  -50,  -50,  -50,  -50,  -50},{ -449, -449, -449, -449, -449},{ -479, -479, -479, -479, -479},{ -429, -429, -429, -429, -429},{ -329, -329, -329, -329, -329}},
+/*  @.C..UA */
+{{  -50,  -50,  -50,  -50,  -50},{ -679, -679, -679, -679, -679},{ -559, -559, -559, -559, -559},{ -729, -729, -729, -729, -729},{ -189, -189, -189, -189, -189}},
+/*  @.G..UA */
+{{  -50,  -50,  -50,  -50,  -50},{ -939, -939, -939, -939, -939},{ -249, -249, -249, -249, -249},{ -939, -939, -939, -939, -939},{ -329, -329, -329, -329, -329}},
+/*  @.U..UA */
+{{  -50,  -50,  -50,  -50,  -50},{ -639, -639, -639, -639, -639},{ -229, -229, -229, -229, -229},{ -729, -729, -729, -729, -729},{ -190, -190, -190, -190, -190}}
+},
+{
+/*  @.@.. @ */
+{{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.A.. @ */
+{{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.C.. @ */
+{{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.G.. @ */
+{{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}},
+/*  @.U.. @ */
+{{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100},{ -100, -100, -100, -100, -100}}
+}
+}
+};
+
+const int energy_param::int22_37[8][8][5][5][5][5] = {
+/* noPair */ {{{{{0}}}}},
+{ /* noPair */ {{{{0}}}},
+/* CG....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 160,  30, 200},{ 340, 120, 150,  20, 200},{ 340,  30,  60, -70, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 200,  60, 200},{ 340, 210, 180, 150, 200},{ 340, 200, 200, 200, 200},{ 340, 190, 170, 130, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  30,  60, -70, 200},{ 340, 200, 200, 200, 200},{ 340, 100, 140,   0, 200},{ 340, -40, -110, -60, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 190, 170, 130, 200},{ 340, 110,  40,  90, 200},{ 340, 140,  80, 130, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 120, 210, 200, 190},{ 340, 110, 140, 200, 120},{ 340,  20, 150, 200, 130},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 180, 200, 170},{ 340, 140, 170, 200, 150},{ 340, 200, 200, 200, 200},{ 340, 120, 150, 200, 140}},
+{{ 340, 340, 340, 340, 340},{ 340,  20, 150, 200, 130},{ 340, 200, 200, 200, 200},{ 340,  90, 180, 200, 170},{ 340, -150, -20, 200, -40}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 120, 150, 200, 140},{ 340,   0, 130, 200, 110},{ 340,  30,  60, 200,  50}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 200, 100, 110},{ 340,  20, 200,  90,   0},{ 340, -70, 200,   0,  90},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 200, 140,  40},{ 340, 150, 200, 180, 130},{ 340, 200, 200, 200, 200},{ 340, 130, 200, 170, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, -70, 200,   0,  90},{ 340, 200, 200, 200, 200},{ 340,   0, 200,  80,  90},{ 340, -60, 200, -70, -260}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 130, 200, 170, 110},{ 340,  90, 200,  90, -110},{ 340, 130, 200, 120, 110}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 190, -40, 140},{ 340, 200, 120, -150,  30},{ 340, 200, 130, -60, 130},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170, -110,  80},{ 340, 200, 150, -20,  60},{ 340, 200, 200, 200, 200},{ 340, 200, 140, -40,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 130, -60, 130},{ 340, 200, 200, 200, 200},{ 340, 200, 170, -70, 120},{ 340, 200, -40, -420, -50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 140, -40,  50},{ 340, 200, 110, -260, 110},{ 340, 200,  50, -50, -40}}
+}
+},
+/* CG....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  50,  60,   0, 200},{ 340, 110, 150, -70, 200},{ 340, -30,  10, -160, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 110, -100, 200},{ 340, 170, 150, -60, 200},{ 340, 200, 200, 200, 200},{ 340,  70,  50,  20, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  40,  50, -70, 200},{ 340, 200, 200, 200, 200},{ 340, 100, 140,   0, 200},{ 340,  10, -70, -80, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 180, 150, 120, 200},{ 340, -50, -60, -60, 200},{ 340, 150,   0,  90, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 220, 200, 200},{ 340, 100, 130, 200, 120},{ 340, -70,  70, 200,  40},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 190, 200, 110},{ 340, 100, 130, 200, 120},{ 340, 200, 200, 200, 200},{ 340,   0,  30, 200, 170}},
+{{ 340, 340, 340, 340, 340},{ 340,  70,  70, 200, 100},{ 340, 200, 200, 200, 200},{ 340,  90, 180, 200, 170},{ 340, -190, -30, 200, -70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 110, 140, 200, 120},{ 340, -150, -20, 200, -30},{ 340, -20, -10, 200,  20}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, -20, 200, 110,  90},{ 340, -40, 200,  90,   0},{ 340, -170, 200, -90,  30},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200,  80, -10},{ 340, 110, 200, 150, 100},{ 340, 200, 200, 200, 200},{ 340,  20, 200,  50,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, -50, 200, -20,  60},{ 340, 200, 200, 200, 200},{ 340,   0, 200,  80,  90},{ 340, -90, 200, -100, -300}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 120, 200, 150, 100},{ 340, -130, 200, -60, -240},{ 340,  90, 200, 110,  60}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, -10, 140},{ 340, 200, 120, -160,  30},{ 340, 200,  40, -160,  50},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 110, -160,  30},{ 340, 200, 120, -60,  30},{ 340, 200, 200, 200, 200},{ 340, 200,  20, -160,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  50, -60, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 170, -70, 120},{ 340, 200, -70, -440, -100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 120, -50,  30},{ 340, 200, -10, -410,  10},{ 340, 200,  40, -100,  60}}
+}
+},
+/* CG....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 180, 210,  80, 200},{ 340,  80, 110, -20, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 220,  90, 200},{ 340, 230, 210, 170, 200},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 110, -20, 200},{ 340, 200, 200, 200, 200},{ 340, 130, 170,  30, 200},{ 340,  60,   0,  40, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200},{ 340, 160,  90, 140, 200},{ 340, 190, 130, 180, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 280, 200, 270},{ 340, 170, 200, 200, 180},{ 340,  70, 200, 200, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 210, 200, 190},{ 340, 160, 190, 200, 180},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 200, 180},{ 340, 200, 200, 200, 200},{ 340, 120, 210, 200, 200},{ 340, -50,  80, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180},{ 340,  50, 180, 200, 160},{ 340,  80, 110, 200, 100}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180, 180},{ 340,  80, 200, 150,  60},{ 340, -20, 200,  50, 140},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 200, 160,  70},{ 340, 170, 200, 210, 150},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150}},
+{{ 340, 340, 340, 340, 340},{ 340, -20, 200,  50, 140},{ 340, 200, 200, 200, 200},{ 340,  30, 200, 110, 110},{ 340,  40, 200,  40, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150},{ 340, 140, 200, 130, -60},{ 340, 180, 200, 170, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 220},{ 340, 200, 180, -90,  90},{ 340, 200, 180, -10, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 190, -80, 100},{ 340, 200, 180,   0,  90},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 180, -10, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 200, -40, 150},{ 340, 200,  70, -310,  60}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90},{ 340, 200, 160, -210, 160},{ 340, 200, 100,   0,  10}}
+}
+},
+/* CG....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 160, 190,  60, 200},{ 340, 100, 130,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 260, 240, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 260, 240, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 130,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 140, 170,  40, 200},{ 340,  20, -40,   0, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200},{ 340, 150,  80, 130, 200},{ 340, 220, 150, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 280, 200, 270},{ 340, 150, 180, 200, 160},{ 340,  90, 220, 200, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 220, 200, 210},{ 340, 190, 220, 200, 210},{ 340, 200, 200, 200, 200},{ 340, 190, 220, 200, 210}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 220, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 130, 220, 200, 200},{ 340, -90,  40, 200,  30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180},{ 340,  40, 170, 200, 150},{ 340, 110, 140, 200, 120}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180, 180},{ 340,  60, 200, 130,  40},{ 340,   0, 200,  70, 160},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180,  80},{ 340, 200, 200, 240, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 240, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200,  70, 160},{ 340, 200, 200, 200, 200},{ 340,  40, 200, 110, 120},{ 340,   0, 200,   0, -200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150},{ 340, 130, 200, 120, -70},{ 340, 200, 200, 190, 180}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 220},{ 340, 200, 160, -110,  70},{ 340, 200, 200,  10, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 210, -70, 120},{ 340, 200, 210,  30, 120},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200,  10, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 200, -30, 150},{ 340, 200,  30, -350,  20}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90},{ 340, 200, 150, -220, 150},{ 340, 200, 120,  30,  30}}
+}
+},
+/* CG....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 180, 210,  80, 200},{ 340,  80, 110, -20, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 220,  90, 200},{ 340, 230, 210, 170, 200},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 110, -20, 200},{ 340, 200, 200, 200, 200},{ 340, 130, 170,  30, 200},{ 340,  60,   0,  40, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200},{ 340, 160,  90, 140, 200},{ 340, 190, 130, 180, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 280, 200, 270},{ 340, 170, 200, 200, 180},{ 340,  70, 200, 200, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 210, 200, 190},{ 340, 160, 190, 200, 180},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 200, 180},{ 340, 200, 200, 200, 200},{ 340, 120, 210, 200, 200},{ 340, -50,  80, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180},{ 340,  50, 180, 200, 160},{ 340,  80, 110, 200, 100}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180, 180},{ 340,  80, 200, 150,  60},{ 340, -20, 200,  50, 140},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 200, 160,  70},{ 340, 170, 200, 210, 150},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150}},
+{{ 340, 340, 340, 340, 340},{ 340, -20, 200,  50, 140},{ 340, 200, 200, 200, 200},{ 340,  30, 200, 110, 110},{ 340,  40, 200,  40, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150},{ 340, 140, 200, 130, -60},{ 340, 180, 200, 170, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 220},{ 340, 200, 180, -90,  90},{ 340, 200, 180, -10, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 190, -80, 100},{ 340, 200, 180,   0,  90},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 180, -10, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 200, -40, 150},{ 340, 200,  70, -310,  60}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90},{ 340, 200, 160, -210, 160},{ 340, 200, 100,   0,  10}}
+}
+},
+/* CG....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 160, 190,  60, 200},{ 340, 100, 130,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 100, 200},{ 340, 260, 240, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 260, 240, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 130,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 140, 170,  40, 200},{ 340,  20, -40,   0, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 230, 210, 170, 200},{ 340, 150,  80, 130, 200},{ 340, 220, 150, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 280, 200, 270},{ 340, 150, 180, 200, 160},{ 340,  90, 220, 200, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 220, 200, 210},{ 340, 190, 220, 200, 210},{ 340, 200, 200, 200, 200},{ 340, 190, 220, 200, 210}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 220, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 130, 220, 200, 200},{ 340, -90,  40, 200,  30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 190, 200, 180},{ 340,  40, 170, 200, 150},{ 340, 110, 140, 200, 120}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180, 180},{ 340,  60, 200, 130,  40},{ 340,   0, 200,  70, 160},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 180,  80},{ 340, 200, 200, 240, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 240, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200,  70, 160},{ 340, 200, 200, 200, 200},{ 340,  40, 200, 110, 120},{ 340,   0, 200,   0, -200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 210, 150},{ 340, 130, 200, 120, -70},{ 340, 200, 200, 190, 180}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 220},{ 340, 200, 160, -110,  70},{ 340, 200, 200,  10, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 210, -70, 120},{ 340, 200, 210,  30, 120},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200,  10, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 200, -30, 150},{ 340, 200,  30, -350,  20}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,   0,  90},{ 340, 200, 150, -220, 150},{ 340, 200, 120,  30,  30}}
+}
+},
+/* CG....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* GC....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 110,  40, 200},{ 340, 130, 100,  70, 200},{ 340, -20,  70, -50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 110,  50, 200},{ 340, 220, 190,  70, 200},{ 340, 200, 200, 200, 200},{ 340, 200, 110,  50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, -100, -70, 200},{ 340, 200, 200, 200, 200},{ 340, 110,  80, -20, 200},{ 340, -10, -160, -60, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 110, 100, 200},{ 340,  90, -10,  60, 200},{ 340, 140,  30, 140, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 170, 200, 180},{ 340, 100, 100, 200, 110},{ 340, -40, 110, 200, 120},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 150, 200, 150},{ 340, 130, 130, 200, 140},{ 340, 200, 200, 200, 200},{ 340, 120, 120, 200, 120}},
+{{ 340, 340, 340, 340, 340},{ 340, -70, -60, 200, 120},{ 340, 200, 200, 200, 200},{ 340,  90, 150, 200, 150},{ 340, -160, -60, 200, -50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 120, 120, 200, 120},{ 340,   0, 100, 200, 100},{ 340,  30,  30, 200,  30}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, -30, 200, 100, -50},{ 340, -70, 200,  90, -150},{ 340, -170, 200,   0, -130},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 140, -60},{ 340,  70, 200, 180, -20},{ 340, 200, 200, 200, 200},{ 340,  40, 200, 170, -10}},
+{{ 340, 340, 340, 340, 340},{ 340, -160, 200,   0, -60},{ 340, 200, 200, 200, 200},{ 340, -90, 200,  80, -60},{ 340, -160, 200, -70, -410}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  40, 200, 170, -30},{ 340,  30, 200,  90, -240},{ 340,  50, 200, 120,  10}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  70,  10, 150},{ 340, 200,   0, -190, -20},{ 340, 200,  20, -90,  90},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  50, -70,   0},{ 340, 200,  30, -30, -10},{ 340, 200, 200, 200, 200},{ 340, 200,  20, -70,  40}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  20, -80,  90},{ 340, 200, 200, 200, 200},{ 340, 200,  50, -100, 110},{ 340, 200, -160, -440, -100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 170, -70,  20},{ 340, 200,   0, -300,  60},{ 340, 200,  10, -100,  60}}
+}
+},
+/* GC....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 120,  10, 200},{ 340, 120,  90, -10, 200},{ 340, -50, -80, -190, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 120,  90, -20, 200},{ 340, 180,  90,  90, 200},{ 340, 200, 200, 200, 200},{ 340,  80,   0, -10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, -20, -130, 200},{ 340, 200, 200, 200, 200},{ 340, 110,  80, -20, 200},{ 340, -70, -200, -130, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 190, 100,  90, 200},{ 340, -30, -160, -90, 200},{ 340, 150,  20,  90, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 120, 180, 200, 190},{ 340, 100, 100, 200, 100},{ 340, -80,  20, 200,  30},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  90,  90, 200, 100},{ 340, 100, 100, 200, 100},{ 340, 200, 200, 200, 200},{ 340,   0,   0, 200,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, -10,  90, 200,  90},{ 340, 200, 200, 200, 200},{ 340,  90, 150, 200, 150},{ 340, -190, -90, 200, -90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 100, 100, 200, 110},{ 340, -150, -50, 200, -50},{ 340,  20,  20, 200,  30}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, -50, 200, 110, -30},{ 340, -80, 200,  90, -150},{ 340, -260, 200, -90, -150},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, -80, 200,  80, -160},{ 340,  20, 200, 150, -50},{ 340, 200, 200, 200, 200},{ 340, -80, 200,  50, -150}},
+{{ 340, 340, 340, 340, 340},{ 340, -190, 200, -20, -90},{ 340, 200, 200, 200, 200},{ 340, -90, 200,  80, -60},{ 340, -190, 200, -100, -450}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  30, 200, 150, -50},{ 340, -150, 200, -60, -410},{ 340,  30, 200, 110, -50}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  80, -70, 150},{ 340, 200,   0, -190,  20},{ 340, 200, -80, -190,  30},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,   0, -200,  20},{ 340, 200,   0, -90,  20},{ 340, 200, 200, 200, 200},{ 340, 200, -100, -190, -70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, -10, -130,  90},{ 340, 200, 200, 200, 200},{ 340, 200,  50, -100, 110},{ 340, 200, -190, -490, -90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200,   0, -90,  30},{ 340, 200, -150, -450, -50},{ 340, 200, -70, -90, -50}}
+}
+},
+/* GC....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 190, 160,  50, 200},{ 340,  90,  60, -50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170,  60, 200},{ 340, 240, 150, 140, 200},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  90,  60, -50, 200},{ 340, 200, 200, 200, 200},{ 340, 140, 110,   0, 200},{ 340,  70, -60,  10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200},{ 340, 170,  40, 110, 200},{ 340, 200,  70, 150, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 250, 200, 250},{ 340, 160, 160, 200, 170},{ 340,  60, 160, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170, 200, 180},{ 340, 160, 160, 200, 160},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 160, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 120, 180, 200, 180},{ 340, -50,  50, 200,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160},{ 340,  40, 140, 200, 150},{ 340,  80,  80, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180,  40},{ 340, -10, 200, 150, -90},{ 340, -110, 200,  50, -10},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200, 160, -80},{ 340,  80, 200, 210,  10},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, -110, 200,  50, -10},{ 340, 200, 200, 200, 200},{ 340, -60, 200, 110, -30},{ 340, -50, 200,  40, -310}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10},{ 340,  50, 200, 130, -210},{ 340,  80, 200, 170,  10}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150,   0, 210},{ 340, 200,  60, -130,  90},{ 340, 200,  70, -50, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  70, -120, 100},{ 340, 200,  60, -30,  80},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  70, -50, 170},{ 340, 200, 200, 200, 200},{ 340, 200,  80, -70, 140},{ 340, 200, -50, -350,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80},{ 340, 200,  50, -250, 150},{ 340, 200, -20, -30,   0}}
+}
+},
+/* GC....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 170, 140,  30, 200},{ 340, 110,  80, -30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 270, 180, 170, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 180, 170, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 110,  80, -30, 200},{ 340, 200, 200, 200, 200},{ 340, 150, 120,  10, 200},{ 340,  30, -100, -30, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200},{ 340, 160,  30, 100, 200},{ 340, 230, 100, 170, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 250, 200, 250},{ 340, 140, 140, 200, 150},{ 340,  80, 180, 200, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 190, 200, 190},{ 340, 190, 190, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 190, 190, 200, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 180, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 120, 180, 200, 190},{ 340, -90,  10, 200,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160},{ 340,  30, 130, 200, 140},{ 340, 100, 100, 200, 110}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180,  40},{ 340, -30, 200, 130, -110},{ 340, -90, 200,  70,  10},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180, -60},{ 340, 110, 200, 240,  40},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 240,  40}},
+{{ 340, 340, 340, 340, 340},{ 340, -90, 200,  70,  10},{ 340, 200, 200, 200, 200},{ 340, -50, 200, 110, -30},{ 340, -90, 200,   0, -350}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10},{ 340,  40, 200, 120, -220},{ 340, 110, 200, 190,  30}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150,   0, 210},{ 340, 200,  40, -150,  70},{ 340, 200,  90, -30, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  90, -100, 110},{ 340, 200,  90,   0, 110},{ 340, 200, 200, 200, 200},{ 340, 200,  90,   0, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  90, -30, 190},{ 340, 200, 200, 200, 200},{ 340, 200,  80, -70, 150},{ 340, 200, -90, -390,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80},{ 340, 200,  40, -260, 140},{ 340, 200,   0, -10,  30}}
+}
+},
+/* GC....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 190, 160,  50, 200},{ 340,  90,  60, -50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170,  60, 200},{ 340, 240, 150, 140, 200},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  90,  60, -50, 200},{ 340, 200, 200, 200, 200},{ 340, 140, 110,   0, 200},{ 340,  70, -60,  10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200},{ 340, 170,  40, 110, 200},{ 340, 200,  70, 150, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 250, 200, 250},{ 340, 160, 160, 200, 170},{ 340,  60, 160, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170, 200, 180},{ 340, 160, 160, 200, 160},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 160, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 120, 180, 200, 180},{ 340, -50,  50, 200,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160},{ 340,  40, 140, 200, 150},{ 340,  80,  80, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180,  40},{ 340, -10, 200, 150, -90},{ 340, -110, 200,  50, -10},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200, 160, -80},{ 340,  80, 200, 210,  10},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, -110, 200,  50, -10},{ 340, 200, 200, 200, 200},{ 340, -60, 200, 110, -30},{ 340, -50, 200,  40, -310}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10},{ 340,  50, 200, 130, -210},{ 340,  80, 200, 170,  10}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150,   0, 210},{ 340, 200,  60, -130,  90},{ 340, 200,  70, -50, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  70, -120, 100},{ 340, 200,  60, -30,  80},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  70, -50, 170},{ 340, 200, 200, 200, 200},{ 340, 200,  80, -70, 140},{ 340, 200, -50, -350,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80},{ 340, 200,  50, -250, 150},{ 340, 200, -20, -30,   0}}
+}
+},
+/* GC....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 170, 140,  30, 200},{ 340, 110,  80, -30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 180,  70, 200},{ 340, 270, 180, 170, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 180, 170, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 110,  80, -30, 200},{ 340, 200, 200, 200, 200},{ 340, 150, 120,  10, 200},{ 340,  30, -100, -30, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 150, 140, 200},{ 340, 160,  30, 100, 200},{ 340, 230, 100, 170, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 250, 200, 250},{ 340, 140, 140, 200, 150},{ 340,  80, 180, 200, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 190, 200, 190},{ 340, 190, 190, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 190, 190, 200, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 180, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 120, 180, 200, 190},{ 340, -90,  10, 200,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 160, 200, 160},{ 340,  30, 130, 200, 140},{ 340, 100, 100, 200, 110}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180,  40},{ 340, -30, 200, 130, -110},{ 340, -90, 200,  70,  10},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  10, 200, 180, -60},{ 340, 110, 200, 240,  40},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 240,  40}},
+{{ 340, 340, 340, 340, 340},{ 340, -90, 200,  70,  10},{ 340, 200, 200, 200, 200},{ 340, -50, 200, 110, -30},{ 340, -90, 200,   0, -350}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 210,  10},{ 340,  40, 200, 120, -220},{ 340, 110, 200, 190,  30}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150,   0, 210},{ 340, 200,  40, -150,  70},{ 340, 200,  90, -30, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  90, -100, 110},{ 340, 200,  90,   0, 110},{ 340, 200, 200, 200, 200},{ 340, 200,  90,   0, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200,  90, -30, 190},{ 340, 200, 200, 200, 200},{ 340, 200,  80, -70, 150},{ 340, 200, -90, -390,  10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -30,  80},{ 340, 200,  40, -260, 140},{ 340, 200,   0, -10,  30}}
+}
+},
+/* GC....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* GU....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 190,  80, 200},{ 340, 190, 180,  70, 200},{ 340, 100,  90, -20, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 220, 110, 200},{ 340, 280, 210, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 190, 180, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100,  90, -20, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 160,  50, 200},{ 340,  30, -80, -10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 270, 190, 180, 200},{ 340, 180,  70, 140, 200},{ 340, 220, 100, 180, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 230, 200, 230},{ 340, 170, 160, 200, 160},{ 340,  80, 170, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 210, 200, 210},{ 340, 200, 190, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 180, 180, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 170, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 150, 210, 200, 210},{ 340, -90,   0, 200,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 180, 180, 200, 180},{ 340,  60, 150, 200, 150},{ 340,  90,  90, 200,  90}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 200, 130, 160},{ 340,  70, 200, 120,  50},{ 340, -20, 200,  30, 140},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 200, 170,  90},{ 340, 200, 200, 210, 180},{ 340, 200, 200, 200, 200},{ 340, 180, 200, 200, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, -20, 200,  30, 140},{ 340, 200, 200, 200, 200},{ 340,  50, 200, 110, 130},{ 340, -10, 200, -40, -210}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 180, 200, 200, 160},{ 340, 140, 200, 110, -60},{ 340, 180, 200, 150, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  60, 190},{ 340, 200, 160, -50,  80},{ 340, 200, 170,  40, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 210,   0, 130},{ 340, 200, 190,  80, 110},{ 340, 200, 200, 200, 200},{ 340, 200, 180,  70, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170,  40, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  40, 170},{ 340, 200,   0, -310,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,  70, 100},{ 340, 200, 150, -160, 160},{ 340, 200,  90,  60,  10}}
+}
+},
+/* GU....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 200,  90, 200},{ 340, 190, 170,  60, 200},{ 340,  10,   0, -110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 170,  60, 200},{ 340, 250, 170, 160, 200},{ 340, 200, 200, 200, 200},{ 340, 150,  70,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  70,  60, -50, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 160,  50, 200},{ 340,   0, -120, -50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 250, 180, 170, 200},{ 340,  40, -80, -10, 200},{ 340, 210, 100, 170, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 240, 200, 240},{ 340, 160, 160, 200, 160},{ 340, -10,  80, 200,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 150, 200, 150},{ 340, 160, 160, 200, 160},{ 340, 200, 200, 200, 200},{ 340,  60,  60, 200,  60}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 140, 200, 140},{ 340, 200, 200, 200, 200},{ 340, 150, 210, 200, 210},{ 340, -130, -30, 200, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 160, 200, 160},{ 340, -90,  10, 200,  10},{ 340,  90,  80, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 200, 140, 170},{ 340,  60, 200, 120,  40},{ 340, -110, 200, -60,  50},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 200, 110,  40},{ 340, 160, 200, 180, 140},{ 340, 200, 200, 200, 200},{ 340,  70, 200,  80,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, -50, 200,   0, 110},{ 340, 200, 200, 200, 200},{ 340,  50, 200, 110, 130},{ 340, -50, 200, -70, -250}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 180, 150},{ 340, -10, 200, -30, -210},{ 340, 170, 200, 140, 150}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240,  70, 200},{ 340, 200, 160, -50,  80},{ 340, 200,  80, -50,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150, -60,  70},{ 340, 200, 160,  50,  80},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -50, -20}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 140,  10, 150},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  40, 170},{ 340, 200, -30, -350, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 160,  50,  80},{ 340, 200,  10, -310,  10},{ 340, 200,  80,  50,   0}}
+}
+},
+/* GU....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 250, 240, 130, 200},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 250, 140, 200},{ 340, 310, 230, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 190,  80, 200},{ 340, 130,  20,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 230, 120, 190, 200},{ 340, 270, 150, 220, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 230, 220, 200, 220},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 230, 200, 230},{ 340, 220, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 180, 240, 200, 240},{ 340,  10, 100, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 110, 200, 200, 200},{ 340, 140, 140, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 130, 200, 180, 110},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 200, 190, 120},{ 340, 220, 200, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 140, 160},{ 340,  90, 200,  70, -110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 190, 200, 160, -10},{ 340, 220, 200, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 220,  10, 140},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  20, 150},{ 340, 200, 220, 100, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200, 100, -210, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 200, -110, 200},{ 340, 200, 140, 110,  60}}
+}
+},
+/* GU....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 230, 220, 110, 200},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 340, 260, 250, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 260, 250, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 200,  90, 200},{ 340, 100, -20,  50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 220, 110, 180, 200},{ 340, 290, 180, 250, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 210, 200, 200, 200},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 250, 200, 250},{ 340, 250, 250, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 250, 250, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 190, 240, 200, 240},{ 340, -30,  70, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 100, 190, 200, 190},{ 340, 170, 160, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 110, 200, 160,  90},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 130},{ 340, 250, 200, 270, 230},{ 340, 200, 200, 200, 200},{ 340, 250, 200, 270, 230}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200},{ 340,  90, 200, 140, 170},{ 340,  50, 200,  30, -150}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 180, 200, 150, -20},{ 340, 250, 200, 220, 230}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 200, -10, 120},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  30, 170},{ 340, 200, 250, 130, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 130, 170}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200,  70, -250,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 190, -120, 190},{ 340, 200, 160, 130,  80}}
+}
+},
+/* GU....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 250, 240, 130, 200},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 250, 140, 200},{ 340, 310, 230, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 190,  80, 200},{ 340, 130,  20,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 230, 120, 190, 200},{ 340, 270, 150, 220, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 230, 220, 200, 220},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 230, 200, 230},{ 340, 220, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 180, 240, 200, 240},{ 340,  10, 100, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 110, 200, 200, 200},{ 340, 140, 140, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 130, 200, 180, 110},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 200, 190, 120},{ 340, 220, 200, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 140, 160},{ 340,  90, 200,  70, -110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 190, 200, 160, -10},{ 340, 220, 200, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 220,  10, 140},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  20, 150},{ 340, 200, 220, 100, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200, 100, -210, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 200, -110, 200},{ 340, 200, 140, 110,  60}}
+}
+},
+/* GU....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 230, 220, 110, 200},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 340, 260, 250, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 260, 250, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 200,  90, 200},{ 340, 100, -20,  50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 220, 110, 180, 200},{ 340, 290, 180, 250, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 210, 200, 200, 200},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 250, 200, 250},{ 340, 250, 250, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 250, 250, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 190, 240, 200, 240},{ 340, -30,  70, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 100, 190, 200, 190},{ 340, 170, 160, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 110, 200, 160,  90},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 130},{ 340, 250, 200, 270, 230},{ 340, 200, 200, 200, 200},{ 340, 250, 200, 270, 230}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200},{ 340,  90, 200, 140, 170},{ 340,  50, 200,  30, -150}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 180, 200, 150, -20},{ 340, 250, 200, 220, 230}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 200, -10, 120},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  30, 170},{ 340, 200, 250, 130, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 130, 170}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200,  70, -250,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 190, -120, 190},{ 340, 200, 160, 130,  80}}
+}
+},
+/* GU....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* UG....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 100, 200},{ 340, 190, 190,  90, 200},{ 340, 100, 100,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 240, 130, 200},{ 340, 280, 220, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 210, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 100,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 180,  70, 200},{ 340,  30, -70,  10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 270, 210, 200, 200},{ 340, 180,  80, 160, 200},{ 340, 220, 120, 190, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 260, 200, 230},{ 340, 150, 190, 200, 160},{ 340,  60, 200, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 240, 200, 210},{ 340, 180, 220, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 160, 210, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 200, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 130, 240, 200, 210},{ 340, -110,  30, 200,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 210, 200, 180},{ 340,  40, 180, 200, 150},{ 340,  70, 120, 200,  90}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 140, 150},{ 340,  90, 200, 130,  40},{ 340,   0, 200,  40, 130},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 200, 170,  80},{ 340, 220, 200, 220, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 200, 150}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200,  40, 130},{ 340, 200, 200, 200, 200},{ 340,  70, 200, 110, 120},{ 340,  10, 200, -30, -220}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 200, 150},{ 340, 160, 200, 120, -70},{ 340, 190, 200, 150, 150}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260,  20, 220},{ 340, 200, 190, -90, 110},{ 340, 200, 200,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, -40, 150},{ 340, 200, 220,  40, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 200, 240,   0, 190},{ 340, 200,  30, -350,  30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120},{ 340, 200, 180, -200, 180},{ 340, 200, 120,  20,  30}}
+}
+},
+/* UG....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 210, 110, 200},{ 340, 190, 190,  80, 200},{ 340,  10,  10, -90, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 180,  80, 200},{ 340, 250, 190, 180, 200},{ 340, 200, 200, 200, 200},{ 340, 150,  90,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  70,  70, -30, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 180,  70, 200},{ 340,   0, -100, -30, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 250, 190, 190, 200},{ 340,  40, -60,  10, 200},{ 340, 210, 110, 190, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 270, 200, 240},{ 340, 140, 190, 200, 160},{ 340, -30, 110, 200,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 180, 200, 150},{ 340, 140, 190, 200, 160},{ 340, 200, 200, 200, 200},{ 340,  40,  90, 200,  60}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 170, 200, 140},{ 340, 200, 200, 200, 200},{ 340, 130, 240, 200, 210},{ 340, -150,   0, 200, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 150, 190, 200, 160},{ 340, -110,  40, 200,  10},{ 340,  70, 110, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 200, 150, 160},{ 340,  80, 200, 120,  30},{ 340, -90, 200, -50,  40},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 200, 120,  30},{ 340, 180, 200, 180, 130},{ 340, 200, 200, 200, 200},{ 340,  90, 200,  80,  40}},
+{{ 340, 340, 340, 340, 340},{ 340, -30, 200,  10, 100},{ 340, 200, 200, 200, 200},{ 340,  70, 200, 110, 120},{ 340, -30, 200, -70, -260}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 190, 200, 190, 140},{ 340,  10, 200, -30, -220},{ 340, 190, 200, 150, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 230},{ 340, 200, 190, -90, 100},{ 340, 200, 110, -90, 110},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 180, -100, 100},{ 340, 200, 190,  10, 100},{ 340, 200, 200, 200, 200},{ 340, 200,  90, -90,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170, -30, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 240,   0, 190},{ 340, 200,   0, -390, -10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 190,  10, 110},{ 340, 200,  40, -350,  30},{ 340, 200, 110,  10,  30}}
+}
+},
+/* UG....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 250, 250, 150, 200},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 260, 160, 200},{ 340, 310, 250, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 100, 200},{ 340, 130,  30, 110, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 230, 130, 210, 200},{ 340, 270, 170, 240, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 210, 250, 200, 220},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 220, 260, 200, 230},{ 340, 200, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 160, 270, 200, 240},{ 340, -10, 130, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  90, 230, 200, 200},{ 340, 120, 170, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 150, 200, 190, 100},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 200, 200, 110},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200},{ 340, 100, 200, 140, 150},{ 340, 110, 200,  70, -120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 210, 200, 170, -20},{ 340, 240, 200, 200, 190}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 250, -30, 170},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260, -20, 180},{ 340, 200, 250,  70, 160},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 220},{ 340, 200, 130, -250, 130}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 230, -150, 230},{ 340, 200, 170,  70,  80}}
+}
+},
+/* UG....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 230, 230, 130, 200},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 340, 280, 270, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 280, 270, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 110, 200},{ 340, 100,   0,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 220, 120, 200, 200},{ 340, 290, 190, 270, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 190, 230, 200, 200},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 280, 200, 250},{ 340, 230, 280, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 230, 280, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 170, 270, 200, 240},{ 340, -50, 100, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  80, 220, 200, 190},{ 340, 150, 190, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 130, 200, 170,  80},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 120},{ 340, 270, 200, 270, 220},{ 340, 200, 200, 200, 200},{ 340, 270, 200, 270, 220}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 150, 160},{ 340,  70, 200,  30, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 160, -30},{ 340, 270, 200, 230, 220}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 230, -50, 150},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 280,   0, 190},{ 340, 200, 280, 100, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 280, 100, 190}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 230},{ 340, 200, 100, -290,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 220, -160, 220},{ 340, 200, 190,  90, 110}}
+}
+},
+/* UG....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 250, 250, 150, 200},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 260, 160, 200},{ 340, 310, 250, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 100, 200},{ 340, 130,  30, 110, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 230, 130, 210, 200},{ 340, 270, 170, 240, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 210, 250, 200, 220},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 220, 260, 200, 230},{ 340, 200, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 160, 270, 200, 240},{ 340, -10, 130, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  90, 230, 200, 200},{ 340, 120, 170, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 150, 200, 190, 100},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 200, 200, 110},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200},{ 340, 100, 200, 140, 150},{ 340, 110, 200,  70, -120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 210, 200, 170, -20},{ 340, 240, 200, 200, 190}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 250, -30, 170},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260, -20, 180},{ 340, 200, 250,  70, 160},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 220},{ 340, 200, 130, -250, 130}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 230, -150, 230},{ 340, 200, 170,  70,  80}}
+}
+},
+/* UG....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 230, 230, 130, 200},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 340, 280, 270, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 280, 270, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 110, 200},{ 340, 100,   0,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 220, 120, 200, 200},{ 340, 290, 190, 270, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 190, 230, 200, 200},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 280, 200, 250},{ 340, 230, 280, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 230, 280, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 170, 270, 200, 240},{ 340, -50, 100, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  80, 220, 200, 190},{ 340, 150, 190, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 130, 200, 170,  80},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 120},{ 340, 270, 200, 270, 220},{ 340, 200, 200, 200, 200},{ 340, 270, 200, 270, 220}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 150, 160},{ 340,  70, 200,  30, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 160, -30},{ 340, 270, 200, 230, 220}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 230, -50, 150},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 280,   0, 190},{ 340, 200, 280, 100, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 280, 100, 190}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 230},{ 340, 200, 100, -290,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 220, -160, 220},{ 340, 200, 190,  90, 110}}
+}
+},
+/* UG....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* AU....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 190,  80, 200},{ 340, 190, 180,  70, 200},{ 340, 100,  90, -20, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 220, 110, 200},{ 340, 280, 210, 200, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 190, 180, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100,  90, -20, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 160,  50, 200},{ 340,  30, -80, -10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 270, 190, 180, 200},{ 340, 180,  70, 140, 200},{ 340, 220, 100, 180, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 230, 200, 230},{ 340, 170, 160, 200, 160},{ 340,  80, 170, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 210, 200, 210},{ 340, 200, 190, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 180, 180, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 170, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 150, 210, 200, 210},{ 340, -90,   0, 200,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 180, 180, 200, 180},{ 340,  60, 150, 200, 150},{ 340,  90,  90, 200,  90}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 200, 130, 160},{ 340,  70, 200, 120,  50},{ 340, -20, 200,  30, 140},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 200, 170,  90},{ 340, 200, 200, 210, 180},{ 340, 200, 200, 200, 200},{ 340, 180, 200, 200, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, -20, 200,  30, 140},{ 340, 200, 200, 200, 200},{ 340,  50, 200, 110, 130},{ 340, -10, 200, -40, -210}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 180, 200, 200, 160},{ 340, 140, 200, 110, -60},{ 340, 180, 200, 150, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  60, 190},{ 340, 200, 160, -50,  80},{ 340, 200, 170,  40, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 210,   0, 130},{ 340, 200, 190,  80, 110},{ 340, 200, 200, 200, 200},{ 340, 200, 180,  70, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170,  40, 180},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  40, 170},{ 340, 200,   0, -310,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 180,  70, 100},{ 340, 200, 150, -160, 160},{ 340, 200,  90,  60,  10}}
+}
+},
+/* AU....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 200,  90, 200},{ 340, 190, 170,  60, 200},{ 340,  10,   0, -110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 170,  60, 200},{ 340, 250, 170, 160, 200},{ 340, 200, 200, 200, 200},{ 340, 150,  70,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  70,  60, -50, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 160,  50, 200},{ 340,   0, -120, -50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 250, 180, 170, 200},{ 340,  40, -80, -10, 200},{ 340, 210, 100, 170, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 240, 200, 240},{ 340, 160, 160, 200, 160},{ 340, -10,  80, 200,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 150, 200, 150},{ 340, 160, 160, 200, 160},{ 340, 200, 200, 200, 200},{ 340,  60,  60, 200,  60}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 140, 200, 140},{ 340, 200, 200, 200, 200},{ 340, 150, 210, 200, 210},{ 340, -130, -30, 200, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 160, 200, 160},{ 340, -90,  10, 200,  10},{ 340,  90,  80, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340,  90, 200, 140, 170},{ 340,  60, 200, 120,  40},{ 340, -110, 200, -60,  50},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 200, 110,  40},{ 340, 160, 200, 180, 140},{ 340, 200, 200, 200, 200},{ 340,  70, 200,  80,  50}},
+{{ 340, 340, 340, 340, 340},{ 340, -50, 200,   0, 110},{ 340, 200, 200, 200, 200},{ 340,  50, 200, 110, 130},{ 340, -50, 200, -70, -250}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 170, 200, 180, 150},{ 340, -10, 200, -30, -210},{ 340, 170, 200, 140, 150}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240,  70, 200},{ 340, 200, 160, -50,  80},{ 340, 200,  80, -50,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 150, -60,  70},{ 340, 200, 160,  50,  80},{ 340, 200, 200, 200, 200},{ 340, 200,  60, -50, -20}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 140,  10, 150},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  40, 170},{ 340, 200, -30, -350, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 160,  50,  80},{ 340, 200,  10, -310,  10},{ 340, 200,  80,  50,   0}}
+}
+},
+/* AU....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 250, 240, 130, 200},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 250, 140, 200},{ 340, 310, 230, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 190,  80, 200},{ 340, 130,  20,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 230, 120, 190, 200},{ 340, 270, 150, 220, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 230, 220, 200, 220},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 230, 200, 230},{ 340, 220, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 180, 240, 200, 240},{ 340,  10, 100, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 110, 200, 200, 200},{ 340, 140, 140, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 130, 200, 180, 110},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 200, 190, 120},{ 340, 220, 200, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 140, 160},{ 340,  90, 200,  70, -110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 190, 200, 160, -10},{ 340, 220, 200, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 220,  10, 140},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  20, 150},{ 340, 200, 220, 100, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200, 100, -210, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 200, -110, 200},{ 340, 200, 140, 110,  60}}
+}
+},
+/* AU....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 230, 220, 110, 200},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 340, 260, 250, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 260, 250, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 200,  90, 200},{ 340, 100, -20,  50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 220, 110, 180, 200},{ 340, 290, 180, 250, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 210, 200, 200, 200},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 250, 200, 250},{ 340, 250, 250, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 250, 250, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 190, 240, 200, 240},{ 340, -30,  70, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 100, 190, 200, 190},{ 340, 170, 160, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 110, 200, 160,  90},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 130},{ 340, 250, 200, 270, 230},{ 340, 200, 200, 200, 200},{ 340, 250, 200, 270, 230}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200},{ 340,  90, 200, 140, 170},{ 340,  50, 200,  30, -150}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 180, 200, 150, -20},{ 340, 250, 200, 220, 230}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 200, -10, 120},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  30, 170},{ 340, 200, 250, 130, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 130, 170}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200,  70, -250,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 190, -120, 190},{ 340, 200, 160, 130,  80}}
+}
+},
+/* AU....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 250, 240, 130, 200},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 250, 140, 200},{ 340, 310, 230, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 140,  30, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 190,  80, 200},{ 340, 130,  20,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 230, 120, 190, 200},{ 340, 270, 150, 220, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 230, 220, 200, 220},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 230, 200, 230},{ 340, 220, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 220, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 180, 240, 200, 240},{ 340,  10, 100, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 110, 200, 200, 200},{ 340, 140, 140, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 130, 200, 180, 110},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 200, 190, 120},{ 340, 220, 200, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 200,  80, 190},{ 340, 200, 200, 200, 200},{ 340,  80, 200, 140, 160},{ 340,  90, 200,  70, -110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 190, 200, 160, -10},{ 340, 220, 200, 200, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 220,  10, 140},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 230,  20, 150},{ 340, 200, 220, 100, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 220,  90, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200, 100, -210, 110}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 200, -110, 200},{ 340, 200, 140, 110,  60}}
+}
+},
+/* AU....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 230, 220, 110, 200},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 260, 150, 200},{ 340, 340, 260, 250, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 260, 250, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 160,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 200,  90, 200},{ 340, 100, -20,  50, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 230, 220, 200},{ 340, 220, 110, 180, 200},{ 340, 290, 180, 250, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 310, 200, 310},{ 340, 210, 200, 200, 200},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 250, 250, 200, 250},{ 340, 250, 250, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 250, 250, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 240, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 190, 240, 200, 240},{ 340, -30,  70, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 220, 200, 220},{ 340, 100, 190, 200, 190},{ 340, 170, 160, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 230},{ 340, 110, 200, 160,  90},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 200, 210, 130},{ 340, 250, 200, 270, 230},{ 340, 200, 200, 200, 200},{ 340, 250, 200, 270, 230}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200, 100, 210},{ 340, 200, 200, 200, 200},{ 340,  90, 200, 140, 170},{ 340,  50, 200,  30, -150}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 220, 200, 240, 200},{ 340, 180, 200, 150, -20},{ 340, 250, 200, 220, 230}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 310, 130, 270},{ 340, 200, 200, -10, 120},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  30, 170},{ 340, 200, 250, 130, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 130, 170}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, 110, 240},{ 340, 200, 200, 200, 200},{ 340, 200, 240,  70, 200},{ 340, 200,  70, -250,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 220, 100, 140},{ 340, 200, 190, -120, 190},{ 340, 200, 160, 130,  80}}
+}
+},
+/* AU....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* UA....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 100, 200},{ 340, 190, 190,  90, 200},{ 340, 100, 100,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 240, 240, 130, 200},{ 340, 280, 220, 220, 200},{ 340, 200, 200, 200, 200},{ 340, 270, 210, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 100,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 180,  70, 200},{ 340,  30, -70,  10, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 270, 210, 200, 200},{ 340, 180,  80, 160, 200},{ 340, 220, 120, 190, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 260, 200, 230},{ 340, 150, 190, 200, 160},{ 340,  60, 200, 200, 170},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 190, 240, 200, 210},{ 340, 180, 220, 200, 190},{ 340, 200, 200, 200, 200},{ 340, 160, 210, 200, 180}},
+{{ 340, 340, 340, 340, 340},{ 340,  60, 200, 200, 170},{ 340, 200, 200, 200, 200},{ 340, 130, 240, 200, 210},{ 340, -110,  30, 200,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 160, 210, 200, 180},{ 340,  40, 180, 200, 150},{ 340,  70, 120, 200,  90}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 100, 200, 140, 150},{ 340,  90, 200, 130,  40},{ 340,   0, 200,  40, 130},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 200, 170,  80},{ 340, 220, 200, 220, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 200, 150}},
+{{ 340, 340, 340, 340, 340},{ 340,   0, 200,  40, 130},{ 340, 200, 200, 200, 200},{ 340,  70, 200, 110, 120},{ 340,  10, 200, -30, -220}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 200, 200, 150},{ 340, 160, 200, 120, -70},{ 340, 190, 200, 150, 150}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260,  20, 220},{ 340, 200, 190, -90, 110},{ 340, 200, 200,   0, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 240, -40, 150},{ 340, 200, 220,  40, 140},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200,   0, 200},{ 340, 200, 200, 200, 200},{ 340, 200, 240,   0, 190},{ 340, 200,  30, -350,  30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 210,  30, 120},{ 340, 200, 180, -200, 180},{ 340, 200, 120,  20,  30}}
+}
+},
+/* UA....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 210, 210, 110, 200},{ 340, 190, 190,  80, 200},{ 340,  10,  10, -90, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 180, 180,  80, 200},{ 340, 250, 190, 180, 200},{ 340, 200, 200, 200, 200},{ 340, 150,  90,  90, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  70,  70, -30, 200},{ 340, 200, 200, 200, 200},{ 340, 180, 180,  70, 200},{ 340,   0, -100, -30, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 250, 190, 190, 200},{ 340,  40, -60,  10, 200},{ 340, 210, 110, 190, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 270, 200, 240},{ 340, 140, 190, 200, 160},{ 340, -30, 110, 200,  80},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 140, 180, 200, 150},{ 340, 140, 190, 200, 160},{ 340, 200, 200, 200, 200},{ 340,  40,  90, 200,  60}},
+{{ 340, 340, 340, 340, 340},{ 340,  30, 170, 200, 140},{ 340, 200, 200, 200, 200},{ 340, 130, 240, 200, 210},{ 340, -150,   0, 200, -30}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 150, 190, 200, 160},{ 340, -110,  40, 200,  10},{ 340,  70, 110, 200,  80}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 200, 150, 160},{ 340,  80, 200, 120,  30},{ 340, -90, 200, -50,  40},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340,  80, 200, 120,  30},{ 340, 180, 200, 180, 130},{ 340, 200, 200, 200, 200},{ 340,  90, 200,  80,  40}},
+{{ 340, 340, 340, 340, 340},{ 340, -30, 200,  10, 100},{ 340, 200, 200, 200, 200},{ 340,  70, 200, 110, 120},{ 340, -30, 200, -70, -260}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 190, 200, 190, 140},{ 340,  10, 200, -30, -220},{ 340, 190, 200, 150, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  30, 230},{ 340, 200, 190, -90, 100},{ 340, 200, 110, -90, 110},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 180, -100, 100},{ 340, 200, 190,  10, 100},{ 340, 200, 200, 200, 200},{ 340, 200,  90, -90,   0}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 170, -30, 170},{ 340, 200, 200, 200, 200},{ 340, 200, 240,   0, 190},{ 340, 200,   0, -390, -10}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 190,  10, 110},{ 340, 200,  40, -350,  30},{ 340, 200, 110,  10,  30}}
+}
+},
+/* UA....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 250, 250, 150, 200},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 260, 160, 200},{ 340, 310, 250, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 100, 200},{ 340, 130,  30, 110, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 230, 130, 210, 200},{ 340, 270, 170, 240, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 210, 250, 200, 220},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 220, 260, 200, 230},{ 340, 200, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 160, 270, 200, 240},{ 340, -10, 130, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  90, 230, 200, 200},{ 340, 120, 170, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 150, 200, 190, 100},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 200, 200, 110},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200},{ 340, 100, 200, 140, 150},{ 340, 110, 200,  70, -120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 210, 200, 170, -20},{ 340, 240, 200, 200, 190}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 250, -30, 170},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260, -20, 180},{ 340, 200, 250,  70, 160},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 220},{ 340, 200, 130, -250, 130}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 230, -150, 230},{ 340, 200, 170,  70,  80}}
+}
+},
+/* UA....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 230, 230, 130, 200},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 340, 280, 270, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 280, 270, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 110, 200},{ 340, 100,   0,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 220, 120, 200, 200},{ 340, 290, 190, 270, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 190, 230, 200, 200},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 280, 200, 250},{ 340, 230, 280, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 230, 280, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 170, 270, 200, 240},{ 340, -50, 100, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  80, 220, 200, 190},{ 340, 150, 190, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 130, 200, 170,  80},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 120},{ 340, 270, 200, 270, 220},{ 340, 200, 200, 200, 200},{ 340, 270, 200, 270, 220}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 150, 160},{ 340,  70, 200,  30, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 160, -30},{ 340, 270, 200, 230, 220}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 230, -50, 150},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 280,   0, 190},{ 340, 200, 280, 100, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 280, 100, 190}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 230},{ 340, 200, 100, -290,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 220, -160, 220},{ 340, 200, 190,  90, 110}}
+}
+},
+/* UA....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 250, 250, 150, 200},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 260, 260, 160, 200},{ 340, 310, 250, 240, 200},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 150, 150,  50, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 100, 200},{ 340, 130,  30, 110, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 230, 130, 210, 200},{ 340, 270, 170, 240, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 210, 250, 200, 220},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 220, 260, 200, 230},{ 340, 200, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220}},
+{{ 340, 340, 340, 340, 340},{ 340, 110, 250, 200, 220},{ 340, 200, 200, 200, 200},{ 340, 160, 270, 200, 240},{ 340, -10, 130, 200, 100}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  90, 230, 200, 200},{ 340, 120, 170, 200, 140}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 150, 200, 190, 100},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 160, 200, 200, 110},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190}},
+{{ 340, 340, 340, 340, 340},{ 340,  50, 200,  90, 180},{ 340, 200, 200, 200, 200},{ 340, 100, 200, 140, 150},{ 340, 110, 200,  70, -120}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 210, 200, 170, -20},{ 340, 240, 200, 200, 190}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 250, -30, 170},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 260, -20, 180},{ 340, 200, 250,  70, 160},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 250,  50, 250},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 220},{ 340, 200, 130, -250, 130}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 230, -150, 230},{ 340, 200, 170,  70,  80}}
+}
+},
+/* UA....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 230, 230, 130, 200},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 280, 280, 170, 200},{ 340, 340, 280, 270, 200},{ 340, 200, 200, 200, 200},{ 340, 340, 280, 270, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 170,  70, 200},{ 340, 200, 200, 200, 200},{ 340, 210, 210, 110, 200},{ 340, 100,   0,  70, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 310, 250, 240, 200},{ 340, 220, 120, 200, 200},{ 340, 290, 190, 270, 200}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 340, 200, 310},{ 340, 190, 230, 200, 200},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 230, 280, 200, 250},{ 340, 230, 280, 200, 250},{ 340, 200, 200, 200, 200},{ 340, 230, 280, 200, 250}},
+{{ 340, 340, 340, 340, 340},{ 340, 130, 270, 200, 240},{ 340, 200, 200, 200, 200},{ 340, 170, 270, 200, 240},{ 340, -50, 100, 200,  70}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250, 200, 220},{ 340,  80, 220, 200, 190},{ 340, 150, 190, 200, 160}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 220},{ 340, 130, 200, 170,  80},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 170, 200, 210, 120},{ 340, 270, 200, 270, 220},{ 340, 200, 200, 200, 200},{ 340, 270, 200, 270, 220}},
+{{ 340, 340, 340, 340, 340},{ 340,  70, 200, 110, 200},{ 340, 200, 200, 200, 200},{ 340, 110, 200, 150, 160},{ 340,  70, 200,  30, -160}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 240, 200, 240, 190},{ 340, 200, 200, 160, -30},{ 340, 270, 200, 230, 220}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 340, 100, 290},{ 340, 200, 230, -50, 150},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 280,   0, 190},{ 340, 200, 280, 100, 190},{ 340, 200, 200, 200, 200},{ 340, 200, 280, 100, 190}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 270,  70, 270},{ 340, 200, 200, 200, 200},{ 340, 200, 270,  30, 230},{ 340, 200, 100, -290,  90}},
+{{ 340, 340, 340, 340, 340},{ 340, 200, 200, 200, 200},{ 340, 200, 250,  70, 160},{ 340, 200, 220, -160, 220},{ 340, 200, 190,  90, 110}}
+}
+},
+/* UA....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+},
+{ /* noPair */ {{{{0}}}},
+/* ??....CG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....GC */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....GU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....UG */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....AU */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....UA */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+},
+/* ??....?? */
+{{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+},
+{
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}},
+{{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340},{ 340, 340, 340, 340, 340}}
+}
+}
+}
+};
+
+const int energy_param::int22_H[8][8][5][5][5][5] = 
+{ /* noPair */ {{{{{0}}}}},
+{ /* noPair */ {{{{0}}}},
+/* CG.@@..CG */
+{ { { {  0, 0, 0, 0, 0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..CG */
+{ {  0, 0, 0, 0, 0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* CG.@C..CG */
+{ {  0, 0, 0, 0, 0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* CG.@G..CG */
+{ {  0, 0, 0, 0, 0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* CG.@U..CG */
+{ {  0, 0, 0, 0, 0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* CG.A@..CG */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..CG */
+{{  -50,-1029, -949,-1029,-1029},
+{-1079,-2058,-1978,-2058,-2058},
+{ -569,-1548,-1468,-1548,-1548},
+{ -989,-1968,-1888,-1968,-1968},
+{ -859,-1838,-1758,-1838,-1838}},
+/* CG.AC..CG */
+{{  -50,-1029, -949,-1029,-1029},
+{ -999,-1978,-1898,-1978,-1978},
+{ -499,-1478,-1398,-1478,-1478},
+{ -989,-1968,-1888,-1968,-1968},
+{ -789,-1768,-1688,-1768,-1768}},
+/* CG.AG..CG */
+{{  -50,-1029, -949,-1029,-1029},
+{-1079,-2058,-1978,-2058,-2058},
+{ -569,-1548,-1468,-1548,-1548},
+{ -989,-1968,-1888,-1968,-1968},
+{ -859,-1838,-1758,-1838,-1838}},
+/* CG.AU..CG */
+{{  -50,-1029, -949,-1029,-1029},
+{-1079,-2058,-1978,-2058,-2058},
+{ -719,-1698,-1618,-1698,-1698},
+{ -989,-1968,-1888,-1968,-1968},
+{ -909,-1888,-1808,-1888,-1888}}},
+/* CG.C@..CG */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..CG */
+{{  -50, -519, -449, -519, -669},
+{-1079,-1548,-1478,-1548,-1698},
+{ -569,-1038, -968,-1038,-1188},
+{ -989,-1458,-1388,-1458,-1608},
+{ -859,-1328,-1258,-1328,-1478}},
+/* CG.CC..CG */
+{{  -50, -519, -449, -519, -669},
+{ -999,-1468,-1398,-1468,-1618},
+{ -499, -968, -898, -968,-1118},
+{ -989,-1458,-1388,-1458,-1608},
+{ -789,-1258,-1188,-1258,-1408}},
+/* CG.CG..CG */
+{{  -50, -519, -449, -519, -669},
+{-1079,-1548,-1478,-1548,-1698},
+{ -569,-1038, -968,-1038,-1188},
+{ -989,-1458,-1388,-1458,-1608},
+{ -859,-1328,-1258,-1328,-1478}},
+/* CG.CU..CG */
+{{  -50, -519, -449, -519, -669},
+{-1079,-1548,-1478,-1548,-1698},
+{ -719,-1188,-1118,-1188,-1338},
+{ -989,-1458,-1388,-1458,-1608},
+{ -909,-1378,-1308,-1378,-1528}}},
+/* CG.G@..CG */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..CG */
+{{  -50, -939, -939, -939, -939},
+{-1079,-1968,-1968,-1968,-1968},
+{ -569,-1458,-1458,-1458,-1458},
+{ -989,-1878,-1878,-1878,-1878},
+{ -859,-1748,-1748,-1748,-1748}},
+/* CG.GC..CG */
+{{  -50, -939, -939, -939, -939},
+{ -999,-1888,-1888,-1888,-1888},
+{ -499,-1388,-1388,-1388,-1388},
+{ -989,-1878,-1878,-1878,-1878},
+{ -789,-1678,-1678,-1678,-1678}},
+/* CG.GG..CG */
+{{  -50, -939, -939, -939, -939},
+{-1079,-1968,-1968,-1968,-1968},
+{ -569,-1458,-1458,-1458,-1458},
+{ -989,-1878,-1878,-1878,-1878},
+{ -859,-1748,-1748,-1748,-1748}},
+/* CG.GU..CG */
+{{  -50, -939, -939, -939, -939},
+{-1079,-1968,-1968,-1968,-1968},
+{ -719,-1608,-1608,-1608,-1608},
+{ -989,-1878,-1878,-1878,-1878},
+{ -909,-1798,-1798,-1798,-1798}}},
+/* CG.U@..CG */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..CG */
+{{  -50, -809, -739, -809, -859},
+{-1079,-1838,-1768,-1838,-1888},
+{ -569,-1328,-1258,-1328,-1378},
+{ -989,-1748,-1678,-1748,-1798},
+{ -859,-1618,-1548,-1618,-1668}},
+/* CG.UC..CG */
+{{  -50, -809, -739, -809, -859},
+{ -999,-1758,-1688,-1758,-1808},
+{ -499,-1258,-1188,-1258,-1308},
+{ -989,-1748,-1678,-1748,-1798},
+{ -789,-1548,-1478,-1548,-1598}},
+/* CG.UG..CG */
+{{  -50, -809, -739, -809, -859},
+{-1079,-1838,-1768,-1838,-1888},
+{ -569,-1328,-1258,-1328,-1378},
+{ -989,-1748,-1678,-1748,-1798},
+{ -859,-1618,-1548,-1618,-1668}},
+/* CG.UU..CG */
+{{  -50, -809, -739, -809, -859},
+{-1079,-1838,-1768,-1838,-1888},
+{ -719,-1478,-1408,-1478,-1528},
+{ -989,-1748,-1678,-1748,-1798},
+{ -909,-1668,-1598,-1668,-1718}}}},
+/* CG.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* CG.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* CG.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* CG.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* CG.A@..GC */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..GC */
+{{  -50,-1029, -949,-1029,-1029},
+{ -569,-1548,-1468,-1548,-1548},
+{ -769,-1748,-1668,-1748,-1748},
+{ -759,-1738,-1658,-1738,-1738},
+{ -549,-1528,-1448,-1528,-1528}},
+/* CG.AC..GC */
+{{  -50,-1029, -949,-1029,-1029},
+{ -929,-1908,-1828,-1908,-1908},
+{ -359,-1338,-1258,-1338,-1338},
+{ -789,-1768,-1688,-1768,-1768},
+{ -549,-1528,-1448,-1528,-1528}},
+/* CG.AG..GC */
+{{  -50,-1029, -949,-1029,-1029},
+{ -609,-1588,-1508,-1588,-1588},
+{ -359,-1338,-1258,-1338,-1338},
+{ -669,-1648,-1568,-1648,-1648},
+{ -549,-1528,-1448,-1528,-1528}},
+/* CG.AU..GC */
+{{  -50,-1029, -949,-1029,-1029},
+{ -929,-1908,-1828,-1908,-1908},
+{ -439,-1418,-1338,-1418,-1418},
+{ -789,-1768,-1688,-1768,-1768},
+{ -619,-1598,-1518,-1598,-1598}}},
+/* CG.C@..GC */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..GC */
+{{  -50, -519, -449, -519, -669},
+{ -569,-1038, -968,-1038,-1188},
+{ -769,-1238,-1168,-1238,-1388},
+{ -759,-1228,-1158,-1228,-1378},
+{ -549,-1018, -948,-1018,-1168}},
+/* CG.CC..GC */
+{{  -50, -519, -449, -519, -669},
+{ -929,-1398,-1328,-1398,-1548},
+{ -359, -828, -758, -828, -978},
+{ -789,-1258,-1188,-1258,-1408},
+{ -549,-1018, -948,-1018,-1168}},
+/* CG.CG..GC */
+{{  -50, -519, -449, -519, -669},
+{ -609,-1078,-1008,-1078,-1228},
+{ -359, -828, -758, -828, -978},
+{ -669,-1138,-1068,-1138,-1288},
+{ -549,-1018, -948,-1018,-1168}},
+/* CG.CU..GC */
+{{  -50, -519, -449, -519, -669},
+{ -929,-1398,-1328,-1398,-1548},
+{ -439, -908, -838, -908,-1058},
+{ -789,-1258,-1188,-1258,-1408},
+{ -619,-1088,-1018,-1088,-1238}}},
+/* CG.G@..GC */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..GC */
+{{  -50, -939, -939, -939, -939},
+{ -569,-1458,-1458,-1458,-1458},
+{ -769,-1658,-1658,-1658,-1658},
+{ -759,-1648,-1648,-1648,-1648},
+{ -549,-1438,-1438,-1438,-1438}},
+/* CG.GC..GC */
+{{  -50, -939, -939, -939, -939},
+{ -929,-1818,-1818,-1818,-1818},
+{ -359,-1248,-1248,-1248,-1248},
+{ -789,-1678,-1678,-1678,-1678},
+{ -549,-1438,-1438,-1438,-1438}},
+/* CG.GG..GC */
+{{  -50, -939, -939, -939, -939},
+{ -609,-1498,-1498,-1498,-1498},
+{ -359,-1248,-1248,-1248,-1248},
+{ -669,-1558,-1558,-1558,-1558},
+{ -549,-1438,-1438,-1438,-1438}},
+/* CG.GU..GC */
+{{  -50, -939, -939, -939, -939},
+{ -929,-1818,-1818,-1818,-1818},
+{ -439,-1328,-1328,-1328,-1328},
+{ -789,-1678,-1678,-1678,-3080},
+{ -619,-1508,-1508,-1508,-1508}}},
+/* CG.U@..GC */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..GC */
+{{  -50, -809, -739, -809, -859},
+{ -569,-1328,-1258,-1328,-1378},
+{ -769,-1528,-1458,-1528,-1578},
+{ -759,-1518,-1448,-1518,-1568},
+{ -549,-1308,-1238,-1308,-1358}},
+/* CG.UC..GC */
+{{  -50, -809, -739, -809, -859},
+{ -929,-1688,-1618,-1688,-1738},
+{ -359,-1118,-1048,-1118,-1168},
+{ -789,-1548,-1478,-1548,-1598},
+{ -549,-1308,-1238,-1308,-1358}},
+/* CG.UG..GC */
+{{  -50, -809, -739, -809, -859},
+{ -609,-1368,-1298,-1368,-1418},
+{ -359,-1118,-1048,-1118,-1168},
+{ -669,-1428,-1358,-1428,-1478},
+{ -549,-1308,-1238,-1308,-1358}},
+/* CG.UU..GC */
+{{  -50, -809, -739, -809, -859},
+{ -929,-1688,-1618,-1688,-1738},
+{ -439,-1198,-1128,-1198,-1248},
+{ -789,-1548,-1478,-1548,-1598},
+{ -619,-1378,-1308,-1378,-1428}}}},
+/* CG.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* CG.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* CG.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* CG.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* CG.A@..GU */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..GU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -479,-1458,-1378,-1458,-1458},
+{ -309,-1288,-1208,-1288,-1288},
+{ -389,-1368,-1288,-1368,-1368},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AC..GU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AG..GU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AU..GU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}}},
+/* CG.C@..GU */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..GU */
+{{  -50, -519, -449, -519, -669},
+{ -479, -948, -878, -948,-1098},
+{ -309, -778, -708, -778, -928},
+{ -389, -858, -788, -858,-1008},
+{ -379, -848, -778, -848, -998}},
+/* CG.CC..GU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}},
+/* CG.CG..GU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}},
+/* CG.CU..GU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}}},
+/* CG.G@..GU */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..GU */
+{{  -50, -939, -939, -939, -939},
+{ -479,-1368,-1368,-1368,-1368},
+{ -309,-1198,-1198,-1198,-1198},
+{ -389,-1278,-1278,-1278,-1278},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GC..GU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GG..GU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GU..GU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}}},
+/* CG.U@..GU */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..GU */
+{{  -50, -809, -739, -809, -859},
+{ -479,-1238,-1168,-1238,-1288},
+{ -309,-1068, -998,-1068,-1118},
+{ -389,-1148,-1078,-1148,-1198},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UC..GU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UG..GU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UU..GU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}}}},
+/* CG.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* CG.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* CG.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* CG.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* CG.A@..UG */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..UG */
+{{  -50,-1029, -949,-1029,-1029},
+{ -769,-1748,-1668,-1748,-1748},
+{ -529,-1508,-1428,-1508,-1508},
+{ -709,-1688,-1608,-1688,-1688},
+{ -599,-1578,-1498,-1578,-1578}},
+/* CG.AC..UG */
+{{  -50,-1029, -949,-1029,-1029},
+{ -839,-1818,-1738,-1818,-1818},
+{ -529,-1508,-1428,-1508,-1508},
+{ -859,-1838,-1758,-1838,-1838},
+{ -489,-1468,-1388,-1468,-1468}},
+/* CG.AG..UG */
+{{  -50,-1029, -949,-1029,-1029},
+{-1009,-1988,-1908,-1988,-1988},
+{ -409,-1388,-1308,-1388,-1388},
+{ -969,-1948,-1868,-1948,-1948},
+{ -599,-1578,-1498,-1578,-1578}},
+/* CG.AU..UG */
+{{  -50,-1029, -949,-1029,-1029},
+{ -859,-1838,-1758,-1838,-1838},
+{ -529,-1508,-1428,-1508,-1508},
+{ -859,-1838,-1758,-1838,-1838},
+{ -409,-1388,-1308,-1388,-1388}}},
+/* CG.C@..UG */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..UG */
+{{  -50, -519, -449, -519, -669},
+{ -769,-1238,-1168,-1238,-1388},
+{ -529, -998, -928, -998,-1148},
+{ -709,-1178,-1108,-1178,-1328},
+{ -599,-1068, -998,-1068,-1218}},
+/* CG.CC..UG */
+{{  -50, -519, -449, -519, -669},
+{ -839,-1308,-1238,-1308,-1458},
+{ -529, -998, -928, -998,-1148},
+{ -859,-1328,-1258,-1328,-1478},
+{ -489, -958, -888, -958,-1108}},
+/* CG.CG..UG */
+{{  -50, -519, -449, -519, -669},
+{-1009,-1478,-1408,-1478,-1628},
+{ -409, -878, -808, -878,-1028},
+{ -969,-1438,-1368,-1438,-1588},
+{ -599,-1068, -998,-1068,-1218}},
+/* CG.CU..UG */
+{{  -50, -519, -449, -519, -669},
+{ -859,-1328,-1258,-1328,-1478},
+{ -529, -998, -928, -998,-1148},
+{ -859,-1328,-1258,-1328,-1478},
+{ -409, -878, -808, -878,-1028}}},
+/* CG.G@..UG */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..UG */
+{{  -50, -939, -939, -939, -939},
+{ -769,-1658,-1658,-1658,-1658},
+{ -529,-1418,-1418,-1418,-1418},
+{ -709,-1598,-1598,-1598,-1598},
+{ -599,-1488,-1488,-1488,-1488}},
+/* CG.GC..UG */
+{{  -50, -939, -939, -939, -939},
+{ -839,-1728,-1728,-1728,-1728},
+{ -529,-1418,-1418,-1418,-1418},
+{ -859,-1748,-1748,-1748,-1748},
+{ -489,-1378,-1378,-1378,-1378}},
+/* CG.GG..UG */
+{{  -50, -939, -939, -939, -939},
+{-1009,-1898,-1898,-1898,-1898},
+{ -409,-1298,-1298,-1298,-1298},
+{ -969,-1858,-1858,-1858,-1858},
+{ -599,-1488,-1488,-1488,-1488}},
+/* CG.GU..UG */
+{{  -50, -939, -939, -939, -939},
+{ -859,-1748,-1748,-1748,-1748},
+{ -529,-1418,-1418,-1418,-1418},
+{ -859,-1748,-1748,-1748,-1748},
+{ -409,-1298,-1298,-1298,-1298}}},
+/* CG.U@..UG */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..UG */
+{{  -50, -809, -739, -809, -859},
+{ -769,-1528,-1458,-1528,-1578},
+{ -529,-1288,-1218,-1288,-1338},
+{ -709,-1468,-1398,-1468,-1518},
+{ -599,-1358,-1288,-1358,-1408}},
+/* CG.UC..UG */
+{{  -50, -809, -739, -809, -859},
+{ -839,-1598,-1528,-1598,-1648},
+{ -529,-1288,-1218,-1288,-1338},
+{ -859,-1618,-1548,-1618,-1668},
+{ -489,-1248,-1178,-1248,-1298}},
+/* CG.UG..UG */
+{{  -50, -809, -739, -809, -859},
+{-1009,-1768,-1698,-1768,-1818},
+{ -409,-1168,-1098,-1168,-1218},
+{ -969,-1728,-1658,-1728,-1778},
+{ -599,-1358,-1288,-1358,-1408}},
+/* CG.UU..UG */
+{{  -50, -809, -739, -809, -859},
+{ -859,-1618,-1548,-1618,-1668},
+{ -529,-1288,-1218,-1288,-1338},
+{ -859,-1618,-1548,-1618,-1668},
+{ -409,-1168,-1098,-1168,-1218}}}},
+/* CG.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* CG.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* CG.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* CG.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* CG.A@..AU */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..AU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -479,-1458,-1378,-1458,-1458},
+{ -309,-1288,-1208,-1288,-1288},
+{ -389,-1368,-1288,-1368,-1368},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AC..AU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AG..AU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}},
+/* CG.AU..AU */
+{{  -50,-1029, -949,-1029,-1029},
+{ -649,-1628,-1548,-1628,-1628},
+{ -289,-1268,-1188,-1268,-1268},
+{ -739,-1718,-1638,-1718,-1718},
+{ -379,-1358,-1278,-1358,-1358}}},
+/* CG.C@..AU */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..AU */
+{{  -50, -519, -449, -519, -669},
+{ -479, -948, -878, -948,-1098},
+{ -309, -778, -708, -778, -928},
+{ -389, -858, -788, -858,-1008},
+{ -379, -848, -778, -848, -998}},
+/* CG.CC..AU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}},
+/* CG.CG..AU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}},
+/* CG.CU..AU */
+{{  -50, -519, -449, -519, -669},
+{ -649,-1118,-1048,-1118,-1268},
+{ -289, -758, -688, -758, -908},
+{ -739,-1208,-1138,-1208,-1358},
+{ -379, -848, -778, -848, -998}}},
+/* CG.G@..AU */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..AU */
+{{  -50, -939, -939, -939, -939},
+{ -479,-1368,-1368,-1368,-1368},
+{ -309,-1198,-1198,-1198,-1198},
+{ -389,-1278,-1278,-1278,-1278},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GC..AU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GG..AU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}},
+/* CG.GU..AU */
+{{  -50, -939, -939, -939, -939},
+{ -649,-1538,-1538,-1538,-1538},
+{ -289,-1178,-1178,-1178,-1178},
+{ -739,-1628,-1628,-1628,-1628},
+{ -379,-1268,-1268,-1268,-1268}}},
+/* CG.U@..AU */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..AU */
+{{  -50, -809, -739, -809, -859},
+{ -479,-1238,-1168,-1238,-1288},
+{ -309,-1068, -998,-1068,-1118},
+{ -389,-1148,-1078,-1148,-1198},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UC..AU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UG..AU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}},
+/* CG.UU..AU */
+{{  -50, -809, -739, -809, -859},
+{ -649,-1408,-1338,-1408,-1458},
+{ -289,-1048, -978,-1048,-1098},
+{ -739,-1498,-1428,-1498,-1548},
+{ -379,-1138,-1068,-1138,-1188}}}},
+/* CG.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* CG.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* CG.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* CG.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* CG.A@..UA */
+{{{  -50,-1029, -949,-1029,-1029},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA..UA */
+{{  -50,-1029, -949,-1029,-1029},
+{ -449,-1428,-1348,-1428,-1428},
+{ -479,-1458,-1378,-1458,-1458},
+{ -429,-1408,-1328,-1408,-1408},
+{ -329,-1308,-1228,-1308,-1308}},
+/* CG.AC..UA */
+{{  -50,-1029, -949,-1029,-1029},
+{ -679,-1658,-1578,-1658,-1658},
+{ -559,-1538,-1458,-1538,-1538},
+{ -729,-1708,-1628,-1708,-1708},
+{ -189,-1168,-1088,-1168,-1168}},
+/* CG.AG..UA */
+{{  -50,-1029, -949,-1029,-1029},
+{ -939,-1918,-1838,-1918,-1918},
+{ -249,-1228,-1148,-1228,-1228},
+{ -939,-1918,-1838,-1918,-1918},
+{ -329,-1308,-1228,-1308,-1308}},
+/* CG.AU..UA */
+{{  -50,-1029, -949,-1029,-1029},
+{ -639,-1618,-1538,-1618,-1618},
+{ -229,-1208,-1128,-1208,-1208},
+{ -729,-1708,-1628,-1708,-1708},
+{ -190,-1169,-1089,-1169,-1169}}},
+/* CG.C@..UA */
+{{{  -50, -519, -449, -519, -669},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA..UA */
+{{  -50, -519, -449, -519, -669},
+{ -449, -918, -848, -918,-1068},
+{ -479, -948, -878, -948,-1098},
+{ -429, -898, -828, -898,-1048},
+{ -329, -798, -728, -798, -948}},
+/* CG.CC..UA */
+{{  -50, -519, -449, -519, -669},
+{ -679,-1148,-1078,-1148,-1298},
+{ -559,-1028, -958,-1028,-1178},
+{ -729,-1198,-1128,-1198,-1348},
+{ -189, -658, -588, -658, -808}},
+/* CG.CG..UA */
+{{  -50, -519, -449, -519, -669},
+{ -939,-1408,-1338,-1408,-1558},
+{ -249, -718, -648, -718, -868},
+{ -939,-1408,-1338,-1408,-1558},
+{ -329, -798, -728, -798, -948}},
+/* CG.CU..UA */
+{{  -50, -519, -449, -519, -669},
+{ -639,-1108,-1038,-1108,-1258},
+{ -229, -698, -628, -698, -848},
+{ -729,-1198,-1128,-1198,-1348},
+{ -190, -659, -589, -659, -809}}},
+/* CG.G@..UA */
+{{{  -50, -939, -939, -939, -939},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA..UA */
+{{  -50, -939, -939, -939, -939},
+{ -449,-1338,-1338,-1338,-1338},
+{ -479,-1368,-1368,-1368,-1368},
+{ -429,-1318,-1318,-1318,-1318},
+{ -329,-1218,-1218,-1218,-1218}},
+/* CG.GC..UA */
+{{  -50, -939, -939, -939, -939},
+{ -679,-1568,-1568,-1568,-1568},
+{ -559,-1448,-1448,-1448,-1448},
+{ -729,-1618,-1618,-1618,-1618},
+{ -189,-1078,-1078,-1078,-1078}},
+/* CG.GG..UA */
+{{  -50, -939, -939, -939, -939},
+{ -939,-1828,-1828,-1828,-1828},
+{ -249,-1138,-1138,-1138,-1138},
+{ -939,-1828,-1828,-1828,-1828},
+{ -329,-1218,-1218,-1218,-1218}},
+/* CG.GU..UA */
+{{  -50, -939, -939, -939, -939},
+{ -639,-1528,-1528,-1528,-1528},
+{ -229,-1118,-1118,-1118,-1118},
+{ -729,-1618,-1618,-1618,-1618},
+{ -190,-1079,-1079,-1079,-1079}}},
+/* CG.U@..UA */
+{{{  -50, -809, -739, -809, -859},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA..UA */
+{{  -50, -809, -739, -809, -859},
+{ -449,-1208,-1138,-1208,-1258},
+{ -479,-1238,-1168,-1238,-1288},
+{ -429,-1188,-1118,-1188,-1238},
+{ -329,-1088,-1018,-1088,-1138}},
+/* CG.UC..UA */
+{{  -50, -809, -739, -809, -859},
+{ -679,-1438,-1368,-1438,-1488},
+{ -559,-1318,-1248,-1318,-1368},
+{ -729,-1488,-1418,-1488,-1538},
+{ -189, -948, -878, -948, -998}},
+/* CG.UG..UA */
+{{  -50, -809, -739, -809, -859},
+{ -939,-1698,-1628,-1698,-1748},
+{ -249,-1008, -938,-1008,-1058},
+{ -939,-1698,-1628,-1698,-1748},
+{ -329,-1088,-1018,-1088,-1138}},
+/* CG.UU..UA */
+{{  -50, -809, -739, -809, -859},
+{ -639,-1398,-1328,-1398,-1448},
+{ -229, -988, -918, -988,-1038},
+{ -729,-1488,-1418,-1488,-1538},
+{ -190, -949, -879, -949, -999}}}},
+/* CG.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* CG.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* CG.A@.. @ */
+{{{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AA.. @ */
+{{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AC.. @ */
+{{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AG.. @ */
+{{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}},
+/* CG.AU.. @ */
+{{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079},
+{ -100,-1079, -999,-1079,-1079}}},
+/* CG.C@.. @ */
+{{{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CA.. @ */
+{{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CC.. @ */
+{{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CG.. @ */
+{{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}},
+/* CG.CU.. @ */
+{{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719},
+{ -100, -569, -499, -569, -719}}},
+/* CG.G@.. @ */
+{{{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GA.. @ */
+{{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GC.. @ */
+{{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GG.. @ */
+{{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}},
+/* CG.GU.. @ */
+{{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989},
+{ -100, -989, -989, -989, -989}}},
+/* CG.U@.. @ */
+{{{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UA.. @ */
+{{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UC.. @ */
+{{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UG.. @ */
+{{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}},
+/* CG.UU.. @ */
+{{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909},
+{ -100, -859, -789, -859, -909}}}}},
+{ /* noPair */ {{{{0}}}},
+/* GC.@@..CG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* GC.@C..CG */
+{{    0,    0,    0,    0,    0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* GC.@G..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* GC.@U..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* GC.A@..CG */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..CG */
+{{  -50, -519, -879, -559, -879},
+{-1079,-1548,-1908,-1588,-1908},
+{ -569,-1038,-1398,-1078,-1398},
+{ -989,-1458,-1818,-1498,-1818},
+{ -859,-1328,-1688,-1368,-1688}},
+/* GC.AC..CG */
+{{  -50, -519, -879, -559, -879},
+{ -999,-1468,-1828,-1508,-1828},
+{ -499, -968,-1328,-1008,-1328},
+{ -989,-1458,-1818,-1498,-1818},
+{ -789,-1258,-1618,-1298,-1618}},
+/* GC.AG..CG */
+{{  -50, -519, -879, -559, -879},
+{-1079,-1548,-1908,-1588,-1908},
+{ -569,-1038,-1398,-1078,-1398},
+{ -989,-1458,-1818,-1498,-1818},
+{ -859,-1328,-1688,-1368,-1688}},
+/* GC.AU..CG */
+{{  -50, -519, -879, -559, -879},
+{-1079,-1548,-1908,-1588,-1908},
+{ -719,-1188,-1548,-1228,-1548},
+{ -989,-1458,-1818,-1498,-1818},
+{ -909,-1378,-1738,-1418,-1738}}},
+/* GC.C@..CG */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..CG */
+{{  -50, -719, -309, -309, -389},
+{-1079,-1748,-1338,-1338,-1418},
+{ -569,-1238, -828, -828, -908},
+{ -989,-1658,-1248,-1248,-1328},
+{ -859,-1528,-1118,-1118,-1198}},
+/* GC.CC..CG */
+{{  -50, -719, -309, -309, -389},
+{ -999,-1668,-1258,-1258,-1338},
+{ -499,-1168, -758, -758, -838},
+{ -989,-1658,-1248,-1248,-1328},
+{ -789,-1458,-1048,-1048,-1128}},
+/* GC.CG..CG */
+{{  -50, -719, -309, -309, -389},
+{-1079,-1748,-1338,-1338,-1418},
+{ -569,-1238, -828, -828, -908},
+{ -989,-1658,-1248,-1248,-1328},
+{ -859,-1528,-1118,-1118,-1198}},
+/* GC.CU..CG */
+{{  -50, -719, -309, -309, -389},
+{-1079,-1748,-1338,-1338,-1418},
+{ -719,-1388, -978, -978,-1058},
+{ -989,-1658,-1248,-1248,-1328},
+{ -909,-1578,-1168,-1168,-1248}}},
+/* GC.G@..CG */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..CG */
+{{  -50, -709, -739, -619, -739},
+{-1079,-1738,-1768,-1648,-1768},
+{ -569,-1228,-1258,-1138,-1258},
+{ -989,-1648,-1678,-1558,-1678},
+{ -859,-1518,-1548,-1428,-1548}},
+/* GC.GC..CG */
+{{  -50, -709, -739, -619, -739},
+{ -999,-1658,-1688,-1568,-1688},
+{ -499,-1158,-1188,-1068,-1188},
+{ -989,-1648,-1678,-1558,-1678},
+{ -789,-1448,-1478,-1358,-1478}},
+/* GC.GG..CG */
+{{  -50, -709, -739, -619, -739},
+{-1079,-1738,-1768,-1648,-1768},
+{ -569,-1228,-1258,-1138,-1258},
+{ -989,-1648,-1678,-1558,-1678},
+{ -859,-1518,-1548,-1428,-1548}},
+/* GC.GU..CG */
+{{  -50, -709, -739, -619, -739},
+{-1079,-1738,-1768,-1648,-1768},
+{ -719,-1378,-1408,-1288,-1408},
+{ -989,-1648,-1678,-1558,-3080},
+{ -909,-1568,-1598,-1478,-1598}}},
+/* GC.U@..CG */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..CG */
+{{  -50, -499, -499, -499, -569},
+{-1079,-1528,-1528,-1528,-1598},
+{ -569,-1018,-1018,-1018,-1088},
+{ -989,-1438,-1438,-1438,-1508},
+{ -859,-1308,-1308,-1308,-1378}},
+/* GC.UC..CG */
+{{  -50, -499, -499, -499, -569},
+{ -999,-1448,-1448,-1448,-1518},
+{ -499, -948, -948, -948,-1018},
+{ -989,-1438,-1438,-1438,-1508},
+{ -789,-1238,-1238,-1238,-1308}},
+/* GC.UG..CG */
+{{  -50, -499, -499, -499, -569},
+{-1079,-1528,-1528,-1528,-1598},
+{ -569,-1018,-1018,-1018,-1088},
+{ -989,-1438,-1438,-1438,-1508},
+{ -859,-1308,-1308,-1308,-1378}},
+/* GC.UU..CG */
+{{  -50, -499, -499, -499, -569},
+{-1079,-1528,-1528,-1528,-1598},
+{ -719,-1168,-1168,-1168,-1238},
+{ -989,-1438,-1438,-1438,-1508},
+{ -909,-1358,-1358,-1358,-1428}}}},
+/* GC.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* GC.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* GC.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* GC.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* GC.A@..GC */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..GC */
+{{  -50, -519, -879, -559, -879},
+{ -569,-1038,-1398,-1078,-1398},
+{ -769,-1238,-1598,-1278,-1598},
+{ -759,-1228,-1588,-1268,-1588},
+{ -549,-1018,-1378,-1058,-1378}},
+/* GC.AC..GC */
+{{  -50, -519, -879, -559, -879},
+{ -929,-1398,-1758,-1438,-1758},
+{ -359, -828,-1188, -868,-1188},
+{ -789,-1258,-1618,-1298,-1618},
+{ -549,-1018,-1378,-1058,-1378}},
+/* GC.AG..GC */
+{{  -50, -519, -879, -559, -879},
+{ -609,-1078,-1438,-1118,-1438},
+{ -359, -828,-1188, -868,-1188},
+{ -669,-1138,-1498,-1178,-1498},
+{ -549,-1018,-1378,-1058,-1378}},
+/* GC.AU..GC */
+{{  -50, -519, -879, -559, -879},
+{ -929,-1398,-1758,-1438,-1758},
+{ -439, -908,-1268, -948,-1268},
+{ -789,-1258,-1618,-1298,-1618},
+{ -619,-1088,-1448,-1128,-1448}}},
+/* GC.C@..GC */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..GC */
+{{  -50, -719, -309, -309, -389},
+{ -569,-1238, -828, -828, -908},
+{ -769,-1438,-1028,-1028,-1108},
+{ -759,-1428,-1018,-1018,-1098},
+{ -549,-1218, -808, -808, -888}},
+/* GC.CC..GC */
+{{  -50, -719, -309, -309, -389},
+{ -929,-1598,-1188,-1188,-1268},
+{ -359,-1028, -618, -618, -698},
+{ -789,-1458,-1048,-1048,-1128},
+{ -549,-1218, -808, -808, -888}},
+/* GC.CG..GC */
+{{  -50, -719, -309, -309, -389},
+{ -609,-1278, -868, -868, -948},
+{ -359,-1028, -618, -618, -698},
+{ -669,-1338, -928, -928,-1008},
+{ -549,-1218, -808, -808, -888}},
+/* GC.CU..GC */
+{{  -50, -719, -309, -309, -389},
+{ -929,-1598,-1188,-1188,-1268},
+{ -439,-1108, -698, -698, -778},
+{ -789,-1458,-1048,-1048,-1128},
+{ -619,-1288, -878, -878, -958}}},
+/* GC.G@..GC */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..GC */
+{{  -50, -709, -739, -619, -739},
+{ -569,-1228,-1258,-1138,-1258},
+{ -769,-1428,-1458,-1338,-1458},
+{ -759,-1418,-1448,-1328,-1448},
+{ -549,-1208,-1238,-1118,-1238}},
+/* GC.GC..GC */
+{{  -50, -709, -739, -619, -739},
+{ -929,-1588,-1618,-1498,-1618},
+{ -359,-1018,-1048, -928,-1048},
+{ -789,-1448,-1478,-1358,-1478},
+{ -549,-1208,-1238,-1118,-1238}},
+/* GC.GG..GC */
+{{  -50, -709, -739, -619, -739},
+{ -609,-1268,-1298,-1178,-1298},
+{ -359,-1018,-1048, -928,-1048},
+{ -669,-1328,-1358,-1238,-1358},
+{ -549,-1208,-1238,-1118,-1238}},
+/* GC.GU..GC */
+{{  -50, -709, -739, -619, -739},
+{ -929,-1588,-1618,-1498,-1618},
+{ -439,-1098,-1128,-1008,-1128},
+{ -789,-1448,-1478,-1358,-3080},
+{ -619,-1278,-1308,-1188,-1308}}},
+/* GC.U@..GC */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..GC */
+{{  -50, -499, -499, -499, -569},
+{ -569,-1018,-1018,-1018,-1088},
+{ -769,-1218,-1218,-1218,-1288},
+{ -759,-1208,-1208,-1208,-1278},
+{ -549, -998, -998, -998,-1068}},
+/* GC.UC..GC */
+{{  -50, -499, -499, -499, -569},
+{ -929,-1378,-1378,-1378,-1448},
+{ -359, -808, -808, -808, -878},
+{ -789,-1238,-1238,-1238,-1308},
+{ -549, -998, -998, -998,-1068}},
+/* GC.UG..GC */
+{{  -50, -499, -499, -499, -569},
+{ -609,-1058,-1058,-1058,-1128},
+{ -359, -808, -808, -808, -878},
+{ -669,-1118,-1118,-1118,-1188},
+{ -549, -998, -998, -998,-1068}},
+/* GC.UU..GC */
+{{  -50, -499, -499, -499, -569},
+{ -929,-1378,-1378,-1378,-1448},
+{ -439, -888, -888, -888, -958},
+{ -789,-1238,-1238,-1238,-1308},
+{ -619,-1068,-1068,-1068,-1138}}}},
+/* GC.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* GC.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GC.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GC.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* GC.A@..GU */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..GU */
+{{  -50, -519, -879, -559, -879},
+{ -479, -948,-1308, -988,-1308},
+{ -309, -778,-1138, -818,-1138},
+{ -389, -858,-1218, -898,-1218},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AC..GU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AG..GU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AU..GU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}}},
+/* GC.C@..GU */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..GU */
+{{  -50, -719, -309, -309, -389},
+{ -479,-1148, -738, -738, -818},
+{ -309, -978, -568, -568, -648},
+{ -389,-1058, -648, -648, -728},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CC..GU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CG..GU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CU..GU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}}},
+/* GC.G@..GU */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..GU */
+{{  -50, -709, -739, -619, -739},
+{ -479,-1138,-1168,-1048,-1168},
+{ -309, -968, -998, -878, -998},
+{ -389,-1048,-1078, -958,-1078},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GC..GU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GG..GU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GU..GU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}}},
+/* GC.U@..GU */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..GU */
+{{  -50, -499, -499, -499, -569},
+{ -479, -928, -928, -928, -998},
+{ -309, -758, -758, -758, -828},
+{ -389, -838, -838, -838, -908},
+{ -379, -828, -828, -828, -898}},
+/* GC.UC..GU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}},
+/* GC.UG..GU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}},
+/* GC.UU..GU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}}}},
+/* GC.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* GC.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* GC.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* GC.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* GC.A@..UG */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..UG */
+{{  -50, -519, -879, -559, -879},
+{ -769,-1238,-1598,-1278,-1598},
+{ -529, -998,-1358,-1038,-1358},
+{ -709,-1178,-1538,-1218,-1538},
+{ -599,-1068,-1428,-1108,-1428}},
+/* GC.AC..UG */
+{{  -50, -519, -879, -559, -879},
+{ -839,-1308,-1668,-1348,-1668},
+{ -529, -998,-1358,-1038,-1358},
+{ -859,-1328,-1688,-1368,-1688},
+{ -489, -958,-1318, -998,-1318}},
+/* GC.AG..UG */
+{{  -50, -519, -879, -559, -879},
+{-1009,-1478,-1838,-1518,-1838},
+{ -409, -878,-1238, -918,-1238},
+{ -969,-1438,-1798,-1478,-1798},
+{ -599,-1068,-1428,-1108,-1428}},
+/* GC.AU..UG */
+{{  -50, -519, -879, -559, -879},
+{ -859,-1328,-1688,-1368,-1688},
+{ -529, -998,-1358,-1038,-1358},
+{ -859,-1328,-1688,-1368,-1688},
+{ -409, -878,-1238, -918,-1238}}},
+/* GC.C@..UG */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..UG */
+{{  -50, -719, -309, -309, -389},
+{ -769,-1438,-1028,-1028,-1108},
+{ -529,-1198, -788, -788, -868},
+{ -709,-1378, -968, -968,-1048},
+{ -599,-1268, -858, -858, -938}},
+/* GC.CC..UG */
+{{  -50, -719, -309, -309, -389},
+{ -839,-1508,-1098,-1098,-1178},
+{ -529,-1198, -788, -788, -868},
+{ -859,-1528,-1118,-1118,-1198},
+{ -489,-1158, -748, -748, -828}},
+/* GC.CG..UG */
+{{  -50, -719, -309, -309, -389},
+{-1009,-1678,-1268,-1268,-1348},
+{ -409,-1078, -668, -668, -748},
+{ -969,-1638,-1228,-1228,-1308},
+{ -599,-1268, -858, -858, -938}},
+/* GC.CU..UG */
+{{  -50, -719, -309, -309, -389},
+{ -859,-1528,-1118,-1118,-1198},
+{ -529,-1198, -788, -788, -868},
+{ -859,-1528,-1118,-1118,-1198},
+{ -409,-1078, -668, -668, -748}}},
+/* GC.G@..UG */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..UG */
+{{  -50, -709, -739, -619, -739},
+{ -769,-1428,-1458,-1338,-1458},
+{ -529,-1188,-1218,-1098,-1218},
+{ -709,-1368,-1398,-1278,-1398},
+{ -599,-1258,-1288,-1168,-1288}},
+/* GC.GC..UG */
+{{  -50, -709, -739, -619, -739},
+{ -839,-1498,-1528,-1408,-1528},
+{ -529,-1188,-1218,-1098,-1218},
+{ -859,-1518,-1548,-1428,-1548},
+{ -489,-1148,-1178,-1058,-1178}},
+/* GC.GG..UG */
+{{  -50, -709, -739, -619, -739},
+{-1009,-1668,-1698,-1578,-1698},
+{ -409,-1068,-1098, -978,-1098},
+{ -969,-1628,-1658,-1538,-1658},
+{ -599,-1258,-1288,-1168,-1288}},
+/* GC.GU..UG */
+{{  -50, -709, -739, -619, -739},
+{ -859,-1518,-1548,-1428,-1548},
+{ -529,-1188,-1218,-1098,-1218},
+{ -859,-1518,-1548,-1428,-1548},
+{ -409,-1068,-1098, -978,-1098}}},
+/* GC.U@..UG */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..UG */
+{{  -50, -499, -499, -499, -569},
+{ -769,-1218,-1218,-1218,-1288},
+{ -529, -978, -978, -978,-1048},
+{ -709,-1158,-1158,-1158,-1228},
+{ -599,-1048,-1048,-1048,-1118}},
+/* GC.UC..UG */
+{{  -50, -499, -499, -499, -569},
+{ -839,-1288,-1288,-1288,-1358},
+{ -529, -978, -978, -978,-1048},
+{ -859,-1308,-1308,-1308,-1378},
+{ -489, -938, -938, -938,-1008}},
+/* GC.UG..UG */
+{{  -50, -499, -499, -499, -569},
+{-1009,-1458,-1458,-1458,-1528},
+{ -409, -858, -858, -858, -928},
+{ -969,-1418,-1418,-1418,-1488},
+{ -599,-1048,-1048,-1048,-1118}},
+/* GC.UU..UG */
+{{  -50, -499, -499, -499, -569},
+{ -859,-1308,-1308,-1308,-1378},
+{ -529, -978, -978, -978,-1048},
+{ -859,-1308,-1308,-1308,-1378},
+{ -409, -858, -858, -858, -928}}}},
+/* GC.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* GC.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GC.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GC.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* GC.A@..AU */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..AU */
+{{  -50, -519, -879, -559, -879},
+{ -479, -948,-1308, -988,-1308},
+{ -309, -778,-1138, -818,-1138},
+{ -389, -858,-1218, -898,-1218},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AC..AU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AG..AU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}},
+/* GC.AU..AU */
+{{  -50, -519, -879, -559, -879},
+{ -649,-1118,-1478,-1158,-1478},
+{ -289, -758,-1118, -798,-1118},
+{ -739,-1208,-1568,-1248,-1568},
+{ -379, -848,-1208, -888,-1208}}},
+/* GC.C@..AU */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..AU */
+{{  -50, -719, -309, -309, -389},
+{ -479,-1148, -738, -738, -818},
+{ -309, -978, -568, -568, -648},
+{ -389,-1058, -648, -648, -728},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CC..AU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CG..AU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}},
+/* GC.CU..AU */
+{{  -50, -719, -309, -309, -389},
+{ -649,-1318, -908, -908, -988},
+{ -289, -958, -548, -548, -628},
+{ -739,-1408, -998, -998,-1078},
+{ -379,-1048, -638, -638, -718}}},
+/* GC.G@..AU */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..AU */
+{{  -50, -709, -739, -619, -739},
+{ -479,-1138,-1168,-1048,-1168},
+{ -309, -968, -998, -878, -998},
+{ -389,-1048,-1078, -958,-1078},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GC..AU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GG..AU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}},
+/* GC.GU..AU */
+{{  -50, -709, -739, -619, -739},
+{ -649,-1308,-1338,-1218,-1338},
+{ -289, -948, -978, -858, -978},
+{ -739,-1398,-1428,-1308,-1428},
+{ -379,-1038,-1068, -948,-1068}}},
+/* GC.U@..AU */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..AU */
+{{  -50, -499, -499, -499, -569},
+{ -479, -928, -928, -928, -998},
+{ -309, -758, -758, -758, -828},
+{ -389, -838, -838, -838, -908},
+{ -379, -828, -828, -828, -898}},
+/* GC.UC..AU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}},
+/* GC.UG..AU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}},
+/* GC.UU..AU */
+{{  -50, -499, -499, -499, -569},
+{ -649,-1098,-1098,-1098,-1168},
+{ -289, -738, -738, -738, -808},
+{ -739,-1188,-1188,-1188,-1258},
+{ -379, -828, -828, -828, -898}}}},
+/* GC.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* GC.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* GC.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* GC.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* GC.A@..UA */
+{{{  -50, -519, -879, -559, -879},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA..UA */
+{{  -50, -519, -879, -559, -879},
+{ -449, -918,-1278, -958,-1278},
+{ -479, -948,-1308, -988,-1308},
+{ -429, -898,-1258, -938,-1258},
+{ -329, -798,-1158, -838,-1158}},
+/* GC.AC..UA */
+{{  -50, -519, -879, -559, -879},
+{ -679,-1148,-1508,-1188,-1508},
+{ -559,-1028,-1388,-1068,-1388},
+{ -729,-1198,-1558,-1238,-1558},
+{ -189, -658,-1018, -698,-1018}},
+/* GC.AG..UA */
+{{  -50, -519, -879, -559, -879},
+{ -939,-1408,-1768,-1448,-1768},
+{ -249, -718,-1078, -758,-1078},
+{ -939,-1408,-1768,-1448,-1768},
+{ -329, -798,-1158, -838,-1158}},
+/* GC.AU..UA */
+{{  -50, -519, -879, -559, -879},
+{ -639,-1108,-1468,-1148,-1468},
+{ -229, -698,-1058, -738,-1058},
+{ -729,-1198,-1558,-1238,-1558},
+{ -190, -659,-1019, -699,-1019}}},
+/* GC.C@..UA */
+{{{  -50, -719, -309, -309, -389},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA..UA */
+{{  -50, -719, -309, -309, -389},
+{ -449,-1118, -708, -708, -788},
+{ -479,-1148, -738, -738, -818},
+{ -429,-1098, -688, -688, -768},
+{ -329, -998, -588, -588, -668}},
+/* GC.CC..UA */
+{{  -50, -719, -309, -309, -389},
+{ -679,-1348, -938, -938,-1018},
+{ -559,-1228, -818, -818, -898},
+{ -729,-1398, -988, -988,-1068},
+{ -189, -858, -448, -448, -528}},
+/* GC.CG..UA */
+{{  -50, -719, -309, -309, -389},
+{ -939,-1608,-1198,-1198,-1278},
+{ -249, -918, -508, -508, -588},
+{ -939,-1608,-1198,-1198,-1278},
+{ -329, -998, -588, -588, -668}},
+/* GC.CU..UA */
+{{  -50, -719, -309, -309, -389},
+{ -639,-1308, -898, -898, -978},
+{ -229, -898, -488, -488, -568},
+{ -729,-1398, -988, -988,-1068},
+{ -190, -859, -449, -449, -529}}},
+/* GC.G@..UA */
+{{{  -50, -709, -739, -619, -739},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA..UA */
+{{  -50, -709, -739, -619, -739},
+{ -449,-1108,-1138,-1018,-1138},
+{ -479,-1138,-1168,-1048,-1168},
+{ -429,-1088,-1118, -998,-1118},
+{ -329, -988,-1018, -898,-1018}},
+/* GC.GC..UA */
+{{  -50, -709, -739, -619, -739},
+{ -679,-1338,-1368,-1248,-1368},
+{ -559,-1218,-1248,-1128,-1248},
+{ -729,-1388,-1418,-1298,-1418},
+{ -189, -848, -878, -758, -878}},
+/* GC.GG..UA */
+{{  -50, -709, -739, -619, -739},
+{ -939,-1598,-1628,-1508,-1628},
+{ -249, -908, -938, -818, -938},
+{ -939,-1598,-1628,-1508,-1628},
+{ -329, -988,-1018, -898,-1018}},
+/* GC.GU..UA */
+{{  -50, -709, -739, -619, -739},
+{ -639,-1298,-1328,-1208,-1328},
+{ -229, -888, -918, -798, -918},
+{ -729,-1388,-1418,-1298,-1418},
+{ -190, -849, -879, -759, -879}}},
+/* GC.U@..UA */
+{{{  -50, -499, -499, -499, -569},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA..UA */
+{{  -50, -499, -499, -499, -569},
+{ -449, -898, -898, -898, -968},
+{ -479, -928, -928, -928, -998},
+{ -429, -878, -878, -878, -948},
+{ -329, -778, -778, -778, -848}},
+/* GC.UC..UA */
+{{  -50, -499, -499, -499, -569},
+{ -679,-1128,-1128,-1128,-1198},
+{ -559,-1008,-1008,-1008,-1078},
+{ -729,-1178,-1178,-1178,-1248},
+{ -189, -638, -638, -638, -708}},
+/* GC.UG..UA */
+{{  -50, -499, -499, -499, -569},
+{ -939,-1388,-1388,-1388,-1458},
+{ -249, -698, -698, -698, -768},
+{ -939,-1388,-1388,-1388,-1458},
+{ -329, -778, -778, -778, -848}},
+/* GC.UU..UA */
+{{  -50, -499, -499, -499, -569},
+{ -639,-1088,-1088,-1088,-1158},
+{ -229, -678, -678, -678, -748},
+{ -729,-1178,-1178,-1178,-1248},
+{ -190, -639, -639, -639, -709}}}},
+/* GC.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GC.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* GC.A@.. @ */
+{{{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AA.. @ */
+{{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AC.. @ */
+{{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AG.. @ */
+{{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}},
+/* GC.AU.. @ */
+{{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929},
+{ -100, -569, -929, -609, -929}}},
+/* GC.C@.. @ */
+{{{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CA.. @ */
+{{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CC.. @ */
+{{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CG.. @ */
+{{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}},
+/* GC.CU.. @ */
+{{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439},
+{ -100, -769, -359, -359, -439}}},
+/* GC.G@.. @ */
+{{{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GA.. @ */
+{{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GC.. @ */
+{{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GG.. @ */
+{{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}},
+/* GC.GU.. @ */
+{{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789},
+{ -100, -759, -789, -669, -789}}},
+/* GC.U@.. @ */
+{{{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UA.. @ */
+{{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UC.. @ */
+{{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UG.. @ */
+{{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}},
+/* GC.UU.. @ */
+{{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619},
+{ -100, -549, -549, -549, -619}}}}},
+{ /* noPair */ {{{{0}}}},
+/* GU.@@..CG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* GU.@C..CG */
+{{    0,    0,    0,    0,    0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* GU.@G..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* GU.@U..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* GU.A@..CG */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -569, -948,-1118,-1118,-1118},
+{ -989,-1368,-1538,-1538,-1538},
+{ -859,-1238,-1408,-1408,-1408}},
+/* GU.AC..CG */
+{{  -50, -429, -599, -599, -599},
+{ -999,-1378,-1548,-1548,-1548},
+{ -499, -878,-1048,-1048,-1048},
+{ -989,-1368,-1538,-1538,-1538},
+{ -789,-1168,-1338,-1338,-1338}},
+/* GU.AG..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -569, -948,-1118,-1118,-1118},
+{ -989,-1368,-1538,-1538,-1538},
+{ -859,-1238,-1408,-1408,-1408}},
+/* GU.AU..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -719,-1098,-1268,-1268,-1268},
+{ -989,-1368,-1538,-1538,-1538},
+{ -909,-1288,-1458,-1458,-1458}}},
+/* GU.C@..CG */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -569, -778, -758, -758, -758},
+{ -989,-1198,-1178,-1178,-1178},
+{ -859,-1068,-1048,-1048,-1048}},
+/* GU.CC..CG */
+{{  -50, -259, -239, -239, -239},
+{ -999,-1208,-1188,-1188,-1188},
+{ -499, -708, -688, -688, -688},
+{ -989,-1198,-1178,-1178,-1178},
+{ -789, -998, -978, -978, -978}},
+/* GU.CG..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -569, -778, -758, -758, -758},
+{ -989,-1198,-1178,-1178,-1178},
+{ -859,-1068,-1048,-1048,-1048}},
+/* GU.CU..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -719, -928, -908, -908, -908},
+{ -989,-1198,-1178,-1178,-1178},
+{ -909,-1118,-1098,-1098,-1098}}},
+/* GU.G@..CG */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -569, -858,-1208,-1208,-1208},
+{ -989,-1278,-1628,-1628,-1628},
+{ -859,-1148,-1498,-1498,-1498}},
+/* GU.GC..CG */
+{{  -50, -339, -689, -689, -689},
+{ -999,-1288,-1638,-1638,-1638},
+{ -499, -788,-1138,-1138,-1138},
+{ -989,-1278,-1628,-1628,-1628},
+{ -789,-1078,-1428,-1428,-1428}},
+/* GU.GG..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -569, -858,-1208,-1208,-1208},
+{ -989,-1278,-1628,-1628,-1628},
+{ -859,-1148,-1498,-1498,-1498}},
+/* GU.GU..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -719,-1008,-1358,-1358,-1358},
+{ -989,-1278,-1628,-1628,-1628},
+{ -909,-1198,-1548,-1548,-1548}}},
+/* GU.U@..CG */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -569, -848, -848, -848, -848},
+{ -989,-1268,-1268,-1268,-1268},
+{ -859,-1138,-1138,-1138,-1138}},
+/* GU.UC..CG */
+{{  -50, -329, -329, -329, -329},
+{ -999,-1278,-1278,-1278,-1278},
+{ -499, -778, -778, -778, -778},
+{ -989,-1268,-1268,-1268,-1268},
+{ -789,-1068,-1068,-1068,-1068}},
+/* GU.UG..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -569, -848, -848, -848, -848},
+{ -989,-1268,-1268,-1268,-1268},
+{ -859,-1138,-1138,-1138,-1138}},
+/* GU.UU..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -719, -998, -998, -998, -998},
+{ -989,-1268,-1268,-1268,-1268},
+{ -909,-1188,-1188,-1188,-1188}}}},
+/* GU.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* GU.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* GU.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* GU.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* GU.A@..GC */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..GC */
+{{  -50, -429, -599, -599, -599},
+{ -569, -948,-1118,-1118,-1118},
+{ -769,-1148,-1318,-1318,-1318},
+{ -759,-1138,-1308,-1308,-1308},
+{ -549, -928,-1098,-1098,-1098}},
+/* GU.AC..GC */
+{{  -50, -429, -599, -599, -599},
+{ -929,-1308,-1478,-1478,-1478},
+{ -359, -738, -908, -908, -908},
+{ -789,-1168,-1338,-1338,-1338},
+{ -549, -928,-1098,-1098,-1098}},
+/* GU.AG..GC */
+{{  -50, -429, -599, -599, -599},
+{ -609, -988,-1158,-1158,-1158},
+{ -359, -738, -908, -908, -908},
+{ -669,-1048,-1218,-1218,-1218},
+{ -549, -928,-1098,-1098,-1098}},
+/* GU.AU..GC */
+{{  -50, -429, -599, -599, -599},
+{ -929,-1308,-1478,-1478,-1478},
+{ -439, -818, -988, -988, -988},
+{ -789,-1168,-1338,-1338,-1338},
+{ -619, -998,-1168,-1168,-1168}}},
+/* GU.C@..GC */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..GC */
+{{  -50, -259, -239, -239, -239},
+{ -569, -778, -758, -758, -758},
+{ -769, -978, -958, -958, -958},
+{ -759, -968, -948, -948, -948},
+{ -549, -758, -738, -738, -738}},
+/* GU.CC..GC */
+{{  -50, -259, -239, -239, -239},
+{ -929,-1138,-1118,-1118,-1118},
+{ -359, -568, -548, -548, -548},
+{ -789, -998, -978, -978, -978},
+{ -549, -758, -738, -738, -738}},
+/* GU.CG..GC */
+{{  -50, -259, -239, -239, -239},
+{ -609, -818, -798, -798, -798},
+{ -359, -568, -548, -548, -548},
+{ -669, -878, -858, -858, -858},
+{ -549, -758, -738, -738, -738}},
+/* GU.CU..GC */
+{{  -50, -259, -239, -239, -239},
+{ -929,-1138,-1118,-1118,-1118},
+{ -439, -648, -628, -628, -628},
+{ -789, -998, -978, -978, -978},
+{ -619, -828, -808, -808, -808}}},
+/* GU.G@..GC */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..GC */
+{{  -50, -339, -689, -689, -689},
+{ -569, -858,-1208,-1208,-1208},
+{ -769,-1058,-1408,-1408,-1408},
+{ -759,-1048,-1398,-1398,-1398},
+{ -549, -838,-1188,-1188,-1188}},
+/* GU.GC..GC */
+{{  -50, -339, -689, -689, -689},
+{ -929,-1218,-1568,-1568,-1568},
+{ -359, -648, -998, -998, -998},
+{ -789,-1078,-1428,-1428,-1428},
+{ -549, -838,-1188,-1188,-1188}},
+/* GU.GG..GC */
+{{  -50, -339, -689, -689, -689},
+{ -609, -898,-1248,-1248,-1248},
+{ -359, -648, -998, -998, -998},
+{ -669, -958,-1308,-1308,-1308},
+{ -549, -838,-1188,-1188,-1188}},
+/* GU.GU..GC */
+{{  -50, -339, -689, -689, -689},
+{ -929,-1218,-1568,-1568,-1568},
+{ -439, -728,-1078,-1078,-1078},
+{ -789,-1078,-1428,-1428,-1428},
+{ -619, -908,-1258,-1258,-1258}}},
+/* GU.U@..GC */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..GC */
+{{  -50, -329, -329, -329, -329},
+{ -569, -848, -848, -848, -848},
+{ -769,-1048,-1048,-1048,-1048},
+{ -759,-1038,-1038,-1038,-1038},
+{ -549, -828, -828, -828, -828}},
+/* GU.UC..GC */
+{{  -50, -329, -329, -329, -329},
+{ -929,-1208,-1208,-1208,-1208},
+{ -359, -638, -638, -638, -638},
+{ -789,-1068,-1068,-1068,-1068},
+{ -549, -828, -828, -828, -828}},
+/* GU.UG..GC */
+{{  -50, -329, -329, -329, -329},
+{ -609, -888, -888, -888, -888},
+{ -359, -638, -638, -638, -638},
+{ -669, -948, -948, -948, -948},
+{ -549, -828, -828, -828, -828}},
+/* GU.UU..GC */
+{{  -50, -329, -329, -329, -329},
+{ -929,-1208,-1208,-1208,-1208},
+{ -439, -718, -718, -718, -718},
+{ -789,-1068,-1068,-1068,-1068},
+{ -619, -898, -898, -898, -898}}}},
+/* GU.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* GU.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GU.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GU.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* GU.A@..GU */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..GU */
+{{  -50, -429, -599, -599, -599},
+{ -479, -858,-1028,-1028,-1028},
+{ -309, -688, -858, -858, -858},
+{ -389, -768, -938, -938, -938},
+{ -379, -758, -928, -928, -928}},
+/* GU.AC..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* GU.AG..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* GU.AU..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}}},
+/* GU.C@..GU */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..GU */
+{{  -50, -259, -239, -239, -239},
+{ -479, -688, -668, -668, -668},
+{ -309, -518, -498, -498, -498},
+{ -389, -598, -578, -578, -578},
+{ -379, -588, -568, -568, -568}},
+/* GU.CC..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* GU.CG..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* GU.CU..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}}},
+/* GU.G@..GU */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..GU */
+{{  -50, -339, -689, -689, -689},
+{ -479, -768,-1118,-1118,-1118},
+{ -309, -598, -948, -948, -948},
+{ -389, -678,-1028,-1028,-1028},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GC..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GG..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GU..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}}},
+/* GU.U@..GU */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..GU */
+{{  -50, -329, -329, -329, -329},
+{ -479, -758, -758, -758, -758},
+{ -309, -588, -588, -588, -588},
+{ -389, -668, -668, -668, -668},
+{ -379, -658, -658, -658, -658}},
+/* GU.UC..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* GU.UG..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* GU.UU..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}}}},
+/* GU.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* GU.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* GU.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* GU.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* GU.A@..UG */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..UG */
+{{  -50, -429, -599, -599, -599},
+{ -769,-1148,-1318,-1318,-1318},
+{ -529, -908,-1078,-1078,-1078},
+{ -709,-1088,-1258,-1258,-1258},
+{ -599, -978,-1148,-1148,-1148}},
+/* GU.AC..UG */
+{{  -50, -429, -599, -599, -599},
+{ -839,-1218,-1388,-1388,-1388},
+{ -529, -908,-1078,-1078,-1078},
+{ -859,-1238,-1408,-1408,-1408},
+{ -489, -868,-1038,-1038,-1038}},
+/* GU.AG..UG */
+{{  -50, -429, -599, -599, -599},
+{-1009,-1388,-1558,-1558,-1558},
+{ -409, -788, -958, -958, -958},
+{ -969,-1348,-1518,-1518,-1518},
+{ -599, -978,-1148,-1148,-1148}},
+/* GU.AU..UG */
+{{  -50, -429, -599, -599, -599},
+{ -859,-1238,-1408,-1408,-1408},
+{ -529, -908,-1078,-1078,-1078},
+{ -859,-1238,-1408,-1408,-1408},
+{ -409, -788, -958, -958, -958}}},
+/* GU.C@..UG */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..UG */
+{{  -50, -259, -239, -239, -239},
+{ -769, -978, -958, -958, -958},
+{ -529, -738, -718, -718, -718},
+{ -709, -918, -898, -898, -898},
+{ -599, -808, -788, -788, -788}},
+/* GU.CC..UG */
+{{  -50, -259, -239, -239, -239},
+{ -839,-1048,-1028,-1028,-1028},
+{ -529, -738, -718, -718, -718},
+{ -859,-1068,-1048,-1048,-1048},
+{ -489, -698, -678, -678, -678}},
+/* GU.CG..UG */
+{{  -50, -259, -239, -239, -239},
+{-1009,-1218,-1198,-1198,-1198},
+{ -409, -618, -598, -598, -598},
+{ -969,-1178,-1158,-1158,-1158},
+{ -599, -808, -788, -788, -788}},
+/* GU.CU..UG */
+{{  -50, -259, -239, -239, -239},
+{ -859,-1068,-1048,-1048,-1048},
+{ -529, -738, -718, -718, -718},
+{ -859,-1068,-1048,-1048,-1048},
+{ -409, -618, -598, -598, -598}}},
+/* GU.G@..UG */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..UG */
+{{  -50, -339, -689, -689, -689},
+{ -769,-1058,-1408,-1408,-1408},
+{ -529, -818,-1168,-1168,-1168},
+{ -709, -998,-1348,-1348,-1348},
+{ -599, -888,-1238,-1238,-1238}},
+/* GU.GC..UG */
+{{  -50, -339, -689, -689, -689},
+{ -839,-1128,-1478,-1478,-1478},
+{ -529, -818,-1168,-1168,-1168},
+{ -859,-1148,-1498,-1498,-1498},
+{ -489, -778,-1128,-1128,-1128}},
+/* GU.GG..UG */
+{{  -50, -339, -689, -689, -689},
+{-1009,-1298,-1648,-1648,-1648},
+{ -409, -698,-1048,-1048,-1048},
+{ -969,-1258,-1608,-1608,-1608},
+{ -599, -888,-1238,-1238,-1238}},
+/* GU.GU..UG */
+{{  -50, -339, -689, -689, -689},
+{ -859,-1148,-1498,-1498,-1498},
+{ -529, -818,-1168,-1168,-1168},
+{ -859,-1148,-1498,-1498,-1498},
+{ -409, -698,-1048,-1048,-1048}}},
+/* GU.U@..UG */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..UG */
+{{  -50, -329, -329, -329, -329},
+{ -769,-1048,-1048,-1048,-1048},
+{ -529, -808, -808, -808, -808},
+{ -709, -988, -988, -988, -988},
+{ -599, -878, -878, -878, -878}},
+/* GU.UC..UG */
+{{  -50, -329, -329, -329, -329},
+{ -839,-1118,-1118,-1118,-1118},
+{ -529, -808, -808, -808, -808},
+{ -859,-1138,-1138,-1138,-1138},
+{ -489, -768, -768, -768, -768}},
+/* GU.UG..UG */
+{{  -50, -329, -329, -329, -329},
+{-1009,-1288,-1288,-1288,-1288},
+{ -409, -688, -688, -688, -688},
+{ -969,-1248,-1248,-1248,-1248},
+{ -599, -878, -878, -878, -878}},
+/* GU.UU..UG */
+{{  -50, -329, -329, -329, -329},
+{ -859,-1138,-1138,-1138,-1138},
+{ -529, -808, -808, -808, -808},
+{ -859,-1138,-1138,-1138,-1138},
+{ -409, -688, -688, -688, -688}}}},
+/* GU.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* GU.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GU.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* GU.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* GU.A@..AU */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..AU */
+{{  -50, -429, -599, -599, -599},
+{ -479, -858,-1028,-1028,-1028},
+{ -309, -688, -858, -858, -858},
+{ -389, -768, -938, -938, -938},
+{ -379, -758, -928, -928, -928}},
+/* GU.AC..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* GU.AG..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* GU.AU..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}}},
+/* GU.C@..AU */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..AU */
+{{  -50, -259, -239, -239, -239},
+{ -479, -688, -668, -668, -668},
+{ -309, -518, -498, -498, -498},
+{ -389, -598, -578, -578, -578},
+{ -379, -588, -568, -568, -568}},
+/* GU.CC..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* GU.CG..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* GU.CU..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}}},
+/* GU.G@..AU */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..AU */
+{{  -50, -339, -689, -689, -689},
+{ -479, -768,-1118,-1118,-1118},
+{ -309, -598, -948, -948, -948},
+{ -389, -678,-1028,-1028,-1028},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GC..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GG..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* GU.GU..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}}},
+/* GU.U@..AU */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..AU */
+{{  -50, -329, -329, -329, -329},
+{ -479, -758, -758, -758, -758},
+{ -309, -588, -588, -588, -588},
+{ -389, -668, -668, -668, -668},
+{ -379, -658, -658, -658, -658}},
+/* GU.UC..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* GU.UG..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* GU.UU..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}}}},
+/* GU.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* GU.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* GU.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* GU.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* GU.A@..UA */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA..UA */
+{{  -50, -429, -599, -599, -599},
+{ -449, -828, -998, -998, -998},
+{ -479, -858,-1028,-1028,-1028},
+{ -429, -808, -978, -978, -978},
+{ -329, -708, -878, -878, -878}},
+/* GU.AC..UA */
+{{  -50, -429, -599, -599, -599},
+{ -679,-1058,-1228,-1228,-1228},
+{ -559, -938,-1108,-1108,-1108},
+{ -729,-1108,-1278,-1278,-1278},
+{ -189, -568, -738, -738, -738}},
+/* GU.AG..UA */
+{{  -50, -429, -599, -599, -599},
+{ -939,-1318,-1488,-1488,-1488},
+{ -249, -628, -798, -798, -798},
+{ -939,-1318,-1488,-1488,-1488},
+{ -329, -708, -878, -878, -878}},
+/* GU.AU..UA */
+{{  -50, -429, -599, -599, -599},
+{ -639,-1018,-1188,-1188,-1188},
+{ -229, -608, -778, -778, -778},
+{ -729,-1108,-1278,-1278,-1278},
+{ -190, -569, -739, -739, -739}}},
+/* GU.C@..UA */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA..UA */
+{{  -50, -259, -239, -239, -239},
+{ -449, -658, -638, -638, -638},
+{ -479, -688, -668, -668, -668},
+{ -429, -638, -618, -618, -618},
+{ -329, -538, -518, -518, -518}},
+/* GU.CC..UA */
+{{  -50, -259, -239, -239, -239},
+{ -679, -888, -868, -868, -868},
+{ -559, -768, -748, -748, -748},
+{ -729, -938, -918, -918, -918},
+{ -189, -398, -378, -378, -378}},
+/* GU.CG..UA */
+{{  -50, -259, -239, -239, -239},
+{ -939,-1148,-1128,-1128,-1128},
+{ -249, -458, -438, -438, -438},
+{ -939,-1148,-1128,-1128,-1128},
+{ -329, -538, -518, -518, -518}},
+/* GU.CU..UA */
+{{  -50, -259, -239, -239, -239},
+{ -639, -848, -828, -828, -828},
+{ -229, -438, -418, -418, -418},
+{ -729, -938, -918, -918, -918},
+{ -190, -399, -379, -379, -379}}},
+/* GU.G@..UA */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA..UA */
+{{  -50, -339, -689, -689, -689},
+{ -449, -738,-1088,-1088,-1088},
+{ -479, -768,-1118,-1118,-1118},
+{ -429, -718,-1068,-1068,-1068},
+{ -329, -618, -968, -968, -968}},
+/* GU.GC..UA */
+{{  -50, -339, -689, -689, -689},
+{ -679, -968,-1318,-1318,-1318},
+{ -559, -848,-1198,-1198,-1198},
+{ -729,-1018,-1368,-1368,-1368},
+{ -189, -478, -828, -828, -828}},
+/* GU.GG..UA */
+{{  -50, -339, -689, -689, -689},
+{ -939,-1228,-1578,-1578,-1578},
+{ -249, -538, -888, -888, -888},
+{ -939,-1228,-1578,-1578,-1578},
+{ -329, -618, -968, -968, -968}},
+/* GU.GU..UA */
+{{  -50, -339, -689, -689, -689},
+{ -639, -928,-1278,-1278,-1278},
+{ -229, -518, -868, -868, -868},
+{ -729,-1018,-1368,-1368,-1368},
+{ -190, -479, -829, -829, -829}}},
+/* GU.U@..UA */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA..UA */
+{{  -50, -329, -329, -329, -329},
+{ -449, -728, -728, -728, -728},
+{ -479, -758, -758, -758, -758},
+{ -429, -708, -708, -708, -708},
+{ -329, -608, -608, -608, -608}},
+/* GU.UC..UA */
+{{  -50, -329, -329, -329, -329},
+{ -679, -958, -958, -958, -958},
+{ -559, -838, -838, -838, -838},
+{ -729,-1008,-1008,-1008,-1008},
+{ -189, -468, -468, -468, -468}},
+/* GU.UG..UA */
+{{  -50, -329, -329, -329, -329},
+{ -939,-1218,-1218,-1218,-1218},
+{ -249, -528, -528, -528, -528},
+{ -939,-1218,-1218,-1218,-1218},
+{ -329, -608, -608, -608, -608}},
+/* GU.UU..UA */
+{{  -50, -329, -329, -329, -329},
+{ -639, -918, -918, -918, -918},
+{ -229, -508, -508, -508, -508},
+{ -729,-1008,-1008,-1008,-1008},
+{ -190, -469, -469, -469, -469}}}},
+/* GU.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* GU.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* GU.A@.. @ */
+{{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AA.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AC.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AG.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* GU.AU.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}}},
+/* GU.C@.. @ */
+{{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CA.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CC.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CG.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* GU.CU.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}}},
+/* GU.G@.. @ */
+{{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GA.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GC.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GG.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* GU.GU.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}}},
+/* GU.U@.. @ */
+{{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UA.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UC.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UG.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* GU.UU.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}}}}},
+{ /* noPair */ {{{{0}}}},
+/* UG.@@..CG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* UG.@C..CG */
+{{    0,    0,    0,    0,    0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* UG.@G..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* UG.@U..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* UG.A@..CG */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..CG */
+{{  -50, -719, -789, -959, -809},
+{-1079,-1748,-1818,-1988,-1838},
+{ -569,-1238,-1308,-1478,-1328},
+{ -989,-1658,-1728,-1898,-1748},
+{ -859,-1528,-1598,-1768,-1618}},
+/* UG.AC..CG */
+{{  -50, -719, -789, -959, -809},
+{ -999,-1668,-1738,-1908,-1758},
+{ -499,-1168,-1238,-1408,-1258},
+{ -989,-1658,-1728,-1898,-1748},
+{ -789,-1458,-1528,-1698,-1548}},
+/* UG.AG..CG */
+{{  -50, -719, -789, -959, -809},
+{-1079,-1748,-1818,-1988,-1838},
+{ -569,-1238,-1308,-1478,-1328},
+{ -989,-1658,-1728,-1898,-1748},
+{ -859,-1528,-1598,-1768,-1618}},
+/* UG.AU..CG */
+{{  -50, -719, -789, -959, -809},
+{-1079,-1748,-1818,-1988,-1838},
+{ -719,-1388,-1458,-1628,-1478},
+{ -989,-1658,-1728,-1898,-1748},
+{ -909,-1578,-1648,-1818,-1668}}},
+/* UG.C@..CG */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..CG */
+{{  -50, -479, -479, -359, -479},
+{-1079,-1508,-1508,-1388,-1508},
+{ -569, -998, -998, -878, -998},
+{ -989,-1418,-1418,-1298,-1418},
+{ -859,-1288,-1288,-1168,-1288}},
+/* UG.CC..CG */
+{{  -50, -479, -479, -359, -479},
+{ -999,-1428,-1428,-1308,-1428},
+{ -499, -928, -928, -808, -928},
+{ -989,-1418,-1418,-1298,-1418},
+{ -789,-1218,-1218,-1098,-1218}},
+/* UG.CG..CG */
+{{  -50, -479, -479, -359, -479},
+{-1079,-1508,-1508,-1388,-1508},
+{ -569, -998, -998, -878, -998},
+{ -989,-1418,-1418,-1298,-1418},
+{ -859,-1288,-1288,-1168,-1288}},
+/* UG.CU..CG */
+{{  -50, -479, -479, -359, -479},
+{-1079,-1508,-1508,-1388,-1508},
+{ -719,-1148,-1148,-1028,-1148},
+{ -989,-1418,-1418,-1298,-1418},
+{ -909,-1338,-1338,-1218,-1338}}},
+/* UG.G@..CG */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..CG */
+{{  -50, -659, -809, -919, -809},
+{-1079,-1688,-1838,-1948,-1838},
+{ -569,-1178,-1328,-1438,-1328},
+{ -989,-1598,-1748,-1858,-1748},
+{ -859,-1468,-1618,-1728,-1618}},
+/* UG.GC..CG */
+{{  -50, -659, -809, -919, -809},
+{ -999,-1608,-1758,-1868,-1758},
+{ -499,-1108,-1258,-1368,-1258},
+{ -989,-1598,-1748,-1858,-1748},
+{ -789,-1398,-1548,-1658,-1548}},
+/* UG.GG..CG */
+{{  -50, -659, -809, -919, -809},
+{-1079,-1688,-1838,-1948,-1838},
+{ -569,-1178,-1328,-1438,-1328},
+{ -989,-1598,-1748,-1858,-1748},
+{ -859,-1468,-1618,-1728,-1618}},
+/* UG.GU..CG */
+{{  -50, -659, -809, -919, -809},
+{-1079,-1688,-1838,-1948,-1838},
+{ -719,-1328,-1478,-1588,-1478},
+{ -989,-1598,-1748,-1858,-1748},
+{ -909,-1518,-1668,-1778,-1668}}},
+/* UG.U@..CG */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..CG */
+{{  -50, -549, -439, -549, -359},
+{-1079,-1578,-1468,-1578,-1388},
+{ -569,-1068, -958,-1068, -878},
+{ -989,-1488,-1378,-1488,-1298},
+{ -859,-1358,-1248,-1358,-1168}},
+/* UG.UC..CG */
+{{  -50, -549, -439, -549, -359},
+{ -999,-1498,-1388,-1498,-1308},
+{ -499, -998, -888, -998, -808},
+{ -989,-1488,-1378,-1488,-1298},
+{ -789,-1288,-1178,-1288,-1098}},
+/* UG.UG..CG */
+{{  -50, -549, -439, -549, -359},
+{-1079,-1578,-1468,-1578,-1388},
+{ -569,-1068, -958,-1068, -878},
+{ -989,-1488,-1378,-1488,-1298},
+{ -859,-1358,-1248,-1358,-1168}},
+/* UG.UU..CG */
+{{  -50, -549, -439, -549, -359},
+{-1079,-1578,-1468,-1578,-1388},
+{ -719,-1218,-1108,-1218,-1028},
+{ -989,-1488,-1378,-1488,-1298},
+{ -909,-1408,-1298,-1408,-1218}}}},
+/* UG.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* UG.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* UG.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* UG.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* UG.A@..GC */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..GC */
+{{  -50, -719, -789, -959, -809},
+{ -569,-1238,-1308,-1478,-1328},
+{ -769,-1438,-1508,-1678,-1528},
+{ -759,-1428,-1498,-1668,-1518},
+{ -549,-1218,-1288,-1458,-1308}},
+/* UG.AC..GC */
+{{  -50, -719, -789, -959, -809},
+{ -929,-1598,-1668,-1838,-1688},
+{ -359,-1028,-1098,-1268,-1118},
+{ -789,-1458,-1528,-1698,-1548},
+{ -549,-1218,-1288,-1458,-1308}},
+/* UG.AG..GC */
+{{  -50, -719, -789, -959, -809},
+{ -609,-1278,-1348,-1518,-1368},
+{ -359,-1028,-1098,-1268,-1118},
+{ -669,-1338,-1408,-1578,-1428},
+{ -549,-1218,-1288,-1458,-1308}},
+/* UG.AU..GC */
+{{  -50, -719, -789, -959, -809},
+{ -929,-1598,-1668,-1838,-1688},
+{ -439,-1108,-1178,-1348,-1198},
+{ -789,-1458,-1528,-1698,-1548},
+{ -619,-1288,-1358,-1528,-1378}}},
+/* UG.C@..GC */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..GC */
+{{  -50, -479, -479, -359, -479},
+{ -569, -998, -998, -878, -998},
+{ -769,-1198,-1198,-1078,-1198},
+{ -759,-1188,-1188,-1068,-1188},
+{ -549, -978, -978, -858, -978}},
+/* UG.CC..GC */
+{{  -50, -479, -479, -359, -479},
+{ -929,-1358,-1358,-1238,-1358},
+{ -359, -788, -788, -668, -788},
+{ -789,-1218,-1218,-1098,-1218},
+{ -549, -978, -978, -858, -978}},
+/* UG.CG..GC */
+{{  -50, -479, -479, -359, -479},
+{ -609,-1038,-1038, -918,-1038},
+{ -359, -788, -788, -668, -788},
+{ -669,-1098,-1098, -978,-1098},
+{ -549, -978, -978, -858, -978}},
+/* UG.CU..GC */
+{{  -50, -479, -479, -359, -479},
+{ -929,-1358,-1358,-1238,-1358},
+{ -439, -868, -868, -748, -868},
+{ -789,-1218,-1218,-1098,-1218},
+{ -619,-1048,-1048, -928,-1048}}},
+/* UG.G@..GC */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..GC */
+{{  -50, -659, -809, -919, -809},
+{ -569,-1178,-1328,-1438,-1328},
+{ -769,-1378,-1528,-1638,-1528},
+{ -759,-1368,-1518,-1628,-1518},
+{ -549,-1158,-1308,-1418,-1308}},
+/* UG.GC..GC */
+{{  -50, -659, -809, -919, -809},
+{ -929,-1538,-1688,-1798,-1688},
+{ -359, -968,-1118,-1228,-1118},
+{ -789,-1398,-1548,-1658,-1548},
+{ -549,-1158,-1308,-1418,-1308}},
+/* UG.GG..GC */
+{{  -50, -659, -809, -919, -809},
+{ -609,-1218,-1368,-1478,-1368},
+{ -359, -968,-1118,-1228,-1118},
+{ -669,-1278,-1428,-1538,-1428},
+{ -549,-1158,-1308,-1418,-1308}},
+/* UG.GU..GC */
+{{  -50, -659, -809, -919, -809},
+{ -929,-1538,-1688,-1798,-1688},
+{ -439,-1048,-1198,-1308,-1198},
+{ -789,-1398,-1548,-1658,-1548},
+{ -619,-1228,-1378,-1488,-1378}}},
+/* UG.U@..GC */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..GC */
+{{  -50, -549, -439, -549, -359},
+{ -569,-1068, -958,-1068, -878},
+{ -769,-1268,-1158,-1268,-1078},
+{ -759,-1258,-1148,-1258,-1068},
+{ -549,-1048, -938,-1048, -858}},
+/* UG.UC..GC */
+{{  -50, -549, -439, -549, -359},
+{ -929,-1428,-1318,-1428,-1238},
+{ -359, -858, -748, -858, -668},
+{ -789,-1288,-1178,-1288,-1098},
+{ -549,-1048, -938,-1048, -858}},
+/* UG.UG..GC */
+{{  -50, -549, -439, -549, -359},
+{ -609,-1108, -998,-1108, -918},
+{ -359, -858, -748, -858, -668},
+{ -669,-1168,-1058,-1168, -978},
+{ -549,-1048, -938,-1048, -858}},
+/* UG.UU..GC */
+{{  -50, -549, -439, -549, -359},
+{ -929,-1428,-1318,-1428,-1238},
+{ -439, -938, -828, -938, -748},
+{ -789,-1288,-1178,-1288,-1098},
+{ -619,-1118,-1008,-1118, -928}}}},
+/* UG.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* UG.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UG.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UG.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* UG.A@..GU */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..GU */
+{{  -50, -719, -789, -959, -809},
+{ -479,-1148,-1218,-1388,-1238},
+{ -309, -978,-1048,-1218,-1068},
+{ -389,-1058,-1128,-1298,-1148},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AC..GU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AG..GU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AU..GU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}}},
+/* UG.C@..GU */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..GU */
+{{  -50, -479, -479, -359, -479},
+{ -479, -908, -908, -788, -908},
+{ -309, -738, -738, -618, -738},
+{ -389, -818, -818, -698, -818},
+{ -379, -808, -808, -688, -808}},
+/* UG.CC..GU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}},
+/* UG.CG..GU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}},
+/* UG.CU..GU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}}},
+/* UG.G@..GU */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..GU */
+{{  -50, -659, -809, -919, -809},
+{ -479,-1088,-1238,-1348,-1238},
+{ -309, -918,-1068,-1178,-1068},
+{ -389, -998,-1148,-1258,-1148},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GC..GU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GG..GU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GU..GU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}}},
+/* UG.U@..GU */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..GU */
+{{  -50, -549, -439, -549, -359},
+{ -479, -978, -868, -978, -788},
+{ -309, -808, -698, -808, -618},
+{ -389, -888, -778, -888, -698},
+{ -379, -878, -768, -878, -688}},
+/* UG.UC..GU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}},
+/* UG.UG..GU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}},
+/* UG.UU..GU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}}}},
+/* UG.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* UG.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* UG.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* UG.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* UG.A@..UG */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..UG */
+{{  -50, -719, -789, -959, -809},
+{ -769,-1438,-1508,-1678,-1528},
+{ -529,-1198,-1268,-1438,-1288},
+{ -709,-1378,-1448,-1618,-1468},
+{ -599,-1268,-1338,-1508,-1358}},
+/* UG.AC..UG */
+{{  -50, -719, -789, -959, -809},
+{ -839,-1508,-1578,-1748,-1598},
+{ -529,-1198,-1268,-1438,-1288},
+{ -859,-1528,-1598,-1768,-1618},
+{ -489,-1158,-1228,-1398,-1248}},
+/* UG.AG..UG */
+{{  -50, -719, -789, -959, -809},
+{-1009,-1678,-1748,-1918,-1768},
+{ -409,-1078,-1148,-1318,-1168},
+{ -969,-1638,-1708,-1878,-1728},
+{ -599,-1268,-1338,-1508,-1358}},
+/* UG.AU..UG */
+{{  -50, -719, -789, -959, -809},
+{ -859,-1528,-1598,-1768,-1618},
+{ -529,-1198,-1268,-1438,-1288},
+{ -859,-1528,-1598,-1768,-1618},
+{ -409,-1078,-1148,-1318,-1168}}},
+/* UG.C@..UG */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..UG */
+{{  -50, -479, -479, -359, -479},
+{ -769,-1198,-1198,-1078,-1198},
+{ -529, -958, -958, -838, -958},
+{ -709,-1138,-1138,-1018,-1138},
+{ -599,-1028,-1028, -908,-1028}},
+/* UG.CC..UG */
+{{  -50, -479, -479, -359, -479},
+{ -839,-1268,-1268,-1148,-1268},
+{ -529, -958, -958, -838, -958},
+{ -859,-1288,-1288,-1168,-1288},
+{ -489, -918, -918, -798, -918}},
+/* UG.CG..UG */
+{{  -50, -479, -479, -359, -479},
+{-1009,-1438,-1438,-1318,-1438},
+{ -409, -838, -838, -718, -838},
+{ -969,-1398,-1398,-1278,-1398},
+{ -599,-1028,-1028, -908,-1028}},
+/* UG.CU..UG */
+{{  -50, -479, -479, -359, -479},
+{ -859,-1288,-1288,-1168,-1288},
+{ -529, -958, -958, -838, -958},
+{ -859,-1288,-1288,-1168,-1288},
+{ -409, -838, -838, -718, -838}}},
+/* UG.G@..UG */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..UG */
+{{  -50, -659, -809, -919, -809},
+{ -769,-1378,-1528,-1638,-1528},
+{ -529,-1138,-1288,-1398,-1288},
+{ -709,-1318,-1468,-1578,-1468},
+{ -599,-1208,-1358,-1468,-1358}},
+/* UG.GC..UG */
+{{  -50, -659, -809, -919, -809},
+{ -839,-1448,-1598,-1708,-1598},
+{ -529,-1138,-1288,-1398,-1288},
+{ -859,-1468,-1618,-1728,-1618},
+{ -489,-1098,-1248,-1358,-1248}},
+/* UG.GG..UG */
+{{  -50, -659, -809, -919, -809},
+{-1009,-1618,-1768,-1878,-1768},
+{ -409,-1018,-1168,-1278,-1168},
+{ -969,-1578,-1728,-1838,-1728},
+{ -599,-1208,-1358,-1468,-1358}},
+/* UG.GU..UG */
+{{  -50, -659, -809, -919, -809},
+{ -859,-1468,-1618,-1728,-1618},
+{ -529,-1138,-1288,-1398,-1288},
+{ -859,-1468,-1618,-1728,-1618},
+{ -409,-1018,-1168,-1278,-1168}}},
+/* UG.U@..UG */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..UG */
+{{  -50, -549, -439, -549, -359},
+{ -769,-1268,-1158,-1268,-1078},
+{ -529,-1028, -918,-1028, -838},
+{ -709,-1208,-1098,-1208,-1018},
+{ -599,-1098, -988,-1098, -908}},
+/* UG.UC..UG */
+{{  -50, -549, -439, -549, -359},
+{ -839,-1338,-1228,-1338,-1148},
+{ -529,-1028, -918,-1028, -838},
+{ -859,-1358,-1248,-1358,-1168},
+{ -489, -988, -878, -988, -798}},
+/* UG.UG..UG */
+{{  -50, -549, -439, -549, -359},
+{-1009,-1508,-1398,-1508,-1318},
+{ -409, -908, -798, -908, -718},
+{ -969,-1468,-1358,-1468,-1278},
+{ -599,-1098, -988,-1098, -908}},
+/* UG.UU..UG */
+{{  -50, -549, -439, -549, -359},
+{ -859,-1358,-1248,-1358,-1168},
+{ -529,-1028, -918,-1028, -838},
+{ -859,-1358,-1248,-1358,-1168},
+{ -409, -908, -798, -908, -718}}}},
+/* UG.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* UG.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UG.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UG.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* UG.A@..AU */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..AU */
+{{  -50, -719, -789, -959, -809},
+{ -479,-1148,-1218,-1388,-1238},
+{ -309, -978,-1048,-1218,-1068},
+{ -389,-1058,-1128,-1298,-1148},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AC..AU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AG..AU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}},
+/* UG.AU..AU */
+{{  -50, -719, -789, -959, -809},
+{ -649,-1318,-1388,-1558,-1408},
+{ -289, -958,-1028,-1198,-1048},
+{ -739,-1408,-1478,-1648,-1498},
+{ -379,-1048,-1118,-1288,-1138}}},
+/* UG.C@..AU */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..AU */
+{{  -50, -479, -479, -359, -479},
+{ -479, -908, -908, -788, -908},
+{ -309, -738, -738, -618, -738},
+{ -389, -818, -818, -698, -818},
+{ -379, -808, -808, -688, -808}},
+/* UG.CC..AU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}},
+/* UG.CG..AU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}},
+/* UG.CU..AU */
+{{  -50, -479, -479, -359, -479},
+{ -649,-1078,-1078, -958,-1078},
+{ -289, -718, -718, -598, -718},
+{ -739,-1168,-1168,-1048,-1168},
+{ -379, -808, -808, -688, -808}}},
+/* UG.G@..AU */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..AU */
+{{  -50, -659, -809, -919, -809},
+{ -479,-1088,-1238,-1348,-1238},
+{ -309, -918,-1068,-1178,-1068},
+{ -389, -998,-1148,-1258,-1148},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GC..AU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GG..AU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}},
+/* UG.GU..AU */
+{{  -50, -659, -809, -919, -809},
+{ -649,-1258,-1408,-1518,-1408},
+{ -289, -898,-1048,-1158,-1048},
+{ -739,-1348,-1498,-1608,-1498},
+{ -379, -988,-1138,-1248,-1138}}},
+/* UG.U@..AU */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..AU */
+{{  -50, -549, -439, -549, -359},
+{ -479, -978, -868, -978, -788},
+{ -309, -808, -698, -808, -618},
+{ -389, -888, -778, -888, -698},
+{ -379, -878, -768, -878, -688}},
+/* UG.UC..AU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}},
+/* UG.UG..AU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}},
+/* UG.UU..AU */
+{{  -50, -549, -439, -549, -359},
+{ -649,-1148,-1038,-1148, -958},
+{ -289, -788, -678, -788, -598},
+{ -739,-1238,-1128,-1238,-1048},
+{ -379, -878, -768, -878, -688}}}},
+/* UG.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* UG.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* UG.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* UG.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* UG.A@..UA */
+{{{  -50, -719, -789, -959, -809},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA..UA */
+{{  -50, -719, -789, -959, -809},
+{ -449,-1118,-1188,-1358,-1208},
+{ -479,-1148,-1218,-1388,-1238},
+{ -429,-1098,-1168,-1338,-1188},
+{ -329, -998,-1068,-1238,-1088}},
+/* UG.AC..UA */
+{{  -50, -719, -789, -959, -809},
+{ -679,-1348,-1418,-1588,-1438},
+{ -559,-1228,-1298,-1468,-1318},
+{ -729,-1398,-1468,-1638,-1488},
+{ -189, -858, -928,-1098, -948}},
+/* UG.AG..UA */
+{{  -50, -719, -789, -959, -809},
+{ -939,-1608,-1678,-1848,-1698},
+{ -249, -918, -988,-1158,-1008},
+{ -939,-1608,-1678,-1848,-1698},
+{ -329, -998,-1068,-1238,-1088}},
+/* UG.AU..UA */
+{{  -50, -719, -789, -959, -809},
+{ -639,-1308,-1378,-1548,-1398},
+{ -229, -898, -968,-1138, -988},
+{ -729,-1398,-1468,-1638,-1488},
+{ -190, -859, -929,-1099, -949}}},
+/* UG.C@..UA */
+{{{  -50, -479, -479, -359, -479},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA..UA */
+{{  -50, -479, -479, -359, -479},
+{ -449, -878, -878, -758, -878},
+{ -479, -908, -908, -788, -908},
+{ -429, -858, -858, -738, -858},
+{ -329, -758, -758, -638, -758}},
+/* UG.CC..UA */
+{{  -50, -479, -479, -359, -479},
+{ -679,-1108,-1108, -988,-1108},
+{ -559, -988, -988, -868, -988},
+{ -729,-1158,-1158,-1038,-1158},
+{ -189, -618, -618, -498, -618}},
+/* UG.CG..UA */
+{{  -50, -479, -479, -359, -479},
+{ -939,-1368,-1368,-1248,-1368},
+{ -249, -678, -678, -558, -678},
+{ -939,-1368,-1368,-1248,-1368},
+{ -329, -758, -758, -638, -758}},
+/* UG.CU..UA */
+{{  -50, -479, -479, -359, -479},
+{ -639,-1068,-1068, -948,-1068},
+{ -229, -658, -658, -538, -658},
+{ -729,-1158,-1158,-1038,-1158},
+{ -190, -619, -619, -499, -619}}},
+/* UG.G@..UA */
+{{{  -50, -659, -809, -919, -809},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA..UA */
+{{  -50, -659, -809, -919, -809},
+{ -449,-1058,-1208,-1318,-1208},
+{ -479,-1088,-1238,-1348,-1238},
+{ -429,-1038,-1188,-1298,-1188},
+{ -329, -938,-1088,-1198,-1088}},
+/* UG.GC..UA */
+{{  -50, -659, -809, -919, -809},
+{ -679,-1288,-1438,-1548,-1438},
+{ -559,-1168,-1318,-1428,-1318},
+{ -729,-1338,-1488,-1598,-1488},
+{ -189, -798, -948,-1058, -948}},
+/* UG.GG..UA */
+{{  -50, -659, -809, -919, -809},
+{ -939,-1548,-1698,-1808,-1698},
+{ -249, -858,-1008,-1118,-1008},
+{ -939,-1548,-1698,-1808,-1698},
+{ -329, -938,-1088,-1198,-1088}},
+/* UG.GU..UA */
+{{  -50, -659, -809, -919, -809},
+{ -639,-1248,-1398,-1508,-1398},
+{ -229, -838, -988,-1098, -988},
+{ -729,-1338,-1488,-1598,-1488},
+{ -190, -799, -949,-1059, -949}}},
+/* UG.U@..UA */
+{{{  -50, -549, -439, -549, -359},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA..UA */
+{{  -50, -549, -439, -549, -359},
+{ -449, -948, -838, -948, -758},
+{ -479, -978, -868, -978, -788},
+{ -429, -928, -818, -928, -738},
+{ -329, -828, -718, -828, -638}},
+/* UG.UC..UA */
+{{  -50, -549, -439, -549, -359},
+{ -679,-1178,-1068,-1178, -988},
+{ -559,-1058, -948,-1058, -868},
+{ -729,-1228,-1118,-1228,-1038},
+{ -189, -688, -578, -688, -498}},
+/* UG.UG..UA */
+{{  -50, -549, -439, -549, -359},
+{ -939,-1438,-1328,-1438,-1248},
+{ -249, -748, -638, -748, -558},
+{ -939,-1438,-1328,-1438,-1248},
+{ -329, -828, -718, -828, -638}},
+/* UG.UU..UA */
+{{  -50, -549, -439, -549, -359},
+{ -639,-1138,-1028,-1138, -948},
+{ -229, -728, -618, -728, -538},
+{ -729,-1228,-1118,-1228,-1038},
+{ -190, -689, -579, -689, -499}}}},
+/* UG.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UG.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* UG.A@.. @ */
+{{{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AA.. @ */
+{{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AC.. @ */
+{{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AG.. @ */
+{{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}},
+/* UG.AU.. @ */
+{{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859},
+{ -100, -769, -839,-1009, -859}}},
+/* UG.C@.. @ */
+{{{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CA.. @ */
+{{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CC.. @ */
+{{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CG.. @ */
+{{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}},
+/* UG.CU.. @ */
+{{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529},
+{ -100, -529, -529, -409, -529}}},
+/* UG.G@.. @ */
+{{{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GA.. @ */
+{{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GC.. @ */
+{{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GG.. @ */
+{{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}},
+/* UG.GU.. @ */
+{{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859},
+{ -100, -709, -859, -969, -859}}},
+/* UG.U@.. @ */
+{{{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UA.. @ */
+{{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UC.. @ */
+{{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UG.. @ */
+{{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}},
+/* UG.UU.. @ */
+{{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409},
+{ -100, -599, -489, -599, -409}}}}},
+{ /* noPair */ {{{{0}}}},
+/* AU.@@..CG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* AU.@C..CG */
+{{    0,    0,    0,    0,    0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* AU.@G..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* AU.@U..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* AU.A@..CG */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -569, -948,-1118,-1118,-1118},
+{ -989,-1368,-1538,-1538,-1538},
+{ -859,-1238,-1408,-1408,-1408}},
+/* AU.AC..CG */
+{{  -50, -429, -599, -599, -599},
+{ -999,-1378,-1548,-1548,-1548},
+{ -499, -878,-1048,-1048,-1048},
+{ -989,-1368,-1538,-1538,-1538},
+{ -789,-1168,-1338,-1338,-1338}},
+/* AU.AG..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -569, -948,-1118,-1118,-1118},
+{ -989,-1368,-1538,-1538,-1538},
+{ -859,-1238,-1408,-1408,-1408}},
+/* AU.AU..CG */
+{{  -50, -429, -599, -599, -599},
+{-1079,-1458,-1628,-1628,-1628},
+{ -719,-1098,-1268,-1268,-1268},
+{ -989,-1368,-1538,-1538,-1538},
+{ -909,-1288,-1458,-1458,-1458}}},
+/* AU.C@..CG */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -569, -778, -758, -758, -758},
+{ -989,-1198,-1178,-1178,-1178},
+{ -859,-1068,-1048,-1048,-1048}},
+/* AU.CC..CG */
+{{  -50, -259, -239, -239, -239},
+{ -999,-1208,-1188,-1188,-1188},
+{ -499, -708, -688, -688, -688},
+{ -989,-1198,-1178,-1178,-1178},
+{ -789, -998, -978, -978, -978}},
+/* AU.CG..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -569, -778, -758, -758, -758},
+{ -989,-1198,-1178,-1178,-1178},
+{ -859,-1068,-1048,-1048,-1048}},
+/* AU.CU..CG */
+{{  -50, -259, -239, -239, -239},
+{-1079,-1288,-1268,-1268,-1268},
+{ -719, -928, -908, -908, -908},
+{ -989,-1198,-1178,-1178,-1178},
+{ -909,-1118,-1098,-1098,-1098}}},
+/* AU.G@..CG */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -569, -858,-1208,-1208,-1208},
+{ -989,-1278,-1628,-1628,-1628},
+{ -859,-1148,-1498,-1498,-1498}},
+/* AU.GC..CG */
+{{  -50, -339, -689, -689, -689},
+{ -999,-1288,-1638,-1638,-1638},
+{ -499, -788,-1138,-1138,-1138},
+{ -989,-1278,-1628,-1628,-1628},
+{ -789,-1078,-1428,-1428,-1428}},
+/* AU.GG..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -569, -858,-1208,-1208,-1208},
+{ -989,-1278,-1628,-1628,-1628},
+{ -859,-1148,-1498,-1498,-1498}},
+/* AU.GU..CG */
+{{  -50, -339, -689, -689, -689},
+{-1079,-1368,-1718,-1718,-1718},
+{ -719,-1008,-1358,-1358,-1358},
+{ -989,-1278,-1628,-1628,-1628},
+{ -909,-1198,-1548,-1548,-1548}}},
+/* AU.U@..CG */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -569, -848, -848, -848, -848},
+{ -989,-1268,-1268,-1268,-1268},
+{ -859,-1138,-1138,-1138,-1138}},
+/* AU.UC..CG */
+{{  -50, -329, -329, -329, -329},
+{ -999,-1278,-1278,-1278,-1278},
+{ -499, -778, -778, -778, -778},
+{ -989,-1268,-1268,-1268,-1268},
+{ -789,-1068,-1068,-1068,-1068}},
+/* AU.UG..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -569, -848, -848, -848, -848},
+{ -989,-1268,-1268,-1268,-1268},
+{ -859,-1138,-1138,-1138,-1138}},
+/* AU.UU..CG */
+{{  -50, -329, -329, -329, -329},
+{-1079,-1358,-1358,-1358,-1358},
+{ -719, -998, -998, -998, -998},
+{ -989,-1268,-1268,-1268,-1268},
+{ -909,-1188,-1188,-1188,-1188}}}},
+/* AU.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* AU.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* AU.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* AU.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* AU.A@..GC */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..GC */
+{{  -50, -429, -599, -599, -599},
+{ -569, -948,-1118,-1118,-1118},
+{ -769,-1148,-1318,-1318,-1318},
+{ -759,-1138,-1308,-1308,-1308},
+{ -549, -928,-1098,-1098,-1098}},
+/* AU.AC..GC */
+{{  -50, -429, -599, -599, -599},
+{ -929,-1308,-1478,-1478,-1478},
+{ -359, -738, -908, -908, -908},
+{ -789,-1168,-1338,-1338,-1338},
+{ -549, -928,-1098,-1098,-1098}},
+/* AU.AG..GC */
+{{  -50, -429, -599, -599, -599},
+{ -609, -988,-1158,-1158,-1158},
+{ -359, -738, -908, -908, -908},
+{ -669,-1048,-1218,-1218,-1218},
+{ -549, -928,-1098,-1098,-1098}},
+/* AU.AU..GC */
+{{  -50, -429, -599, -599, -599},
+{ -929,-1308,-1478,-1478,-1478},
+{ -439, -818, -988, -988, -988},
+{ -789,-1168,-1338,-1338,-1338},
+{ -619, -998,-1168,-1168,-1168}}},
+/* AU.C@..GC */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..GC */
+{{  -50, -259, -239, -239, -239},
+{ -569, -778, -758, -758, -758},
+{ -769, -978, -958, -958, -958},
+{ -759, -968, -948, -948, -948},
+{ -549, -758, -738, -738, -738}},
+/* AU.CC..GC */
+{{  -50, -259, -239, -239, -239},
+{ -929,-1138,-1118,-1118,-1118},
+{ -359, -568, -548, -548, -548},
+{ -789, -998, -978, -978, -978},
+{ -549, -758, -738, -738, -738}},
+/* AU.CG..GC */
+{{  -50, -259, -239, -239, -239},
+{ -609, -818, -798, -798, -798},
+{ -359, -568, -548, -548, -548},
+{ -669, -878, -858, -858, -858},
+{ -549, -758, -738, -738, -738}},
+/* AU.CU..GC */
+{{  -50, -259, -239, -239, -239},
+{ -929,-1138,-1118,-1118,-1118},
+{ -439, -648, -628, -628, -628},
+{ -789, -998, -978, -978, -978},
+{ -619, -828, -808, -808, -808}}},
+/* AU.G@..GC */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..GC */
+{{  -50, -339, -689, -689, -689},
+{ -569, -858,-1208,-1208,-1208},
+{ -769,-1058,-1408,-1408,-1408},
+{ -759,-1048,-1398,-1398,-1398},
+{ -549, -838,-1188,-1188,-1188}},
+/* AU.GC..GC */
+{{  -50, -339, -689, -689, -689},
+{ -929,-1218,-1568,-1568,-1568},
+{ -359, -648, -998, -998, -998},
+{ -789,-1078,-1428,-1428,-1428},
+{ -549, -838,-1188,-1188,-1188}},
+/* AU.GG..GC */
+{{  -50, -339, -689, -689, -689},
+{ -609, -898,-1248,-1248,-1248},
+{ -359, -648, -998, -998, -998},
+{ -669, -958,-1308,-1308,-1308},
+{ -549, -838,-1188,-1188,-1188}},
+/* AU.GU..GC */
+{{  -50, -339, -689, -689, -689},
+{ -929,-1218,-1568,-1568,-1568},
+{ -439, -728,-1078,-1078,-1078},
+{ -789,-1078,-1428,-1428,-1428},
+{ -619, -908,-1258,-1258,-1258}}},
+/* AU.U@..GC */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..GC */
+{{  -50, -329, -329, -329, -329},
+{ -569, -848, -848, -848, -848},
+{ -769,-1048,-1048,-1048,-1048},
+{ -759,-1038,-1038,-1038,-1038},
+{ -549, -828, -828, -828, -828}},
+/* AU.UC..GC */
+{{  -50, -329, -329, -329, -329},
+{ -929,-1208,-1208,-1208,-1208},
+{ -359, -638, -638, -638, -638},
+{ -789,-1068,-1068,-1068,-1068},
+{ -549, -828, -828, -828, -828}},
+/* AU.UG..GC */
+{{  -50, -329, -329, -329, -329},
+{ -609, -888, -888, -888, -888},
+{ -359, -638, -638, -638, -638},
+{ -669, -948, -948, -948, -948},
+{ -549, -828, -828, -828, -828}},
+/* AU.UU..GC */
+{{  -50, -329, -329, -329, -329},
+{ -929,-1208,-1208,-1208,-1208},
+{ -439, -718, -718, -718, -718},
+{ -789,-1068,-1068,-1068,-1068},
+{ -619, -898, -898, -898, -898}}}},
+/* AU.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* AU.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* AU.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* AU.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* AU.A@..GU */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..GU */
+{{  -50, -429, -599, -599, -599},
+{ -479, -858,-1028,-1028,-1028},
+{ -309, -688, -858, -858, -858},
+{ -389, -768, -938, -938, -938},
+{ -379, -758, -928, -928, -928}},
+/* AU.AC..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* AU.AG..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* AU.AU..GU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}}},
+/* AU.C@..GU */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..GU */
+{{  -50, -259, -239, -239, -239},
+{ -479, -688, -668, -668, -668},
+{ -309, -518, -498, -498, -498},
+{ -389, -598, -578, -578, -578},
+{ -379, -588, -568, -568, -568}},
+/* AU.CC..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* AU.CG..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* AU.CU..GU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}}},
+/* AU.G@..GU */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..GU */
+{{  -50, -339, -689, -689, -689},
+{ -479, -768,-1118,-1118,-1118},
+{ -309, -598, -948, -948, -948},
+{ -389, -678,-1028,-1028,-1028},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GC..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GG..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GU..GU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}}},
+/* AU.U@..GU */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..GU */
+{{  -50, -329, -329, -329, -329},
+{ -479, -758, -758, -758, -758},
+{ -309, -588, -588, -588, -588},
+{ -389, -668, -668, -668, -668},
+{ -379, -658, -658, -658, -658}},
+/* AU.UC..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* AU.UG..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* AU.UU..GU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}}}},
+/* AU.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* AU.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* AU.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* AU.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* AU.A@..UG */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..UG */
+{{  -50, -429, -599, -599, -599},
+{ -769,-1148,-1318,-1318,-1318},
+{ -529, -908,-1078,-1078,-1078},
+{ -709,-1088,-1258,-1258,-1258},
+{ -599, -978,-1148,-1148,-1148}},
+/* AU.AC..UG */
+{{  -50, -429, -599, -599, -599},
+{ -839,-1218,-1388,-1388,-1388},
+{ -529, -908,-1078,-1078,-1078},
+{ -859,-1238,-1408,-1408,-1408},
+{ -489, -868,-1038,-1038,-1038}},
+/* AU.AG..UG */
+{{  -50, -429, -599, -599, -599},
+{-1009,-1388,-1558,-1558,-1558},
+{ -409, -788, -958, -958, -958},
+{ -969,-1348,-1518,-1518,-1518},
+{ -599, -978,-1148,-1148,-1148}},
+/* AU.AU..UG */
+{{  -50, -429, -599, -599, -599},
+{ -859,-1238,-1408,-1408,-1408},
+{ -529, -908,-1078,-1078,-1078},
+{ -859,-1238,-1408,-1408,-1408},
+{ -409, -788, -958, -958, -958}}},
+/* AU.C@..UG */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..UG */
+{{  -50, -259, -239, -239, -239},
+{ -769, -978, -958, -958, -958},
+{ -529, -738, -718, -718, -718},
+{ -709, -918, -898, -898, -898},
+{ -599, -808, -788, -788, -788}},
+/* AU.CC..UG */
+{{  -50, -259, -239, -239, -239},
+{ -839,-1048,-1028,-1028,-1028},
+{ -529, -738, -718, -718, -718},
+{ -859,-1068,-1048,-1048,-1048},
+{ -489, -698, -678, -678, -678}},
+/* AU.CG..UG */
+{{  -50, -259, -239, -239, -239},
+{-1009,-1218,-1198,-1198,-1198},
+{ -409, -618, -598, -598, -598},
+{ -969,-1178,-1158,-1158,-1158},
+{ -599, -808, -788, -788, -788}},
+/* AU.CU..UG */
+{{  -50, -259, -239, -239, -239},
+{ -859,-1068,-1048,-1048,-1048},
+{ -529, -738, -718, -718, -718},
+{ -859,-1068,-1048,-1048,-1048},
+{ -409, -618, -598, -598, -598}}},
+/* AU.G@..UG */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..UG */
+{{  -50, -339, -689, -689, -689},
+{ -769,-1058,-1408,-1408,-1408},
+{ -529, -818,-1168,-1168,-1168},
+{ -709, -998,-1348,-1348,-1348},
+{ -599, -888,-1238,-1238,-1238}},
+/* AU.GC..UG */
+{{  -50, -339, -689, -689, -689},
+{ -839,-1128,-1478,-1478,-1478},
+{ -529, -818,-1168,-1168,-1168},
+{ -859,-1148,-1498,-1498,-1498},
+{ -489, -778,-1128,-1128,-1128}},
+/* AU.GG..UG */
+{{  -50, -339, -689, -689, -689},
+{-1009,-1298,-1648,-1648,-1648},
+{ -409, -698,-1048,-1048,-1048},
+{ -969,-1258,-1608,-1608,-1608},
+{ -599, -888,-1238,-1238,-1238}},
+/* AU.GU..UG */
+{{  -50, -339, -689, -689, -689},
+{ -859,-1148,-1498,-1498,-1498},
+{ -529, -818,-1168,-1168,-1168},
+{ -859,-1148,-1498,-1498,-1498},
+{ -409, -698,-1048,-1048,-1048}}},
+/* AU.U@..UG */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..UG */
+{{  -50, -329, -329, -329, -329},
+{ -769,-1048,-1048,-1048,-1048},
+{ -529, -808, -808, -808, -808},
+{ -709, -988, -988, -988, -988},
+{ -599, -878, -878, -878, -878}},
+/* AU.UC..UG */
+{{  -50, -329, -329, -329, -329},
+{ -839,-1118,-1118,-1118,-1118},
+{ -529, -808, -808, -808, -808},
+{ -859,-1138,-1138,-1138,-1138},
+{ -489, -768, -768, -768, -768}},
+/* AU.UG..UG */
+{{  -50, -329, -329, -329, -329},
+{-1009,-1288,-1288,-1288,-1288},
+{ -409, -688, -688, -688, -688},
+{ -969,-1248,-1248,-1248,-1248},
+{ -599, -878, -878, -878, -878}},
+/* AU.UU..UG */
+{{  -50, -329, -329, -329, -329},
+{ -859,-1138,-1138,-1138,-1138},
+{ -529, -808, -808, -808, -808},
+{ -859,-1138,-1138,-1138,-1138},
+{ -409, -688, -688, -688, -688}}}},
+/* AU.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* AU.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* AU.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* AU.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* AU.A@..AU */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..AU */
+{{  -50, -429, -599, -599, -599},
+{ -479, -858,-1028,-1028,-1028},
+{ -309, -688, -858, -858, -858},
+{ -389, -768, -938, -938, -938},
+{ -379, -758, -928, -928, -928}},
+/* AU.AC..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* AU.AG..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}},
+/* AU.AU..AU */
+{{  -50, -429, -599, -599, -599},
+{ -649,-1028,-1198,-1198,-1198},
+{ -289, -668, -838, -838, -838},
+{ -739,-1118,-1288,-1288,-1288},
+{ -379, -758, -928, -928, -928}}},
+/* AU.C@..AU */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..AU */
+{{  -50, -259, -239, -239, -239},
+{ -479, -688, -668, -668, -668},
+{ -309, -518, -498, -498, -498},
+{ -389, -598, -578, -578, -578},
+{ -379, -588, -568, -568, -568}},
+/* AU.CC..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* AU.CG..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}},
+/* AU.CU..AU */
+{{  -50, -259, -239, -239, -239},
+{ -649, -858, -838, -838, -838},
+{ -289, -498, -478, -478, -478},
+{ -739, -948, -928, -928, -928},
+{ -379, -588, -568, -568, -568}}},
+/* AU.G@..AU */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..AU */
+{{  -50, -339, -689, -689, -689},
+{ -479, -768,-1118,-1118,-1118},
+{ -309, -598, -948, -948, -948},
+{ -389, -678,-1028,-1028,-1028},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GC..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GG..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}},
+/* AU.GU..AU */
+{{  -50, -339, -689, -689, -689},
+{ -649, -938,-1288,-1288,-1288},
+{ -289, -578, -928, -928, -928},
+{ -739,-1028,-1378,-1378,-1378},
+{ -379, -668,-1018,-1018,-1018}}},
+/* AU.U@..AU */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..AU */
+{{  -50, -329, -329, -329, -329},
+{ -479, -758, -758, -758, -758},
+{ -309, -588, -588, -588, -588},
+{ -389, -668, -668, -668, -668},
+{ -379, -658, -658, -658, -658}},
+/* AU.UC..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* AU.UG..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}},
+/* AU.UU..AU */
+{{  -50, -329, -329, -329, -329},
+{ -649, -928, -928, -928, -928},
+{ -289, -568, -568, -568, -568},
+{ -739,-1018,-1018,-1018,-1018},
+{ -379, -658, -658, -658, -658}}}},
+/* AU.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* AU.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* AU.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* AU.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* AU.A@..UA */
+{{{  -50, -429, -599, -599, -599},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA..UA */
+{{  -50, -429, -599, -599, -599},
+{ -449, -828, -998, -998, -998},
+{ -479, -858,-1028,-1028,-1028},
+{ -429, -808, -978, -978, -978},
+{ -329, -708, -878, -878, -878}},
+/* AU.AC..UA */
+{{  -50, -429, -599, -599, -599},
+{ -679,-1058,-1228,-1228,-1228},
+{ -559, -938,-1108,-1108,-1108},
+{ -729,-1108,-1278,-1278,-1278},
+{ -189, -568, -738, -738, -738}},
+/* AU.AG..UA */
+{{  -50, -429, -599, -599, -599},
+{ -939,-1318,-1488,-1488,-1488},
+{ -249, -628, -798, -798, -798},
+{ -939,-1318,-1488,-1488,-1488},
+{ -329, -708, -878, -878, -878}},
+/* AU.AU..UA */
+{{  -50, -429, -599, -599, -599},
+{ -639,-1018,-1188,-1188,-1188},
+{ -229, -608, -778, -778, -778},
+{ -729,-1108,-1278,-1278,-1278},
+{ -190, -569, -739, -739, -739}}},
+/* AU.C@..UA */
+{{{  -50, -259, -239, -239, -239},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA..UA */
+{{  -50, -259, -239, -239, -239},
+{ -449, -658, -638, -638, -638},
+{ -479, -688, -668, -668, -668},
+{ -429, -638, -618, -618, -618},
+{ -329, -538, -518, -518, -518}},
+/* AU.CC..UA */
+{{  -50, -259, -239, -239, -239},
+{ -679, -888, -868, -868, -868},
+{ -559, -768, -748, -748, -748},
+{ -729, -938, -918, -918, -918},
+{ -189, -398, -378, -378, -378}},
+/* AU.CG..UA */
+{{  -50, -259, -239, -239, -239},
+{ -939,-1148,-1128,-1128,-1128},
+{ -249, -458, -438, -438, -438},
+{ -939,-1148,-1128,-1128,-1128},
+{ -329, -538, -518, -518, -518}},
+/* AU.CU..UA */
+{{  -50, -259, -239, -239, -239},
+{ -639, -848, -828, -828, -828},
+{ -229, -438, -418, -418, -418},
+{ -729, -938, -918, -918, -918},
+{ -190, -399, -379, -379, -379}}},
+/* AU.G@..UA */
+{{{  -50, -339, -689, -689, -689},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA..UA */
+{{  -50, -339, -689, -689, -689},
+{ -449, -738,-1088,-1088,-1088},
+{ -479, -768,-1118,-1118,-1118},
+{ -429, -718,-1068,-1068,-1068},
+{ -329, -618, -968, -968, -968}},
+/* AU.GC..UA */
+{{  -50, -339, -689, -689, -689},
+{ -679, -968,-1318,-1318,-1318},
+{ -559, -848,-1198,-1198,-1198},
+{ -729,-1018,-1368,-1368,-1368},
+{ -189, -478, -828, -828, -828}},
+/* AU.GG..UA */
+{{  -50, -339, -689, -689, -689},
+{ -939,-1228,-1578,-1578,-1578},
+{ -249, -538, -888, -888, -888},
+{ -939,-1228,-1578,-1578,-1578},
+{ -329, -618, -968, -968, -968}},
+/* AU.GU..UA */
+{{  -50, -339, -689, -689, -689},
+{ -639, -928,-1278,-1278,-1278},
+{ -229, -518, -868, -868, -868},
+{ -729,-1018,-1368,-1368,-1368},
+{ -190, -479, -829, -829, -829}}},
+/* AU.U@..UA */
+{{{  -50, -329, -329, -329, -329},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA..UA */
+{{  -50, -329, -329, -329, -329},
+{ -449, -728, -728, -728, -728},
+{ -479, -758, -758, -758, -758},
+{ -429, -708, -708, -708, -708},
+{ -329, -608, -608, -608, -608}},
+/* AU.UC..UA */
+{{  -50, -329, -329, -329, -329},
+{ -679, -958, -958, -958, -958},
+{ -559, -838, -838, -838, -838},
+{ -729,-1008,-1008,-1008,-1008},
+{ -189, -468, -468, -468, -468}},
+/* AU.UG..UA */
+{{  -50, -329, -329, -329, -329},
+{ -939,-1218,-1218,-1218,-1218},
+{ -249, -528, -528, -528, -528},
+{ -939,-1218,-1218,-1218,-1218},
+{ -329, -608, -608, -608, -608}},
+/* AU.UU..UA */
+{{  -50, -329, -329, -329, -329},
+{ -639, -918, -918, -918, -918},
+{ -229, -508, -508, -508, -508},
+{ -729,-1008,-1008,-1008,-1008},
+{ -190, -469, -469, -469, -469}}}},
+/* AU.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* AU.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* AU.A@.. @ */
+{{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AA.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AC.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AG.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}},
+/* AU.AU.. @ */
+{{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649},
+{ -100, -479, -649, -649, -649}}},
+/* AU.C@.. @ */
+{{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CA.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CC.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CG.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}},
+/* AU.CU.. @ */
+{{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289},
+{ -100, -309, -289, -289, -289}}},
+/* AU.G@.. @ */
+{{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GA.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GC.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GG.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}},
+/* AU.GU.. @ */
+{{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739},
+{ -100, -389, -739, -739, -739}}},
+/* AU.U@.. @ */
+{{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UA.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UC.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UG.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}},
+/* AU.UU.. @ */
+{{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379},
+{ -100, -379, -379, -379, -379}}}}},
+{ /* noPair */ {{{{0}}}},
+/* UA.@@..CG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* UA.@C..CG */
+{{    0,    0,    0,    0,    0},
+{ -949, -949, -949, -949, -949},
+{ -449, -449, -449, -449, -449},
+{ -939, -939, -939, -939, -939},
+{ -739, -739, -739, -739, -739}},
+/* UA.@G..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -519, -519, -519, -519, -519},
+{ -939, -939, -939, -939, -939},
+{ -809, -809, -809, -809, -809}},
+/* UA.@U..CG */
+{{    0,    0,    0,    0,    0},
+{-1029,-1029,-1029,-1029,-1029},
+{ -669, -669, -669, -669, -669},
+{ -939, -939, -939, -939, -939},
+{ -859, -859, -859, -859, -859}}},
+/* UA.A@..CG */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..CG */
+{{  -50, -399, -629, -889, -589},
+{-1079,-1428,-1658,-1918,-1618},
+{ -569, -918,-1148,-1408,-1108},
+{ -989,-1338,-1568,-1828,-1528},
+{ -859,-1208,-1438,-1698,-1398}},
+/* UA.AC..CG */
+{{  -50, -399, -629, -889, -589},
+{ -999,-1348,-1578,-1838,-1538},
+{ -499, -848,-1078,-1338,-1038},
+{ -989,-1338,-1568,-1828,-1528},
+{ -789,-1138,-1368,-1628,-1328}},
+/* UA.AG..CG */
+{{  -50, -399, -629, -889, -589},
+{-1079,-1428,-1658,-1918,-1618},
+{ -569, -918,-1148,-1408,-1108},
+{ -989,-1338,-1568,-1828,-1528},
+{ -859,-1208,-1438,-1698,-1398}},
+/* UA.AU..CG */
+{{  -50, -399, -629, -889, -589},
+{-1079,-1428,-1658,-1918,-1618},
+{ -719,-1068,-1298,-1558,-1258},
+{ -989,-1338,-1568,-1828,-1528},
+{ -909,-1258,-1488,-1748,-1448}}},
+/* UA.C@..CG */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..CG */
+{{  -50, -429, -509, -199, -179},
+{-1079,-1458,-1538,-1228,-1208},
+{ -569, -948,-1028, -718, -698},
+{ -989,-1368,-1448,-1138,-1118},
+{ -859,-1238,-1318,-1008, -988}},
+/* UA.CC..CG */
+{{  -50, -429, -509, -199, -179},
+{ -999,-1378,-1458,-1148,-1128},
+{ -499, -878, -958, -648, -628},
+{ -989,-1368,-1448,-1138,-1118},
+{ -789,-1168,-1248, -938, -918}},
+/* UA.CG..CG */
+{{  -50, -429, -509, -199, -179},
+{-1079,-1458,-1538,-1228,-1208},
+{ -569, -948,-1028, -718, -698},
+{ -989,-1368,-1448,-1138,-1118},
+{ -859,-1238,-1318,-1008, -988}},
+/* UA.CU..CG */
+{{  -50, -429, -509, -199, -179},
+{-1079,-1458,-1538,-1228,-1208},
+{ -719,-1098,-1178, -868, -848},
+{ -989,-1368,-1448,-1138,-1118},
+{ -909,-1288,-1368,-1058,-1038}}},
+/* UA.G@..CG */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..CG */
+{{  -50, -379, -679, -889, -679},
+{-1079,-1408,-1708,-1918,-1708},
+{ -569, -898,-1198,-1408,-1198},
+{ -989,-1318,-1618,-1828,-1618},
+{ -859,-1188,-1488,-1698,-1488}},
+/* UA.GC..CG */
+{{  -50, -379, -679, -889, -679},
+{ -999,-1328,-1628,-1838,-1628},
+{ -499, -828,-1128,-1338,-1128},
+{ -989,-1318,-1618,-1828,-1618},
+{ -789,-1118,-1418,-1628,-1418}},
+/* UA.GG..CG */
+{{  -50, -379, -679, -889, -679},
+{-1079,-1408,-1708,-1918,-1708},
+{ -569, -898,-1198,-1408,-1198},
+{ -989,-1318,-1618,-1828,-1618},
+{ -859,-1188,-1488,-1698,-1488}},
+/* UA.GU..CG */
+{{  -50, -379, -679, -889, -679},
+{-1079,-1408,-1708,-1918,-1708},
+{ -719,-1048,-1348,-1558,-1348},
+{ -989,-1318,-1618,-1828,-1618},
+{ -909,-1238,-1538,-1748,-1538}}},
+/* UA.U@..CG */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..CG */
+{{  -50, -279, -139, -279, -140},
+{-1079,-1308,-1168,-1308,-1169},
+{ -569, -798, -658, -798, -659},
+{ -989,-1218,-1078,-1218,-1079},
+{ -859,-1088, -948,-1088, -949}},
+/* UA.UC..CG */
+{{  -50, -279, -139, -279, -140},
+{ -999,-1228,-1088,-1228,-1089},
+{ -499, -728, -588, -728, -589},
+{ -989,-1218,-1078,-1218,-1079},
+{ -789,-1018, -878,-1018, -879}},
+/* UA.UG..CG */
+{{  -50, -279, -139, -279, -140},
+{-1079,-1308,-1168,-1308,-1169},
+{ -569, -798, -658, -798, -659},
+{ -989,-1218,-1078,-1218,-1079},
+{ -859,-1088, -948,-1088, -949}},
+/* UA.UU..CG */
+{{  -50, -279, -139, -279, -140},
+{-1079,-1308,-1168,-1308,-1169},
+{ -719, -948, -808, -948, -809},
+{ -989,-1218,-1078,-1218,-1079},
+{ -909,-1138, -998,-1138, -999}}}},
+/* UA.@@..GC */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..GC */
+{{    0,    0,    0,    0,    0},
+{ -519, -519, -519, -519, -519},
+{ -719, -719, -719, -719, -719},
+{ -709, -709, -709, -709, -709},
+{ -499, -499, -499, -499, -499}},
+/* UA.@C..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -309, -309, -309, -309, -309},
+{ -739, -739, -739, -739, -739},
+{ -499, -499, -499, -499, -499}},
+/* UA.@G..GC */
+{{    0,    0,    0,    0,    0},
+{ -559, -559, -559, -559, -559},
+{ -309, -309, -309, -309, -309},
+{ -619, -619, -619, -619, -619},
+{ -499, -499, -499, -499, -499}},
+/* UA.@U..GC */
+{{    0,    0,    0,    0,    0},
+{ -879, -879, -879, -879, -879},
+{ -389, -389, -389, -389, -389},
+{ -739, -739, -739, -739, -739},
+{ -569, -569, -569, -569, -569}}},
+/* UA.A@..GC */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..GC */
+{{  -50, -399, -629, -889, -589},
+{ -569, -918,-1148,-1408,-1108},
+{ -769,-1118,-1348,-1608,-1308},
+{ -759,-1108,-1338,-1598,-1298},
+{ -549, -898,-1128,-1388,-1088}},
+/* UA.AC..GC */
+{{  -50, -399, -629, -889, -589},
+{ -929,-1278,-1508,-1768,-1468},
+{ -359, -708, -938,-1198, -898},
+{ -789,-1138,-1368,-1628,-1328},
+{ -549, -898,-1128,-1388,-1088}},
+/* UA.AG..GC */
+{{  -50, -399, -629, -889, -589},
+{ -609, -958,-1188,-1448,-1148},
+{ -359, -708, -938,-1198, -898},
+{ -669,-1018,-1248,-1508,-1208},
+{ -549, -898,-1128,-1388,-1088}},
+/* UA.AU..GC */
+{{  -50, -399, -629, -889, -589},
+{ -929,-1278,-1508,-1768,-1468},
+{ -439, -788,-1018,-1278, -978},
+{ -789,-1138,-1368,-1628,-1328},
+{ -619, -968,-1198,-1458,-1158}}},
+/* UA.C@..GC */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..GC */
+{{  -50, -429, -509, -199, -179},
+{ -569, -948,-1028, -718, -698},
+{ -769,-1148,-1228, -918, -898},
+{ -759,-1138,-1218, -908, -888},
+{ -549, -928,-1008, -698, -678}},
+/* UA.CC..GC */
+{{  -50, -429, -509, -199, -179},
+{ -929,-1308,-1388,-1078,-1058},
+{ -359, -738, -818, -508, -488},
+{ -789,-1168,-1248, -938, -918},
+{ -549, -928,-1008, -698, -678}},
+/* UA.CG..GC */
+{{  -50, -429, -509, -199, -179},
+{ -609, -988,-1068, -758, -738},
+{ -359, -738, -818, -508, -488},
+{ -669,-1048,-1128, -818, -798},
+{ -549, -928,-1008, -698, -678}},
+/* UA.CU..GC */
+{{  -50, -429, -509, -199, -179},
+{ -929,-1308,-1388,-1078,-1058},
+{ -439, -818, -898, -588, -568},
+{ -789,-1168,-1248, -938, -918},
+{ -619, -998,-1078, -768, -748}}},
+/* UA.G@..GC */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..GC */
+{{  -50, -379, -679, -889, -679},
+{ -569, -898,-1198,-1408,-1198},
+{ -769,-1098,-1398,-1608,-1398},
+{ -759,-1088,-1388,-1598,-1388},
+{ -549, -878,-1178,-1388,-1178}},
+/* UA.GC..GC */
+{{  -50, -379, -679, -889, -679},
+{ -929,-1258,-1558,-1768,-1558},
+{ -359, -688, -988,-1198, -988},
+{ -789,-1118,-1418,-1628,-1418},
+{ -549, -878,-1178,-1388,-1178}},
+/* UA.GG..GC */
+{{  -50, -379, -679, -889, -679},
+{ -609, -938,-1238,-1448,-1238},
+{ -359, -688, -988,-1198, -988},
+{ -669, -998,-1298,-1508,-1298},
+{ -549, -878,-1178,-1388,-1178}},
+/* UA.GU..GC */
+{{  -50, -379, -679, -889, -679},
+{ -929,-1258,-1558,-1768,-1558},
+{ -439, -768,-1068,-1278,-1068},
+{ -789,-1118,-1418,-1628,-1418},
+{ -619, -948,-1248,-1458,-1248}}},
+/* UA.U@..GC */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..GC */
+{{  -50, -279, -139, -279, -140},
+{ -569, -798, -658, -798, -659},
+{ -769, -998, -858, -998, -859},
+{ -759, -988, -848, -988, -849},
+{ -549, -778, -638, -778, -639}},
+/* UA.UC..GC */
+{{  -50, -279, -139, -279, -140},
+{ -929,-1158,-1018,-1158,-1019},
+{ -359, -588, -448, -588, -449},
+{ -789,-1018, -878,-1018, -879},
+{ -549, -778, -638, -778, -639}},
+/* UA.UG..GC */
+{{  -50, -279, -139, -279, -140},
+{ -609, -838, -698, -838, -699},
+{ -359, -588, -448, -588, -449},
+{ -669, -898, -758, -898, -759},
+{ -549, -778, -638, -778, -639}},
+/* UA.UU..GC */
+{{  -50, -279, -139, -279, -140},
+{ -929,-1158,-1018,-1158,-1019},
+{ -439, -668, -528, -668, -529},
+{ -789,-1018, -878,-1018, -879},
+{ -619, -848, -708, -848, -709}}}},
+/* UA.@@..GU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..GU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* UA.@C..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UA.@G..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UA.@U..GU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* UA.A@..GU */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..GU */
+{{  -50, -399, -629, -889, -589},
+{ -479, -828,-1058,-1318,-1018},
+{ -309, -658, -888,-1148, -848},
+{ -389, -738, -968,-1228, -928},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AC..GU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AG..GU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AU..GU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}}},
+/* UA.C@..GU */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..GU */
+{{  -50, -429, -509, -199, -179},
+{ -479, -858, -938, -628, -608},
+{ -309, -688, -768, -458, -438},
+{ -389, -768, -848, -538, -518},
+{ -379, -758, -838, -528, -508}},
+/* UA.CC..GU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}},
+/* UA.CG..GU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}},
+/* UA.CU..GU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}}},
+/* UA.G@..GU */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..GU */
+{{  -50, -379, -679, -889, -679},
+{ -479, -808,-1108,-1318,-1108},
+{ -309, -638, -938,-1148, -938},
+{ -389, -718,-1018,-1228,-1018},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GC..GU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GG..GU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GU..GU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}}},
+/* UA.U@..GU */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..GU */
+{{  -50, -279, -139, -279, -140},
+{ -479, -708, -568, -708, -569},
+{ -309, -538, -398, -538, -399},
+{ -389, -618, -478, -618, -479},
+{ -379, -608, -468, -608, -469}},
+/* UA.UC..GU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}},
+/* UA.UG..GU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}},
+/* UA.UU..GU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}}}},
+/* UA.@@..UG */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..UG */
+{{    0,    0,    0,    0,    0},
+{ -719, -719, -719, -719, -719},
+{ -479, -479, -479, -479, -479},
+{ -659, -659, -659, -659, -659},
+{ -549, -549, -549, -549, -549}},
+/* UA.@C..UG */
+{{    0,    0,    0,    0,    0},
+{ -789, -789, -789, -789, -789},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -439, -439, -439, -439, -439}},
+/* UA.@G..UG */
+{{    0,    0,    0,    0,    0},
+{ -959, -959, -959, -959, -959},
+{ -359, -359, -359, -359, -359},
+{ -919, -919, -919, -919, -919},
+{ -549, -549, -549, -549, -549}},
+/* UA.@U..UG */
+{{    0,    0,    0,    0,    0},
+{ -809, -809, -809, -809, -809},
+{ -479, -479, -479, -479, -479},
+{ -809, -809, -809, -809, -809},
+{ -359, -359, -359, -359, -359}}},
+/* UA.A@..UG */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..UG */
+{{  -50, -399, -629, -889, -589},
+{ -769,-1118,-1348,-1608,-1308},
+{ -529, -878,-1108,-1368,-1068},
+{ -709,-1058,-1288,-1548,-1248},
+{ -599, -948,-1178,-1438,-1138}},
+/* UA.AC..UG */
+{{  -50, -399, -629, -889, -589},
+{ -839,-1188,-1418,-1678,-1378},
+{ -529, -878,-1108,-1368,-1068},
+{ -859,-1208,-1438,-1698,-1398},
+{ -489, -838,-1068,-1328,-1028}},
+/* UA.AG..UG */
+{{  -50, -399, -629, -889, -589},
+{-1009,-1358,-1588,-1848,-1548},
+{ -409, -758, -988,-1248, -948},
+{ -969,-1318,-1548,-1808,-1508},
+{ -599, -948,-1178,-1438,-1138}},
+/* UA.AU..UG */
+{{  -50, -399, -629, -889, -589},
+{ -859,-1208,-1438,-1698,-1398},
+{ -529, -878,-1108,-1368,-1068},
+{ -859,-1208,-1438,-1698,-1398},
+{ -409, -758, -988,-1248, -948}}},
+/* UA.C@..UG */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..UG */
+{{  -50, -429, -509, -199, -179},
+{ -769,-1148,-1228, -918, -898},
+{ -529, -908, -988, -678, -658},
+{ -709,-1088,-1168, -858, -838},
+{ -599, -978,-1058, -748, -728}},
+/* UA.CC..UG */
+{{  -50, -429, -509, -199, -179},
+{ -839,-1218,-1298, -988, -968},
+{ -529, -908, -988, -678, -658},
+{ -859,-1238,-1318,-1008, -988},
+{ -489, -868, -948, -638, -618}},
+/* UA.CG..UG */
+{{  -50, -429, -509, -199, -179},
+{-1009,-1388,-1468,-1158,-1138},
+{ -409, -788, -868, -558, -538},
+{ -969,-1348,-1428,-1118,-1098},
+{ -599, -978,-1058, -748, -728}},
+/* UA.CU..UG */
+{{  -50, -429, -509, -199, -179},
+{ -859,-1238,-1318,-1008, -988},
+{ -529, -908, -988, -678, -658},
+{ -859,-1238,-1318,-1008, -988},
+{ -409, -788, -868, -558, -538}}},
+/* UA.G@..UG */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..UG */
+{{  -50, -379, -679, -889, -679},
+{ -769,-1098,-1398,-1608,-1398},
+{ -529, -858,-1158,-1368,-1158},
+{ -709,-1038,-1338,-1548,-1338},
+{ -599, -928,-1228,-1438,-1228}},
+/* UA.GC..UG */
+{{  -50, -379, -679, -889, -679},
+{ -839,-1168,-1468,-1678,-1468},
+{ -529, -858,-1158,-1368,-1158},
+{ -859,-1188,-1488,-1698,-1488},
+{ -489, -818,-1118,-1328,-1118}},
+/* UA.GG..UG */
+{{  -50, -379, -679, -889, -679},
+{-1009,-1338,-1638,-1848,-1638},
+{ -409, -738,-1038,-1248,-1038},
+{ -969,-1298,-1598,-1808,-1598},
+{ -599, -928,-1228,-1438,-1228}},
+/* UA.GU..UG */
+{{  -50, -379, -679, -889, -679},
+{ -859,-1188,-1488,-1698,-1488},
+{ -529, -858,-1158,-1368,-1158},
+{ -859,-1188,-1488,-1698,-1488},
+{ -409, -738,-1038,-1248,-1038}}},
+/* UA.U@..UG */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..UG */
+{{  -50, -279, -139, -279, -140},
+{ -769, -998, -858, -998, -859},
+{ -529, -758, -618, -758, -619},
+{ -709, -938, -798, -938, -799},
+{ -599, -828, -688, -828, -689}},
+/* UA.UC..UG */
+{{  -50, -279, -139, -279, -140},
+{ -839,-1068, -928,-1068, -929},
+{ -529, -758, -618, -758, -619},
+{ -859,-1088, -948,-1088, -949},
+{ -489, -718, -578, -718, -579}},
+/* UA.UG..UG */
+{{  -50, -279, -139, -279, -140},
+{-1009,-1238,-1098,-1238,-1099},
+{ -409, -638, -498, -638, -499},
+{ -969,-1198,-1058,-1198,-1059},
+{ -599, -828, -688, -828, -689}},
+/* UA.UU..UG */
+{{  -50, -279, -139, -279, -140},
+{ -859,-1088, -948,-1088, -949},
+{ -529, -758, -618, -758, -619},
+{ -859,-1088, -948,-1088, -949},
+{ -409, -638, -498, -638, -499}}}},
+/* UA.@@..AU */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..AU */
+{{    0,    0,    0,    0,    0},
+{ -429, -429, -429, -429, -429},
+{ -259, -259, -259, -259, -259},
+{ -339, -339, -339, -339, -339},
+{ -329, -329, -329, -329, -329}},
+/* UA.@C..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UA.@G..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}},
+/* UA.@U..AU */
+{{    0,    0,    0,    0,    0},
+{ -599, -599, -599, -599, -599},
+{ -239, -239, -239, -239, -239},
+{ -689, -689, -689, -689, -689},
+{ -329, -329, -329, -329, -329}}},
+/* UA.A@..AU */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..AU */
+{{  -50, -399, -629, -889, -589},
+{ -479, -828,-1058,-1318,-1018},
+{ -309, -658, -888,-1148, -848},
+{ -389, -738, -968,-1228, -928},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AC..AU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AG..AU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}},
+/* UA.AU..AU */
+{{  -50, -399, -629, -889, -589},
+{ -649, -998,-1228,-1488,-1188},
+{ -289, -638, -868,-1128, -828},
+{ -739,-1088,-1318,-1578,-1278},
+{ -379, -728, -958,-1218, -918}}},
+/* UA.C@..AU */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..AU */
+{{  -50, -429, -509, -199, -179},
+{ -479, -858, -938, -628, -608},
+{ -309, -688, -768, -458, -438},
+{ -389, -768, -848, -538, -518},
+{ -379, -758, -838, -528, -508}},
+/* UA.CC..AU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}},
+/* UA.CG..AU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}},
+/* UA.CU..AU */
+{{  -50, -429, -509, -199, -179},
+{ -649,-1028,-1108, -798, -778},
+{ -289, -668, -748, -438, -418},
+{ -739,-1118,-1198, -888, -868},
+{ -379, -758, -838, -528, -508}}},
+/* UA.G@..AU */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..AU */
+{{  -50, -379, -679, -889, -679},
+{ -479, -808,-1108,-1318,-1108},
+{ -309, -638, -938,-1148, -938},
+{ -389, -718,-1018,-1228,-1018},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GC..AU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GG..AU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}},
+/* UA.GU..AU */
+{{  -50, -379, -679, -889, -679},
+{ -649, -978,-1278,-1488,-1278},
+{ -289, -618, -918,-1128, -918},
+{ -739,-1068,-1368,-1578,-1368},
+{ -379, -708,-1008,-1218,-1008}}},
+/* UA.U@..AU */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..AU */
+{{  -50, -279, -139, -279, -140},
+{ -479, -708, -568, -708, -569},
+{ -309, -538, -398, -538, -399},
+{ -389, -618, -478, -618, -479},
+{ -379, -608, -468, -608, -469}},
+/* UA.UC..AU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}},
+/* UA.UG..AU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}},
+/* UA.UU..AU */
+{{  -50, -279, -139, -279, -140},
+{ -649, -878, -738, -878, -739},
+{ -289, -518, -378, -518, -379},
+{ -739, -968, -828, -968, -829},
+{ -379, -608, -468, -608, -469}}}},
+/* UA.@@..UA */
+{{{{    0,    0,    0,    0,    0},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A..UA */
+{{    0,    0,    0,    0,    0},
+{ -399, -399, -399, -399, -399},
+{ -429, -429, -429, -429, -429},
+{ -379, -379, -379, -379, -379},
+{ -279, -279, -279, -279, -279}},
+/* UA.@C..UA */
+{{    0,    0,    0,    0,    0},
+{ -629, -629, -629, -629, -629},
+{ -509, -509, -509, -509, -509},
+{ -679, -679, -679, -679, -679},
+{ -139, -139, -139, -139, -139}},
+/* UA.@G..UA */
+{{    0,    0,    0,    0,    0},
+{ -889, -889, -889, -889, -889},
+{ -199, -199, -199, -199, -199},
+{ -889, -889, -889, -889, -889},
+{ -279, -279, -279, -279, -279}},
+/* UA.@U..UA */
+{{    0,    0,    0,    0,    0},
+{ -589, -589, -589, -589, -589},
+{ -179, -179, -179, -179, -179},
+{ -679, -679, -679, -679, -679},
+{ -140, -140, -140, -140, -140}}},
+/* UA.A@..UA */
+{{{  -50, -399, -629, -889, -589},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA..UA */
+{{  -50, -399, -629, -889, -589},
+{ -449, -798,-1028,-1288, -988},
+{ -479, -828,-1058,-1318,-1018},
+{ -429, -778,-1008,-1268, -968},
+{ -329, -678, -908,-1168, -868}},
+/* UA.AC..UA */
+{{  -50, -399, -629, -889, -589},
+{ -679,-1028,-1258,-1518,-1218},
+{ -559, -908,-1138,-1398,-1098},
+{ -729,-1078,-1308,-1568,-1268},
+{ -189, -538, -768,-1028, -728}},
+/* UA.AG..UA */
+{{  -50, -399, -629, -889, -589},
+{ -939,-1288,-1518,-1778,-1478},
+{ -249, -598, -828,-1088, -788},
+{ -939,-1288,-1518,-1778,-1478},
+{ -329, -678, -908,-1168, -868}},
+/* UA.AU..UA */
+{{  -50, -399, -629, -889, -589},
+{ -639, -988,-1218,-1478,-1178},
+{ -229, -578, -808,-1068, -768},
+{ -729,-1078,-1308,-1568,-1268},
+{ -190, -539, -769,-1029, -729}}},
+/* UA.C@..UA */
+{{{  -50, -429, -509, -199, -179},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA..UA */
+{{  -50, -429, -509, -199, -179},
+{ -449, -828, -908, -598, -578},
+{ -479, -858, -938, -628, -608},
+{ -429, -808, -888, -578, -558},
+{ -329, -708, -788, -478, -458}},
+/* UA.CC..UA */
+{{  -50, -429, -509, -199, -179},
+{ -679,-1058,-1138, -828, -808},
+{ -559, -938,-1018, -708, -688},
+{ -729,-1108,-1188, -878, -858},
+{ -189, -568, -648, -338, -318}},
+/* UA.CG..UA */
+{{  -50, -429, -509, -199, -179},
+{ -939,-1318,-1398,-1088,-1068},
+{ -249, -628, -708, -398, -378},
+{ -939,-1318,-1398,-1088,-1068},
+{ -329, -708, -788, -478, -458}},
+/* UA.CU..UA */
+{{  -50, -429, -509, -199, -179},
+{ -639,-1018,-1098, -788, -768},
+{ -229, -608, -688, -378, -358},
+{ -729,-1108,-1188, -878, -858},
+{ -190, -569, -649, -339, -319}}},
+/* UA.G@..UA */
+{{{  -50, -379, -679, -889, -679},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA..UA */
+{{  -50, -379, -679, -889, -679},
+{ -449, -778,-1078,-1288,-1078},
+{ -479, -808,-1108,-1318,-1108},
+{ -429, -758,-1058,-1268,-1058},
+{ -329, -658, -958,-1168, -958}},
+/* UA.GC..UA */
+{{  -50, -379, -679, -889, -679},
+{ -679,-1008,-1308,-1518,-1308},
+{ -559, -888,-1188,-1398,-1188},
+{ -729,-1058,-1358,-1568,-1358},
+{ -189, -518, -818,-1028, -818}},
+/* UA.GG..UA */
+{{  -50, -379, -679, -889, -679},
+{ -939,-1268,-1568,-1778,-1568},
+{ -249, -578, -878,-1088, -878},
+{ -939,-1268,-1568,-1778,-1568},
+{ -329, -658, -958,-1168, -958}},
+/* UA.GU..UA */
+{{  -50, -379, -679, -889, -679},
+{ -639, -968,-1268,-1478,-1268},
+{ -229, -558, -858,-1068, -858},
+{ -729,-1058,-1358,-1568,-1358},
+{ -190, -519, -819,-1029, -819}}},
+/* UA.U@..UA */
+{{{  -50, -279, -139, -279, -140},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA..UA */
+{{  -50, -279, -139, -279, -140},
+{ -449, -678, -538, -678, -539},
+{ -479, -708, -568, -708, -569},
+{ -429, -658, -518, -658, -519},
+{ -329, -558, -418, -558, -419}},
+/* UA.UC..UA */
+{{  -50, -279, -139, -279, -140},
+{ -679, -908, -768, -908, -769},
+{ -559, -788, -648, -788, -649},
+{ -729, -958, -818, -958, -819},
+{ -189, -418, -278, -418, -279}},
+/* UA.UG..UA */
+{{  -50, -279, -139, -279, -140},
+{ -939,-1168,-1028,-1168,-1029},
+{ -249, -478, -338, -478, -339},
+{ -939,-1168,-1028,-1168,-1029},
+{ -329, -558, -418, -558, -419}},
+/* UA.UU..UA */
+{{  -50, -279, -139, -279, -140},
+{ -639, -868, -728, -868, -729},
+{ -229, -458, -318, -458, -319},
+{ -729, -958, -818, -958, -819},
+{ -190, -419, -279, -419, -280}}}},
+/* UA.@@.. @ */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@A.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@C.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@G.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}},
+/* UA.@U.. @ */
+{{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50},
+{  -50,  -50,  -50,  -50,  -50}}},
+/* UA.A@.. @ */
+{{{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AA.. @ */
+{{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AC.. @ */
+{{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AG.. @ */
+{{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}},
+/* UA.AU.. @ */
+{{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639},
+{ -100, -449, -679, -939, -639}}},
+/* UA.C@.. @ */
+{{{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CA.. @ */
+{{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CC.. @ */
+{{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CG.. @ */
+{{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}},
+/* UA.CU.. @ */
+{{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229},
+{ -100, -479, -559, -249, -229}}},
+/* UA.G@.. @ */
+{{{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GA.. @ */
+{{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GC.. @ */
+{{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GG.. @ */
+{{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}},
+/* UA.GU.. @ */
+{{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729},
+{ -100, -429, -729, -939, -729}}},
+/* UA.U@.. @ */
+{{{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UA.. @ */
+{{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UC.. @ */
+{{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UG.. @ */
+{{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}},
+/* UA.UU.. @ */
+{{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190},
+{ -100, -329, -189, -329, -190}}}}},
+{ /* noPair */ {{{{0}}}},
+/*  @.@@..CG */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.@C..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -999, -999, -999, -999, -999},
+{ -499, -499, -499, -499, -499},
+{ -989, -989, -989, -989, -989},
+{ -789, -789, -789, -789, -789}},
+/*  @.@G..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.@U..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -719, -719, -719, -719, -719},
+{ -989, -989, -989, -989, -989},
+{ -909, -909, -909, -909, -909}}},
+/*  @.A@..CG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.AC..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -999, -999, -999, -999, -999},
+{ -499, -499, -499, -499, -499},
+{ -989, -989, -989, -989, -989},
+{ -789, -789, -789, -789, -789}},
+/*  @.AG..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.AU..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -719, -719, -719, -719, -719},
+{ -989, -989, -989, -989, -989},
+{ -909, -909, -909, -909, -909}}},
+/*  @.C@..CG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.CC..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -999, -999, -999, -999, -999},
+{ -499, -499, -499, -499, -499},
+{ -989, -989, -989, -989, -989},
+{ -789, -789, -789, -789, -789}},
+/*  @.CG..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.CU..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -719, -719, -719, -719, -719},
+{ -989, -989, -989, -989, -989},
+{ -909, -909, -909, -909, -909}}},
+/*  @.G@..CG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.GC..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -999, -999, -999, -999, -999},
+{ -499, -499, -499, -499, -499},
+{ -989, -989, -989, -989, -989},
+{ -789, -789, -789, -789, -789}},
+/*  @.GG..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.GU..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -719, -719, -719, -719, -719},
+{ -989, -989, -989, -989, -989},
+{ -909, -909, -909, -909, -909}}},
+/*  @.U@..CG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.UC..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -999, -999, -999, -999, -999},
+{ -499, -499, -499, -499, -499},
+{ -989, -989, -989, -989, -989},
+{ -789, -789, -789, -789, -789}},
+/*  @.UG..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -569, -569, -569, -569, -569},
+{ -989, -989, -989, -989, -989},
+{ -859, -859, -859, -859, -859}},
+/*  @.UU..CG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1079,-1079,-1079,-1079,-1079},
+{ -719, -719, -719, -719, -719},
+{ -989, -989, -989, -989, -989},
+{ -909, -909, -909, -909, -909}}}},
+/*  @.@@..GC */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -569, -569, -569, -569, -569},
+{ -769, -769, -769, -769, -769},
+{ -759, -759, -759, -759, -759},
+{ -549, -549, -549, -549, -549}},
+/*  @.@C..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -359, -359, -359, -359, -359},
+{ -789, -789, -789, -789, -789},
+{ -549, -549, -549, -549, -549}},
+/*  @.@G..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -609, -609, -609, -609, -609},
+{ -359, -359, -359, -359, -359},
+{ -669, -669, -669, -669, -669},
+{ -549, -549, -549, -549, -549}},
+/*  @.@U..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -439, -439, -439, -439, -439},
+{ -789, -789, -789, -789, -789},
+{ -619, -619, -619, -619, -619}}},
+/*  @.A@..GC */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -569, -569, -569, -569, -569},
+{ -769, -769, -769, -769, -769},
+{ -759, -759, -759, -759, -759},
+{ -549, -549, -549, -549, -549}},
+/*  @.AC..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -359, -359, -359, -359, -359},
+{ -789, -789, -789, -789, -789},
+{ -549, -549, -549, -549, -549}},
+/*  @.AG..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -609, -609, -609, -609, -609},
+{ -359, -359, -359, -359, -359},
+{ -669, -669, -669, -669, -669},
+{ -549, -549, -549, -549, -549}},
+/*  @.AU..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -439, -439, -439, -439, -439},
+{ -789, -789, -789, -789, -789},
+{ -619, -619, -619, -619, -619}}},
+/*  @.C@..GC */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -569, -569, -569, -569, -569},
+{ -769, -769, -769, -769, -769},
+{ -759, -759, -759, -759, -759},
+{ -549, -549, -549, -549, -549}},
+/*  @.CC..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -359, -359, -359, -359, -359},
+{ -789, -789, -789, -789, -789},
+{ -549, -549, -549, -549, -549}},
+/*  @.CG..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -609, -609, -609, -609, -609},
+{ -359, -359, -359, -359, -359},
+{ -669, -669, -669, -669, -669},
+{ -549, -549, -549, -549, -549}},
+/*  @.CU..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -439, -439, -439, -439, -439},
+{ -789, -789, -789, -789, -789},
+{ -619, -619, -619, -619, -619}}},
+/*  @.G@..GC */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -569, -569, -569, -569, -569},
+{ -769, -769, -769, -769, -769},
+{ -759, -759, -759, -759, -759},
+{ -549, -549, -549, -549, -549}},
+/*  @.GC..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -359, -359, -359, -359, -359},
+{ -789, -789, -789, -789, -789},
+{ -549, -549, -549, -549, -549}},
+/*  @.GG..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -609, -609, -609, -609, -609},
+{ -359, -359, -359, -359, -359},
+{ -669, -669, -669, -669, -669},
+{ -549, -549, -549, -549, -549}},
+/*  @.GU..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -439, -439, -439, -439, -439},
+{ -789, -789, -789, -789, -789},
+{ -619, -619, -619, -619, -619}}},
+/*  @.U@..GC */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -569, -569, -569, -569, -569},
+{ -769, -769, -769, -769, -769},
+{ -759, -759, -759, -759, -759},
+{ -549, -549, -549, -549, -549}},
+/*  @.UC..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -359, -359, -359, -359, -359},
+{ -789, -789, -789, -789, -789},
+{ -549, -549, -549, -549, -549}},
+/*  @.UG..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -609, -609, -609, -609, -609},
+{ -359, -359, -359, -359, -359},
+{ -669, -669, -669, -669, -669},
+{ -549, -549, -549, -549, -549}},
+/*  @.UU..GC */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -929, -929, -929, -929, -929},
+{ -439, -439, -439, -439, -439},
+{ -789, -789, -789, -789, -789},
+{ -619, -619, -619, -619, -619}}}},
+/*  @.@@..GU */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.@C..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.@G..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.@U..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.A@..GU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.AC..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.AG..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.AU..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.C@..GU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.CC..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.CG..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.CU..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.G@..GU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.GC..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.GG..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.GU..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.U@..GU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.UC..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.UG..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.UU..GU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}}},
+/*  @.@@..UG */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -769, -769, -769, -769, -769},
+{ -529, -529, -529, -529, -529},
+{ -709, -709, -709, -709, -709},
+{ -599, -599, -599, -599, -599}},
+/*  @.@C..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -839, -839, -839, -839, -839},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -489, -489, -489, -489, -489}},
+/*  @.@G..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1009,-1009,-1009,-1009,-1009},
+{ -409, -409, -409, -409, -409},
+{ -969, -969, -969, -969, -969},
+{ -599, -599, -599, -599, -599}},
+/*  @.@U..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -859, -859, -859, -859, -859},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -409, -409, -409, -409, -409}}},
+/*  @.A@..UG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -769, -769, -769, -769, -769},
+{ -529, -529, -529, -529, -529},
+{ -709, -709, -709, -709, -709},
+{ -599, -599, -599, -599, -599}},
+/*  @.AC..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -839, -839, -839, -839, -839},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -489, -489, -489, -489, -489}},
+/*  @.AG..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1009,-1009,-1009,-1009,-1009},
+{ -409, -409, -409, -409, -409},
+{ -969, -969, -969, -969, -969},
+{ -599, -599, -599, -599, -599}},
+/*  @.AU..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -859, -859, -859, -859, -859},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -409, -409, -409, -409, -409}}},
+/*  @.C@..UG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -769, -769, -769, -769, -769},
+{ -529, -529, -529, -529, -529},
+{ -709, -709, -709, -709, -709},
+{ -599, -599, -599, -599, -599}},
+/*  @.CC..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -839, -839, -839, -839, -839},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -489, -489, -489, -489, -489}},
+/*  @.CG..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1009,-1009,-1009,-1009,-1009},
+{ -409, -409, -409, -409, -409},
+{ -969, -969, -969, -969, -969},
+{ -599, -599, -599, -599, -599}},
+/*  @.CU..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -859, -859, -859, -859, -859},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -409, -409, -409, -409, -409}}},
+/*  @.G@..UG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -769, -769, -769, -769, -769},
+{ -529, -529, -529, -529, -529},
+{ -709, -709, -709, -709, -709},
+{ -599, -599, -599, -599, -599}},
+/*  @.GC..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -839, -839, -839, -839, -839},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -489, -489, -489, -489, -489}},
+/*  @.GG..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1009,-1009,-1009,-1009,-1009},
+{ -409, -409, -409, -409, -409},
+{ -969, -969, -969, -969, -969},
+{ -599, -599, -599, -599, -599}},
+/*  @.GU..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -859, -859, -859, -859, -859},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -409, -409, -409, -409, -409}}},
+/*  @.U@..UG */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -769, -769, -769, -769, -769},
+{ -529, -529, -529, -529, -529},
+{ -709, -709, -709, -709, -709},
+{ -599, -599, -599, -599, -599}},
+/*  @.UC..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -839, -839, -839, -839, -839},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -489, -489, -489, -489, -489}},
+/*  @.UG..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{-1009,-1009,-1009,-1009,-1009},
+{ -409, -409, -409, -409, -409},
+{ -969, -969, -969, -969, -969},
+{ -599, -599, -599, -599, -599}},
+/*  @.UU..UG */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -859, -859, -859, -859, -859},
+{ -529, -529, -529, -529, -529},
+{ -859, -859, -859, -859, -859},
+{ -409, -409, -409, -409, -409}}}},
+/*  @.@@..AU */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.@C..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.@G..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.@U..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.A@..AU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.AC..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.AG..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.AU..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.C@..AU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.CC..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.CG..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.CU..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.G@..AU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.GC..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.GG..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.GU..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}},
+/*  @.U@..AU */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -479, -479, -479, -479, -479},
+{ -309, -309, -309, -309, -309},
+{ -389, -389, -389, -389, -389},
+{ -379, -379, -379, -379, -379}},
+/*  @.UC..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.UG..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}},
+/*  @.UU..AU */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -649, -649, -649, -649, -649},
+{ -289, -289, -289, -289, -289},
+{ -739, -739, -739, -739, -739},
+{ -379, -379, -379, -379, -379}}}},
+/*  @.@@..UA */
+{{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -449, -449, -449, -449, -449},
+{ -479, -479, -479, -479, -479},
+{ -429, -429, -429, -429, -429},
+{ -329, -329, -329, -329, -329}},
+/*  @.@C..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -679, -679, -679, -679, -679},
+{ -559, -559, -559, -559, -559},
+{ -729, -729, -729, -729, -729},
+{ -189, -189, -189, -189, -189}},
+/*  @.@G..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -939, -939, -939, -939, -939},
+{ -249, -249, -249, -249, -249},
+{ -939, -939, -939, -939, -939},
+{ -329, -329, -329, -329, -329}},
+/*  @.@U..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -639, -639, -639, -639, -639},
+{ -229, -229, -229, -229, -229},
+{ -729, -729, -729, -729, -729},
+{ -190, -190, -190, -190, -190}}},
+/*  @.A@..UA */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -449, -449, -449, -449, -449},
+{ -479, -479, -479, -479, -479},
+{ -429, -429, -429, -429, -429},
+{ -329, -329, -329, -329, -329}},
+/*  @.AC..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -679, -679, -679, -679, -679},
+{ -559, -559, -559, -559, -559},
+{ -729, -729, -729, -729, -729},
+{ -189, -189, -189, -189, -189}},
+/*  @.AG..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -939, -939, -939, -939, -939},
+{ -249, -249, -249, -249, -249},
+{ -939, -939, -939, -939, -939},
+{ -329, -329, -329, -329, -329}},
+/*  @.AU..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -639, -639, -639, -639, -639},
+{ -229, -229, -229, -229, -229},
+{ -729, -729, -729, -729, -729},
+{ -190, -190, -190, -190, -190}}},
+/*  @.C@..UA */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -449, -449, -449, -449, -449},
+{ -479, -479, -479, -479, -479},
+{ -429, -429, -429, -429, -429},
+{ -329, -329, -329, -329, -329}},
+/*  @.CC..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -679, -679, -679, -679, -679},
+{ -559, -559, -559, -559, -559},
+{ -729, -729, -729, -729, -729},
+{ -189, -189, -189, -189, -189}},
+/*  @.CG..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -939, -939, -939, -939, -939},
+{ -249, -249, -249, -249, -249},
+{ -939, -939, -939, -939, -939},
+{ -329, -329, -329, -329, -329}},
+/*  @.CU..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -639, -639, -639, -639, -639},
+{ -229, -229, -229, -229, -229},
+{ -729, -729, -729, -729, -729},
+{ -190, -190, -190, -190, -190}}},
+/*  @.G@..UA */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -449, -449, -449, -449, -449},
+{ -479, -479, -479, -479, -479},
+{ -429, -429, -429, -429, -429},
+{ -329, -329, -329, -329, -329}},
+/*  @.GC..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -679, -679, -679, -679, -679},
+{ -559, -559, -559, -559, -559},
+{ -729, -729, -729, -729, -729},
+{ -189, -189, -189, -189, -189}},
+/*  @.GG..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -939, -939, -939, -939, -939},
+{ -249, -249, -249, -249, -249},
+{ -939, -939, -939, -939, -939},
+{ -329, -329, -329, -329, -329}},
+/*  @.GU..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -639, -639, -639, -639, -639},
+{ -229, -229, -229, -229, -229},
+{ -729, -729, -729, -729, -729},
+{ -190, -190, -190, -190, -190}}},
+/*  @.U@..UA */
+{{{  -50,  -50,  -50,  -50,  -50},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -449, -449, -449, -449, -449},
+{ -479, -479, -479, -479, -479},
+{ -429, -429, -429, -429, -429},
+{ -329, -329, -329, -329, -329}},
+/*  @.UC..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -679, -679, -679, -679, -679},
+{ -559, -559, -559, -559, -559},
+{ -729, -729, -729, -729, -729},
+{ -189, -189, -189, -189, -189}},
+/*  @.UG..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -939, -939, -939, -939, -939},
+{ -249, -249, -249, -249, -249},
+{ -939, -939, -939, -939, -939},
+{ -329, -329, -329, -329, -329}},
+/*  @.UU..UA */
+{{  -50,  -50,  -50,  -50,  -50},
+{ -639, -639, -639, -639, -639},
+{ -229, -229, -229, -229, -229},
+{ -729, -729, -729, -729, -729},
+{ -190, -190, -190, -190, -190}}}},
+/*  @.@@.. @ */
+{{{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@A.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@C.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@G.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.@U.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}}},
+/*  @.A@.. @ */
+{{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AA.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AC.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AG.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.AU.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}}},
+/*  @.C@.. @ */
+{{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CA.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CC.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CG.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.CU.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}}},
+/*  @.G@.. @ */
+{{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GA.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GC.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GG.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.GU.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}}},
+/*  @.U@.. @ */
+{{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UA.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UC.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UG.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}},
+/*  @.UU.. @ */
+{{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100},
+{ -100, -100, -100, -100, -100}}}}}};
+
+int 
+energy_param::
+getMaxNinio()      
+{ return MAX_NINIO; }
+    
+int 
+energy_param::
+getNinio(int i)   
+{ return F_ninio37[i]; }
+    
+int 
+energy_param::getDangle5(int i, int j)       
+{ return dangle5_37[convertPairType(i)][convertBaseType(j)]; } 
+    
+int 
+energy_param::
+getDangle3(int i, int j) 
+{ return dangle3_37[convertPairType(i)][convertBaseType(j)]; }
+    
+int 
+energy_param::
+getHairpin(int i) 
+{ return hairpin37[i]; }
+    
+int 
+energy_param::
+getInternalLoop(int i) 
+{ return internal_loop37[i]; }
+    
+int 
+energy_param::getBulge(int i)  
+{ return bulge37[i]; }
+    
+const char 
+*energy_param::
+getTetraLoop(int i) 
+{ return Tetrastrings[i]; }
+    
+int 
+energy_param::
+getTetraLoopEnergy(int i)  
+{ return TETRA_ENERGY37[i]; }
+    
+int 
+energy_param::
+getStack(int i, int j) 
+{ return stack37[convertPairType(i)][convertPairType(j)]; }
+    
+int 
+energy_param::
+getTstackH(int i, int j)      
+{ return mismatchH37[convertPairType(i)][convertLeftType(j)][convertRightType(j)]; }
+    
+int 
+energy_param::
+getTstackI(int i, int j)      
+{ return mismatchI37[convertPairType(i)][convertLeftType(j)][convertRightType(j)]; }
+    
+int 
+energy_param::
+getInt11(int i, int j, int k)
+{ return int11_37[convertPairType(i)][convertPairType(j)][convertLeftType(k)][convertRightType(k)]; }
+    
+int 
+energy_param::
+getInt21(int i, int j, int k, int l)
+{ return int21_37[convertPairType(i)][convertPairType(j)][convertLeftType(k)][convertBaseType(l)][convertRightType(k)]; }
+    
+int 
+energy_param::
+getInt22(int i, int j, int k, int l) 
+{ return int22_37[convertPairType(i)][convertPairType(j)][convertLeftType(k)][convertLeftType(l)][convertRightType(l)][convertRightType(k)]; }
+
+int 
+energy_param::
+getMLintern() 
+{ return ML_intern37;  }
+    
+int 
+energy_param::
+getMLBase()  
+{ return ML_BASE37;    }
+
+int 
+energy_param::
+getMLclosing() 
+{ return ML_closing37; }
+    
+int 
+energy_param::
+getTerminalAU() 
+{ return TerminalAU;   }
+
+/* 
+   1    C<->G    1
+   2    G<->C    2
+   3    G<->U    3
+   5    U<->G    4
+   0    A<->U    5
+   4    U<->A    6
+   6             0
+ */
+int 
+energy_param::
+convertPairType(int type) 
+{
+    if     (type == 0)  return 5;
+    else if(type == 1)  return 1;
+    else if(type == 2)  return 2;
+    else if(type == 3)  return 3;
+    else if(type == 4)  return 6;
+    else if(type == 5)  return 4;
+    else if(type == 6)  return 0;
+    else { cerr << "error convertPairType" << endl; exit(1); }
+}
+
+/*   
+    0 A 1
+    1 C 2
+    2 G 3 
+    3 U 4
+ */
+int
+energy_param::
+convertBaseType(int type) 
+{
+    if     (type == 0) return 1;
+    else if(type == 1) return 2;
+    else if(type == 2) return 3;
+    else if(type == 3) return 4;
+    else { cerr << "error convertBaseType" << endl; exit(1); }
+}
+
+/*
+  A<->A  0
+  A<->C  1
+  A<->G  2
+  A<->U  3
+  C<->A  4
+  C<->C  5
+  C<->G  6
+  C<->U  7
+  G<->A  8
+  G<->C  9
+  G<->G 10
+  G<->U 11
+  U<->A 12
+  U<->C 13
+  U<->G 14
+  U<->U 15
+ */
+int 
+energy_param::
+convertLeftType(int type) 
+{
+    if     (0 <= type && type <= 3 ) { return 1; }
+    else if(4 <= type && type <= 7 ) { return 2; }
+    else if(8 <= type && type <= 11) { return 3; }
+    else if(12<= type && type <= 15) { return 4; }
+    else { cerr << "convertLeftType" << endl; exit(1); }
+}
+
+int
+energy_param::
+convertRightType(int type)
+{
+    if     (type % 4 == 0) { return 1; }
+    else if(type % 4 == 1) { return 2; }
+    else if(type % 4 == 2) { return 3; }
+    else if(type % 4 == 3) { return 4; }
+    else { cerr << "convertRightType" << endl; exit(1); }
+}
+}
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.hpp b/binaries/src/mafft/extensions/mxscarna_src/vienna/energy_param.hpp
new file mode 100644 (file)
index 0000000..b6bcd4c
--- /dev/null
@@ -0,0 +1,111 @@
+/* 
+    Current free energy parameters are summarized in:
+
+    D.H.Mathews, J. Sabina, M. ZUker, D.H. Turner
+    "Expanded sequence dependence of thermodynamic parameters improves
+    prediction of RNA secondary structure"
+    JMB, 288, pp 911-940, 1999
+
+    Enthalpies taken from:
+    
+    A. Walter, D Turner, J Kim, M Lyttle, P M"uller, D Mathews, M Zuker
+    "Coaxial stckaing of helices enhances binding of oligoribonucleotides.."
+    PNAS, 91, pp 9218-9222, 1994
+    
+    D.H. Turner, N. Sugimoto, and S.M. Freier.
+    "RNA Structure Prediction",
+    Ann. Rev. Biophys. Biophys. Chem. 17, 167-192, 1988.
+
+    John A.Jaeger, Douglas H.Turner, and Michael Zuker.
+    "Improved predictions of secondary structures for RNA",
+    PNAS, 86, 7706-7710, October 1989.
+    
+    L. He, R. Kierzek, J. SantaLucia, A.E. Walter, D.H. Turner
+    "Nearest-Neughbor Parameters for GU Mismatches...."
+    Biochemistry 1991, 30 11124-11132
+
+    A.E. Peritz, R. Kierzek, N, Sugimoto, D.H. Turner
+    "Thermodynamic Study of Internal Loops in Oligoribonucleotides..."
+    Biochemistry 1991, 30, 6428--6435
+
+    
+*/
+
+#ifndef ENERGY_PARAM_H
+#define ENERGY_PARAM_H
+
+#include <iostream>
+#include <cstdlib> // by katoh
+
+using namespace std;
+namespace MXSCARNA {
+class energy_param {
+
+    static const int    INF;
+    static const int    NST;
+    static const int    DEF;
+
+    static const double lxc37; /* parameter for logarithmic loop
+                             energy extrapolation            */
+    static const int stack37[8][8];
+    static const int enthalpies[8][8];
+    static const int oldhairpin37[31];
+    static const int hairpin37[31];
+    static const int oldbulge37[31];
+    static const int bulge37[31];
+    static const int oldinternal_loop37[31];
+    static const int internal_loop37[31];
+    static const int mismatchI37[8][5][5];
+    static const int mismatchH37[8][5][5];
+    static const int mism_H[8][5][5];
+    static const int dangle5_37[8][5];
+    static const int dangle3_37[8][5];
+    static const int dangle3_H[8][5];
+    static const int dangle5_H[8][5];
+    static const int ML_BASE37;
+    static const int ML_closing37;
+    static const int ML_intern37;
+    static const int MAX_NINIO;
+    static const int F_ninio37[5];
+    static const char Tetraloops[1400];
+    static const char Tetrastrings[30][7];
+    static const int TETRA_ENERGY37[200];
+    static const int TETRA_ENTH37;
+    static const int TerminalAU;
+    static const int DuplexInit;
+
+    static const int int11_37[8][8][5][5];
+    static const int int11_H[8][8][5][5];
+    static const int int21_37[8][8][5][5][5];
+    static const int int21_H[8][8][5][5][5];
+    static const int int22_37[8][8][5][5][5][5];
+    static const int int22_H[8][8][5][5][5][5];
+
+    int convertPairType(int type);
+    int convertBaseType(int type);
+    int convertLeftType(int type);
+    int convertRightType(int type);
+ public:
+    int getMaxNinio();
+    int getNinio(int i);
+    int getDangle5(int i, int j);
+    int getDangle3(int i, int j);
+    int getHairpin(int i);
+    int getInternalLoop(int i);
+    int getBulge(int i);
+    const char *getTetraLoop(int i);
+    int getTetraLoopEnergy(int i);
+    int getStack(int i, int j);
+    int getTstackH(int i, int j);
+    int getTstackI(int i, int j);
+    int getInt11(int i, int j, int k);
+    int getInt21(int i, int j, int k, int l);
+    int getInt22(int i, int j, int k, int l);
+    int getMLintern();
+    int getMLBase();
+    int getMLclosing();
+    int getTerminalAU();
+};
+}
+#endif
diff --git a/binaries/src/mafft/extensions/mxscarna_src/vienna/params.h b/binaries/src/mafft/extensions/mxscarna_src/vienna/params.h
new file mode 100644 (file)
index 0000000..46d6122
--- /dev/null
@@ -0,0 +1,32 @@
+#include "energy_const.h"
+typedef struct {
+  int id;
+  int stack[NBPAIRS+1][NBPAIRS+1];
+  int hairpin[31];
+  int bulge[MAXLOOP+1];
+  int internal_loop[MAXLOOP+1];
+  int mismatchI[NBPAIRS+1][5][5];
+  int mismatchH[NBPAIRS+1][5][5];
+  int mismatchM[NBPAIRS+1][5][5];
+  int dangle5[NBPAIRS+1][5];
+  int dangle3[NBPAIRS+1][5];
+  int int11[NBPAIRS+1][NBPAIRS+1][5][5];
+  int int21[NBPAIRS+1][NBPAIRS+1][5][5][5];
+  int int22[NBPAIRS+1][NBPAIRS+1][5][5][5][5];
+  int F_ninio[5];
+  double lxc;
+  int MLbase;
+  int MLintern[NBPAIRS+1];
+  int MLclosing;
+  int TerminalAU;
+  int DuplexInit;
+  int TETRA_ENERGY[200];
+  char Tetraloops[1401];
+  int Triloop_E[40];
+  char Triloops[241];
+  double temperature;
+}  paramT;
+
+extern paramT *scale_parameters(void);
+extern paramT *copy_parameters(void);
+extern paramT *set_parameters(paramT *dest);
diff --git a/binaries/src/mafft/extensions/univscript.tmpl b/binaries/src/mafft/extensions/univscript.tmpl
new file mode 100644 (file)
index 0000000..d6200d2
--- /dev/null
@@ -0,0 +1,36 @@
+progs="_PROGS"
+for prog in $progs; do
+       printf  $prog" "
+done
+
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch ppc64 -m64 -O3  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4" CXX="g++-4.0" CXXFLAGS="-arch ppc64 -m64 -O3  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.ppc64
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch ppc -m32 -O3  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4" CXX="g++-4.0" CXXFLAGS="-arch ppc -m32 -O3  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.ppc32
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch x86_64 -fast -m64  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4" CXX="g++-4.0" CXXFLAGS="-arch x86_64 -fast -m64  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.intel64
+done
+
+make clean
+make CC="gcc-4.0" CFLAGS="-arch i386 -fast -m32  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4" CXX="g++-4.0" CXXFLAGS="-arch i386 -fast -m32  -mmacosx-version-min=10.4 -isysroot/Developer/SDKs/MacOSX10.4u.sdk -DMACOSX_DEPLOYMENT_TARGET=10.4"
+for prog in $progs; do
+       mv $prog $prog.intel32
+done
+
+set $progs
+for prog in $progs; do
+#      lipo -create $prog.icc $prog.ppc32 $prog.ppc64 -output $prog
+       lipo -create $prog.intel64 $prog.intel32 $prog.ppc32 $prog.ppc64 -output $prog
+       cp $prog ../binaries
+done
diff --git a/binaries/src/mafft/license b/binaries/src/mafft/license
new file mode 100644 (file)
index 0000000..6d25e27
--- /dev/null
@@ -0,0 +1,48 @@
+============================================================
+
+If you have the './extensions' directory, please also see
+license.extensions file.
+
+============================================================
+
+The codes in the './core' directory is distributed with 
+the BSD license.
+
+MAFFT: multiple sequence alignment program
+Copyright (c) 2009 Kazutaka Katoh
+
+Redistribution and use in source and binary forms,
+with or without modification, are permitted provided
+that the following conditions are met:
+
+Redistributions of source code must retain the
+above copyright notice, this list of conditions
+and the following disclaimer.  Redistributions in
+binary form must reproduce the above copyright
+notice, this list of conditions and the following
+disclaimer in the documentation and/or other
+materials provided with the distribution.
+
+The name of the author may not be used to endorse
+or promote products derived from this software without
+specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
+---------------------------------------------------------------------------------
+
+
+
diff --git a/binaries/src/mafft/license.extensions b/binaries/src/mafft/license.extensions
new file mode 100644 (file)
index 0000000..9e14bea
--- /dev/null
@@ -0,0 +1,120 @@
+The 'extension' directory contains codes from 
+
+(1) the Vienna RNA package
+(2) MXSCARNA
+(3) ProbConsRNA
+
+These packages are distributed under different licenses:
+
+-------------------------------------------------------------------------------
+(1) The Vienna RNA package
+
+See ./extensions/mxscarna_src/vienna/COPYING and http://www.tbi.univie.ac.at/~ivo/RNA/
+
+                         Disclaimer and Copyright
+
+The programs, library and source code of the Vienna RNA Package are free
+software. They are distributed in the hope that they will be useful
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+Permission is granted for research, educational, and commercial use
+and modification so long as 1) the package and any derived works are not
+redistributed for any fee, other than media costs, 2) proper credit is
+given to the authors and the Institute for Theoretical Chemistry of the
+University of Vienna.
+
+If you want to include this software in a commercial product, please contact
+the authors.
+
+Reference:
+  Ivo L Hofacker and  Martin Fekete and  Peter F Stadler
+  Secondary structure prediction for aligned RNA sequences.
+  J Mol Biol. 2002 vol. 319 (18) pp.3724-32
+
+-------------------------------------------------------------------------------
+(2) MXSCARNA
+
+See ./extensions/mxscarna_src/README and http://www.ncrna.org/software/mxscarna/
+
+* Author
+ Yasuo Tabei
+
+ Department of Computational Biology,
+ Graduate School of Frontier Science,
+ The University of Tokyo
+ and
+ Computational Biology Research Center (CBRC),
+ National Institute of Advanced Industrial Science and Technology (AIST)
+
+ E-mail: scarna AT m.aist.go.jp
+
+* What is MXSCARNA
+ MXSCARNA (Multiplex Stem Candidate Aligner for RNAs) is a tool for
+ fast structural multiple alignment of RNA sequences using progressive
+ alignment based on pairwise structural alignment algorithm of SCARNA.
+
+* License
+ While its original source code is provided as free software, MXSCARNA
+ contains the source codes of ProbCons and Rfold and the energy parameters
+ of Vienna RNA package (version 1.5).
+ The author thanks Dr. Chuong Do, Dr. Hisanori Kiryu and Dr. Ivo Hofacker,
+ the authors of ProbCons, Rfold and Vienna RNA package respectively,
+ and Institute for Theoretical Chemistry of the  University of Vienna.
+
+ The source code of Rfold is located in ./extensions/mxscarna_src/rfold-0.1, which includes
+ energy parameters of Vienna RNA package in ./extensions/mxscarna_src/rfold-0.1/src/vienna.
+ Energy parameters of Vienna RNA package are also included in the source
+ code of MXSCARNA (./extensions/mxscarna_src/vienna). Please follow ./extensions/mxscarna_src/rfold-0.1/readme.txt
+ file, which describes the license of Rfold, and
+ ./extensions/mxscarna_src/rfold-0.1/src/vienna/COPYING file and ./extensions/mxscarna_src/vienna/COPYING file,
+ which describe the copyright notice of the Vienna RNA package.
+ The source code of ProbCons is located in ./extensions/mxscarna_src/probconsRNA. Please follow
+ ./extensions/mxscarna_src/probcons/README.
+
+ The original part of MXSCARNA is provided as free software. It is
+ distributed in the hope that it will be useful but WITHOUT ANY WARRANTY;
+ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ PARTICULAR PURPOSE.
+
+ Permission is granted for research, educational, and commercial use
+ and modification so long as
+ 1) the package and any derived works are not redistributed for any fee,
+    other than media costs,
+ 2) proper credit is given to
+    the authors of MXSCARNA, ProbCons, Rfold and Vienna RNA package,
+    the Univeristy of Tokyo,
+    Computational Biology Research Center (CBRC), AIST
+    and Institute for Theoretical Chemistry of the  University of Vienna.
+
+ If you want to include this software in a commercial product, please
+ contact the author.
+
+* Citation
+ Yasuo Tabei, Hisanori Kiryu, Taishin Kin, Kiyoshi Asai
+ A fast structural multiple alignment method for long RNA sequences.
+ BMC bioinformatics 9:33 (2008)
+
+---------------------------------------------------------------------------------
+(3) ProbCons
+
+See ./extensions/mxscarna_src/probconsRNA/README and http://probcons.stanford.edu/
+
+* Author
+  Chuong Do
+
+* License
+PROBCONS has been made  freely  available  as  PUBLIC  DOMAIN  
+software and hence is not subject to copyright in the  United  
+States.  This system and/or any portion of  the  source  code
+may be used, modified, or redistributed without restrictions.  
+PROBCONS is distributed WITHOUT WARRANTY, express or implied.
+The authors accept NO LEGAL LIABILITY OR  RESPONSIBILITY  for
+loss due to reliance on the program.
+
+* Citation
+Do CB, Mahabhashyam MS, Brudno M, Batzoglou S.
+ProbCons: Probabilistic consistency-based multiple sequence alignment.
+Genome Res. 2005 15:330-40.
+
+-------------------------------------------------------------------------------
diff --git a/binaries/src/mafft/readme b/binaries/src/mafft/readme
new file mode 100644 (file)
index 0000000..fd5ef6e
--- /dev/null
@@ -0,0 +1,139 @@
+-----------------------------------------------------------------------
+  MAFFT: a multiple sequence alignment program
+  version 6.857beta, 2011/05/30
+
+  http://mafft.cbrc.jp/alignment/software/
+  kazutaka.katoh@aist.go.jp
+-----------------------------------------------------------------------
+
+1. COMPILE
+     % cd core
+     % make clean
+     % make
+     % cd ..
+
+     To enable multithreading (linux only), 
+     % cd core
+     Uncomment line 8 of Makefile,
+         ENABLE_MULTITHREAD = -Denablemultithread
+     % make clean
+     % make
+     % cd ..
+     
+     If you have the './extensions' directory, which is for RNA alignments,
+     % cd extensions
+     % make clean
+     % make
+     % cd ..
+
+
+2. INSTALL (select 2a or 2b [])
+2a. Install as root
+     # cd core
+     # make install
+     # cd ..
+
+     If you have the './extensions' directory,
+     # cd extensions 
+     # make install
+     # cd ..
+
+     By this procedure (2a), programs are installed into 
+     /usr/local/bin/. Some binaries, which are not directly
+     used by a user, are installed into /usr/local/libexec/mafft/.
+
+     If the MAFFT_BINARIES environment variable is set to /somewhare/else/,
+     the binaries in the /somewhere/else/ directory are used, instead 
+     of those in /usr/local/libexec/mafft/.
+
+2b. Install without being root
+     % cd core/
+          Edit the first line of Makefile 
+          From:
+          PREFIX = ${PKGDIR}/usr/local
+          To:
+          PREFIX = /home/your_home/somewhere
+
+          Edit the third line of Makefile 
+          From:
+          BINDIR = $(PREFIX)/bin
+          To:
+          BINDIR = /home/your_home/bin 
+                   (or elsewhere in your command-search path)
+     % make clean
+     % make
+     % make install
+
+     If you have the './extensions' directory,
+     % cd ../extensions/
+          Edit the first line of Makefile 
+          From:
+          PREFIX = ${PKGDIR}/usr/local
+          To:
+          PREFIX = /home/your_home/somewhere
+     % make clean
+     % make
+     % make install
+
+     The MAFFT_BINARIES environment variable *must not be* set.
+
+     If the MAFFT_BINARIES environment variable is set to /somewhare/else/,
+     it overrides the setting of PREFIX (/home/your_home/somewhere/ in the
+     above example) in Makefile.
+
+3. CHECK
+     % cd test
+     % rehash                                                   # if necessary
+     % mafft sample > test.fftns2                               # FFT-NS-2
+     % mafft --maxiterate 100  sample > test.fftnsi             # FFT-NS-i
+     % mafft --globalpair sample > test.gins1                   # G-INS-1 
+     % mafft --globalpair --maxiterate 100  sample > test.ginsi # G-INS-i 
+     % mafft --localpair sample > test.lins1                    # L-INS-1 
+     % mafft --localpair --maxiterate 100  sample > test.linsi  # L-INS-i 
+     % diff test.fftns2 sample.fftns2
+     % diff test.fftnsi sample.fftnsi
+     % diff test.gins1 sample.gins1
+     % diff test.ginsi sample.ginsi
+     % diff test.lins1 sample.lins1
+
+     If you have the './extensions' directory,
+     % mafft-qinsi samplerna > test.qinsi                       # Q-INS-i
+     % mafft-xinsi samplerna > test.xinsi                       # X-INS-i
+     % diff test.qinsi samplerna.qinsi
+     % diff test.xinsi samplerna.xinsi
+
+     If you use the multithread version, the results of iterative refinement
+     methods (*-*-i) are not always identical.  Try this test with the single-
+     thread mode (--thread 0).
+
+
+4. INPUT FORMAT
+     fasta format.
+
+     The type of input sequences (nucleotide or amino acid) is 
+     automatically recognized based on the frequency of A, T, G, C, U and N.
+
+
+5.  USAGE
+     % /usr/local/bin/mafft input > output
+
+See also http://mafft.cbrc.jp/alignment/software/
+
+
+6. UNINSTALL
+     # rm -r /usr/local/libexec/mafft
+     # rm /usr/local/bin/mafft
+     # rm /usr/local/bin/fftns
+     # rm /usr/local/bin/fftnsi
+     # rm /usr/local/bin/nwns
+     # rm /usr/local/bin/nwnsi
+     # rm /usr/local/bin/linsi
+     # rm /usr/local/bin/ginsi
+     # rm /usr/local/bin/mafft-*
+     # rm /usr/local/share/man/man1/mafft*
+
+
+7. LICENSE
+     See the './license' file.
+
+     If you have the extensions, see also the './license.extensions' file, 
diff --git a/binaries/src/mafft/test/sample b/binaries/src/mafft/test/sample
new file mode 100644 (file)
index 0000000..e323c25
--- /dev/null
@@ -0,0 +1,285 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+MNGTEGDNFYVPFSNKTGLARSPYEYPQYYLAEPWKYSALAAYMFFLILVGFPVNFLTLF
+VTVQHKKLRTPLNYILLNLAMANLFMVLFGFTVTMYTSMNGYFVFGPTMCSIEGFFATLG
+GEVALWSLVVLAIERYIVICKPMGNFRFGNTHAIMGVAFTWIMALACAAPPLVGWSRYIP
+EGMQCSCGPDYYTLNPNFNNESYVVYMFVVHFLVPFVIIFFCYGRLLCTVKEAAAAQQES
+ASTQKAEKEVTRMVVLMVIGFLVCWVPYASVAFYIFTHQGSDFGATFMTLPAFFAKSSAL
+YNPVIYILMNKQFRNCMITTLCCGKNPLGDDESGASTSKTEVSSVSTSPVSPA
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+MNGTEGPNFYVPFSNITGVVRSPFEQPQYYLAEPWQFSMLAAYMFLLIVLGFPINFLTLY
+VTVQHKKLRTPLNYILLNLAVADLFMVFGGFTTTLYTSLHGYFVFGPTGCNLEGFFATLG
+GEIGLWSLVVLAIERYVVVCKPMSNFRFGENHAIMGVAFTWVMALACAAPPLVGWSRYIP
+EGMQCSCGIDYYTLKPEVNNESFVIYMFVVHFTIPMIVIFFCYGQLVFTVKEAAAQQQES
+ATTQKAEKEVTRMVIIMVIFFLICWLPYASVAMYIFTHQGSNFGPIFMTLPAFFAKTASI
+YNPIIYIMMNKQFRNCMLTSLCCGKNPLGDDEASATASKTETSQVAPA
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+MNGTEGINFYVPMSNKTGVVRSPFEYPQYYLAEPWKYRLVCCYIFFLISTGLPINLLTLL
+VTFKHKKLRQPLNYILVNLAVADLFMACFGFTVTFYTAWNGYFVFGPVGCAVEGFFATLG
+GQVALWSLVVLAIERYIVVCKPMGNFRFSATHAMMGIAFTWVMAFSCAAPPLFGWSRYMP
+EGMQCSCGPDYYTHNPDYHNESYVLYMFVIHFIIPVVVIFFSYGRLICKVREAAAQQQES
+ATTQKAEKEVTRMVILMVLGFMLAWTPYAVVAFWIFTNKGADFTATLMAVPAFFSKSSSL
+YNPIIYVLMNKQFRNCMITTICCGKNPFGDEDVSSTVSQSKTEVSSVSSSQVSPA
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+MNGTEGKNFYVPMSNRTGLVRSPFEYPQYYLAEPWQFKILALYLFFLMSMGLPINGLTLV
+VTAQHKKLRQPLNFILVNLAVAGTIMVCFGFTVTFYTAINGYFVLGPTGCAVEGFMATLG
+GEVALWSLVVLAIERYIVVCKPMGSFKFSSSHAFAGIAFTWVMALACAAPPLFGWSRYIP
+EGMQCSCGPDYYTLNPDYNNESYVIYMFVCHFILPVAVIFFTYGRLVCTVKAAAAQQQDS
+ASTQKAEREVTKMVILMVFGFLIAWTPYATVAAWIFFNKGADFSAKFMAIPAFFSKSSAL
+YNPVIYVLLNKQFRNCMLTTIFCGKNPLGDDESSTVSTSKTEVSSVSPA
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+MNGTEGNNFYVPLSNRTGLVRSPFEYPQYYLAEPWQFKLLAVYMFFLICLGLPINGLTLI
+CTAQHKKLRQPLNFILVNLAVAGAIMVCFGFTVTFYTAINGYFALGPTGCAVEGFMATLG
+GEVALWSLVVLAIERYIVVCKPMGSFKFSSTHASAGIAFTWVMAMACAAPPLVGWSRYIP
+EGIQCSCGPDYYTLNPEYNNESYVLYMFICHFILPVTIIFFTYGRLVCTVKAAAAQQQDS
+ASTQKAEREVTKMVILMVLGFLVAWTPYATVAAWIFFNKGAAFSAQFMAIPAFFSKTSAL
+YNPVIYVLLNKQFRSCMLTTLFCGKNPLGDEESSTVSTSKTEVSSVSPA
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+MKQVPEFHEDFYIPIPLDINNLSAYSPFLVPQDHLGNQGIFMAMSVFMFFIFIGGASINI
+LTILCTIQFKKLRSHLNYILVNLSIANLFVAIFGSPLSFYSFFNRYFIFGATACKIEGFL
+ATLGGMVGLWSLAVVAFERWLVICKPLGNFTFKTPHAIAGCILPWISALAASLPPLFGWS
+RYIPEGLQCSCGPDWYTTNNKYNNESYVMFLFCFCFAVPFGTIVFCYGQLLITLKLAAKA
+QADSASTQKAEREVTKMVVVMVLGFLVCWAPYASFSLWIVSHRGEEFDLRMATIPSCLSK
+ASTVYNPVIYVLMNKQFRSCMMKMVCGKNIEEDEASTSSQVTQVSSVAPEK
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+MRKMSEEEFYLFKNISSVGPWDGPQYHIAPVWAFYLQAAFMGTVFLIGFPLNAMVLVATL
+RYKKLRQPLNYILVNVSFGGFLLCIFSVFPVFVASCNGYFVFGRHVCALEGFLGTVAGLV
+TGWSLAFLAFERYIVICKPFGNFRFSSKHALTVVLATWTIGIGVSIPPFFGWSRFIPEGL
+QCSCGPDWYTVGTKYRSESYTWFLFIFCFIVPLSLICFSYTQLLRALKAVAAQQQESATT
+QKAEREVSRMVVVMVGSFCVCYVPYAAFAMYMVNNRNHGLDLRLVTIPSFFSKSACIYNP
+IIYCFMNKQFQACIMKMVCGKAMTDESDTCSSQKTEVSTVSSTQVGPN
+>     8=opsin, greensensitive  human (fragment) S07060
+DLAETVIASTISIVNQVSGYFVLGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKP
+FGNVRFDAKLAIVGIAFSWIWAAVWTAPPIFGWSRYWPHGLKTSCGPDVFSGSSYPGVQS
+YMIVLMVTCCITPLSIIVLCYLQVWLAIRAVAKQQKESESTQKAEKEVTRMVVVMVLAFC
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+MAQQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNSTRGPFEGPNYHIAPRWVYHLTSVWM
+IFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIASTISVVNQVYGYFV
+LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGNVRFDAKLAIVGIAFSWIWA
+AVWTAPPIFGWSRYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCITPLSIIVLCYL
+QVWLAIRAVAKQQKESESTQKAEKEVTRMVVVMVLAFCFCWGPYAFFACFAAANPGYPFH
+PLMAALPAFFAKSATIYNPVIYVFMNRQFRNCILQLFGKKVDDGSELSSASKTEVSSVSS
+VSPA
+>    10== Z68193   1 human Red Opsin <>[]
+MAQQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNSTRGPFEGPNYHIAPRWVYHLTSVWM
+IFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIASTISIVNQVSGYFV
+LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGNVRFDAKLAIVGIAFSWIWS
+AVWTAPPIFGWSRYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCIIPLAIIMLCYL
+QVWLAIRAVAKQQKESESTQKAEKEVTRMVVVMIFAYCVCWGPYTFFACFAAANPGYAFH
+PLMAALPAYFAKSATIYNPVIYVFMNRQFRNCILQLFGKKVDDGSELSSASKTEVSSVSS
+VSPA
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+MTEAWNVAVFAARRSRDDDDTTRGSVFTYTNTNNTRGPFEGPNYHIAPRWVYNLVSFFMI
+IVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVASTISVFNQIFGYFIL
+GHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGNIKFDSKLAIIGIVFSWVWAW
+GWSAPPIFGWSRYWPHGLKTSCGPDVFSGSVELGCQSFMLTLMITCCFLPLFIIIVCYLQ
+VWMAIRAVAAQQKESESTQKAEREVSRMVVVMIVAFCICWGPYASFVSFAAANPGYAFHP
+LAAALPAYFAKSATIYNPVIYVFMNRQFRNCIMQLFGKKVDDGSEASTTSRTEVSSVSNS
+SVAPA
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+MAAWEAAFAARRRHEEEDTTRDSVFTYTNSNNTRGPFEGPNYHIAPRWVYNLTSVWMIFV
+VAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIASTISVINQISGYFILGH
+PMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGNIKFDGKLAVAGILFSWLWSCAW
+TAPPIFGWSRYWPHGLKTSCGPDVFSGSSDPGVQSYMVVLMVTCCFFPLAIIILCYLQVW
+LAIRAVAAQQKESESTQKAEKEVSRMVVVMIVAYCFCWGPYTFFACFAAANPGYAFHPLA
+AALPAYFAKSATIYNPIIYVFMNRQFRNCILQLFGKKVDDGSEVSTSRTEVSSVSNSSVS
+PA
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+MSSNSSQAPPNGTPGPFDGPQWPYQAPQSTYVGVAVLMGTVVACASVVNGLVIVVSICYK
+KLRSPLNYILVNLAVADLLVTLCGSSVSLSNNINGFFVFGRRMCELEGFMVSLTGIVGLW
+SLAILALERYVVVCKPLGDFQFQRRHAVSGCAFTWGWALLWSAPPLLGWSSYVPEGLRTS
+CGPNWYTGGSNNNSYILSLFVTCFVLPLSLILFSYTNLLLTLRAAAAQQKEADTTQRAER
+EVTRMVIVMVMAFLLCWLPYSTFALVVATHKGIIIQPVLASLPSYFSKTATVYNPIIYVF
+MNKQFQSCLLEMLCCGYQPQRTGKASPGTPGPHADVTAAGLRNKVMPAHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+MESGNVSSSLFGNVSTALRPEARLSAETRLLGWNVPPEELRHIPEHWLTYPEPPESMNYL
+LGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVKTPIFIYNSFH
+QGYALGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEGKMTHGKAIAMIIFIY
+MYATPWVVACYTETWGRFVPEGYLTSCTFDYLTDNFDTRLFVACIFFFSFVCPTTMITYY
+YSQIVGHVFSHEKALRDQAKKMNVESLRSNVDKNKETAEIRIAKAAITICFLFFCSWTPY
+GVMSLIGAFGDKTLLTPGATMIPACACKMVACIDPFVYAISHPRYRMELQKRCPWLALNE
+KAPESSAVASTSTTQEPQQTTAA
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+MEYHNVSSVLGNVSSVLRPDARLSAESRLLGWNVPPDELRHIPEHWLIYPEPPESMNYLL
+GTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIKTPIFIYNSFHQ
+GYALGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEGKMTHGKAIAMIIFIYL
+YATPWVVACYTESWGRFVPEGYLTSCTFDYLTDNFDTRLFVACIFFFSFVCPTTMITYYY
+SQIVGHVFSHEKALRDQAKKMNVDSLRSNVDKSKEAAEIRIAKAAITICFLFFASWTPYG
+VMSLIGAFGDKTLLTPGATMIPACTCKMVACIDPFVYAISHPRYRMELQKRCPWLAISEK
+APESRAAISTSTTQEQQQTTAA
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+MEPLCNASEPPLRPEARSSGNGDLQFLGWNVPPDQIQYIPEHWLTQLEPPASMHYMLGVF
+YIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLKAPIFNSFHRGFAIY
+LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNRNMTFTKAVIMNIIIWLYCT
+PWVVLPLTQFWDRFVPEGYLTSCSFDYLSDNFDTRLFVGTIFFFSFVCPTLMILYYYSQI
+VGHVFSHEKALREQAKKMNVESLRSNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVMS
+LIGAFGDKSLLTQGATMIPACTCKLVACIDPFVYAISHPRYRLELQKRCPWLGVNEKSGE
+ISSAQSTTTQEQQQTTAA
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+MDALCNASEPPLRPEARMSSGSDELQFLGWNVPPDQIQYIPEHWLTQLEPPASMHYMLGV
+FYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLKAPIFIYNSFHRGF
+ALGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNRNMTFTKAVIMNIIIWLYC
+TPWVVLPLTQFWDRFVPEGYLTSCSFDYLSDNFDTRLFVGTIFLFSFVVPTLMILYYYSQ
+IVGHVFNHEKALREQAKKMNVESLRSNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVM
+SLIGAFGDKSLLTPGATMIPACTCKLVACIEPFVYAISHPRYRMELQKRCPWLGVNEKSG
+EASSAQSTTTQEQTQQTSAA
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+MTNATGPQMAYYGAASMDFGYPEGVSIVDFVRPEIKPYVHQHWYNYPPVNPMWHYLLGVI
+YLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTNVPFFTYNCFSGGV
+WMFSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNGPKLTTGKAVVFALISWV
+IAIGCALPPFFGWGNYILEGILDSCSYDYLTQDFNTFSYNIFIFVFDYFLPAAIIVFSYV
+FIVKAIFAHEAAMRAQAKKMNVSTLRSNEADAQRAEIRIAKTALVNVSLWFICWTPYALI
+SLKGVMGDTSGITPLVSTLPALLAKSCSCYNPFVYAISHPKYRLAITQHLPWFCVHETET
+KSNDDSQSNSTVAQDKA
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+MANVTGPQMAFYGSGAATFGYPEGMTVADFVPDRVKHMVLDHWYNYPPVNPMWHYLLGVV
+YLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTNFPPFCYNCFSGGR
+WMFSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNGPKLTQGKATFMCGLAWV
+ISVGWSLPPFFGWGSYTLEGILDSCSYDYFTRDMNTITYNICIFIFDFFLPASVIVFSYV
+FIVKAIFAHEAAMRAQAKKMNVTNLRSNEAETQRAEIRIAKTALVNVSLWFICWTPYAAI
+TIQGLLGNAEGITPLLTTLPALLAKSCSCYNPFVYAISHPKFRLAITQHLPWFCVHEKDP
+NDVEENQSSNTQTQEKS
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+MESFAVAAAQLGPHFAPLSNGSVVDKVTPDMAHLISPYWNQFPAMDPIWAKILTAYMIMI
+GMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITNTPMMGINLYFETWVLGP
+MMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGRPMTIPLALGKMYVPEGNLTSC
+GIDYLERDWNPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSL
+RSSEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGLFKFEGLTPLNTIWGACFAKS
+AACYNPIVYGISHPKYRLALKEKCPCCVFGKVDDGKSSDAQSQATASEAESKA
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+MESFAVAAAQLGPHFAPLSNGSVVDKVTPDMAHLISPYWNQFPAMDPIWAKILTAYMIMI
+GMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITNTPMMGINLYFETWVLGP
+MMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGRPMTIPLALGKIAYIWFMSSIW
+CLAPAFGWSRYVPEGNLTSCGIDYLERDWNPRSYLIFYSIFVYYIPLFLICYSYWFIIAA
+VSAHEKAMREQAKKMNVKSLRSSEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGL
+FKFEGLTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVFGKVDDGKSSDA
+QSQATASEAESKA
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+MDSFAAVATQLGPQFAAPSNGSVVDKVTPDMAHLISPYWDQFPAMDPIWAKILTAYMIII
+GMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITNTPMMGINLYFETWVLGP
+MMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGRPMTIPLALGKIAYIWFMSTIW
+CCLAPVFGWSRYVPEGNLTSCGIDYLERDWNPRSYLIFYSIFVYYIPLFLICYSYWFIIA
+AVSAHEKAMREQAKKMNVKSLRSSEDADKSAEGKLAKVALVTISLWFMAWTPYLVINCMG
+LFKFEGLTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVFGKVDDGKSSE
+AQSQATTSEAESKA
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+MERSHLPETPFDLAHSGPRFQAQSSGNGSVLDNVLPDMAHLVNPYWSRFAPMDPMMSKIL
+GLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQSPVMIINFYY
+ETWVLGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGINGTPMTIKTSIMKILFI
+WMMAVFWTVMPLIGWSAYVPEGNLTACSIDYMTRMWNPRSYLITYSLFVYYTPLFLICYS
+YWFIIAAVAAHEKAMREQAKKMNVKSLRSSEDCDKSAEGKLAKVALTTISLWFMAWTPYL
+VICYFGLFKIDGLTPLTTIWGATFAKTSAVYNPIVYGISHPKYRIVLKEKCPMCVFGNTD
+EPKPDAPASDTETTSEADSKA
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+MERSLLPEPPLAMALLGPRFEAQTGGNRSVLDNVLPDMAPLVNPHWSRFAPMDPTMSKIL
+GLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQSPVMIINFYY
+ETWVLGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGINGTPMTIKTSIMKIAFI
+WMMAVFWTIMPLIGWSSYVPEGNLTACSIDYMTRQWNPRSYLITYSLFVYYTPLFMICYS
+YWFIIATVAAHEKAMRDQAKKMNVKSLRSSEDCDKSAENKLAKVALTTISLWFMAWTPYL
+IICYFGLFKIDGLTPLTTIWGATFAKTSAVYNPIVYGISHPNDRLVLKEKCPMCVCGTTD
+EPKPDAPPSDTETTSEAESKD
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+MIAVSGPSYEAFSYGGQARFNNQTVVDKVPPDMLHLIDANWYQYPPLNPMWHGILGFVIG
+MLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCMSPPMVINCYYETWVL
+GPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSGKPLSINGALIRIIAIWLFSL
+GWTIAPMFGWNRYVPEGNMTACGTDYFNRGLLSASYLVCYGIWVYFVPLFLIIYSYWFII
+QAVAAHEKNMREQAKKMNVASLRSSENQNTSAECKLAKVALMTISLWFMAWTPYLVINFS
+GIFNLVKISPLFTIWGSLFAKANAVYNPIVYGISHPKYRAALFAKFPSLACAAEPSSDAV
+STTSGTTTVTDNEKSNA
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+MANQLSYSSLGWPYQPNASVVDTMPKEMLYMIHEHWYAFPPMNPLWYSILGVAMIILGII
+CVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFMMPTMTSNCFAETWILGPFMC
+EVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAAAPLTHKKATLLLLFVWIWSGGWTIL
+PFFGWSRYVPEGNLTSCTVDYLTKDWSSASYVVIYGLAVYFLPLITMIYCYFFIVHAVAE
+HEKQLREQAKKMNVASLRANADQQKQSAECRLAKVAMMTVGLWFMAWTPYLIISWAGVFS
+SGTRLTPLATIWGSVFAKANSCYNPIVYGISHPRYKAALYQRFPSLACGSGESGSDVKSE
+ASATTTMEEKPKIPEA
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+MVESTTLVNQTWWYNPTVDIHPHWAKFDPIPDAVYYSVGIFIGVVGIIGILGNGVVIYLF
+SKTKSLQTPANMFIINLAMSDLSFSAINGFPLKTISAFMKKWIFGKVACQLYGLLGGIFG
+FMSINTMAMISIDRYNVIGRPMAASKKMSHRRAFLMIIFVWMWSIVWSVGPVFNWGAYVP
+EGILTSCSFDYLSTDPSTRSFILCMYFCGFMLPIIIIAFCYFNIVMSVSNHEKEMAAMAK
+RLNAKELRKAQAGASAEMKLAKISMVIITQFMLSWSPYAIIALLAQFGPAEWVTPYAAEL
+PVLFAKASAIHNPIVYSVSHPKFREAIQTTFPWLLTCCQFDEKECEDANDAEEEVVASER
+GGESRDAAQMKEMMAMMQKMQAQQAAYQPPPPPQGYPPQGYPPQGAYPPPQGYPPQGYPP
+QGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQAYQA
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+MGRDLRDNETWWYNPSIVVHPHWREFDQVPDAVYYSLGIFIGICGIIGCGGNGIVIYLFT
+KTKSLQTPANMFIINLAFSDFTFSLVNGFPLMTISCFLKKWIFGFAACKVYGFIGGIFGF
+MSIMTMAMISIDRYNVIGRPMAASKKMSHRRAFIMIIFVWLWSVLWAIGPIFGWGAYTLE
+GVLCNCSFDYISRDSTTRSNILCMFILGFFGPILIIFFCYFNIVMSVSNHEKEMAAMAKR
+LNAKELRKAQAGANAEMRLAKISIVIVSQFLLSWSPYAVVALLAQFGPLEWVTPYAAQLP
+VMFAKASAIHNPMIYSVSHPKFREAISQTFPWVLTCCQFDDKETEDDKDAETEIPAGESS
+DAAPSADAAQMKEMMAMMQKMQQQQAAYPPQGYAPPPQGYPPQGYPPQGYPPQGYPPQGY
+PPPPQGAPPQGAPPAAPPQGVDNQAYQA
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDGGADPVAGSWAPHLLSEVTASPAPTW
+DAPPDNASGCGEQINYGRVEKVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLI
+VSLALADLSVAVAVMPFVSVTDLIGGKWIFGHFFCNVFIAMDVMCCTASIMTLCVISIDR
+YLGITRPLTYPVRQNGKCMAKMILSVWLLSASITLPPLFGWAQNVNDDKVCLISQDFGYT
+IYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRVEPDSVIALNGIVKLQKEVE
+ECANLSRLLKHERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSC
+IPLWVERTFLWLGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMHEALK
+LAERPERPEFVLQNADYCRKKGHDS
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+MPHLLSGFLEVTASPAPTWDAPPDNVSGCGEQINYGRVEKVVIGSILTLITLLTIAGNCL
+VVISVSFVKKLRQPSNYLIVSLALADLSVAVAVMPFVSVTDLIGGKWIFGHFFCNVFIAM
+DVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLLSASITLPPLFGW
+AQNVNDDKVCLISQDFGYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRV
+QPESVISLNGVVKLQKEVEECANLSRLLKHERKNISIFKREQKAATTLGIIVGAFTVCWL
+PFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRPTSRSLLQC
+QYRNINRKLSAAGMHEALKLAERPERSEFVLQNSDHCGKKGHDT
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+MPHLLSGFLEVTASPAPTWDAPPDNVSGCGEQINYGRVEKVVIGSILTLITLLTIAGNCL
+VVISVSFVKKLRQPSNYLIVSLALADLSVAVAVMPFVSVTDLIGGKWIFGHFFCNVFIAM
+DVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLLSASITLPPLFGW
+AQNVNDDKVCLISQDFGYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRV
+QPESVISLNGVVKLQKEVEECANLSRLLKHERKNISIFKREQKAATTLGIIVGAFTVCWL
+PFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRTTYRSLLQC
+QYRNINRKLSAAGMHEALKLAERPERSEFVLQNSDHCGKKGHDT
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+MDVLSPGQGNNTTSPPAPFETGGNTTGISDVTVSYQVITSLLLGTLIFCAVLGNACVVAA
+IALERSLQNVANYLIGSLAVTDLMVSVLVLPMAALYQVLNKWTLGQVTCDLFIALDVLCC
+TSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLIGFLISIPPMLGWRTPED
+RSDPDACTISKDHGYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVKKVEKTGADT
+RHGASPAPQPKKSVNGESGSRNWRLGVESKAGGALCANGAVRQGDDGAALEVIEVHRVGN
+SKEHLPLPSEAGPTPCAPASFERKNERNAEAKRKMALARERKTVKTLGIIMGTFILCWLP
+FFIVALVLPFCESSCHMPTLLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFC
+RQ
+>    33=p A35181 serotonin receptor class 1A - rat
+MDVFSFGQGNNTTASQEPFGTGGNVTSISDVTFSYQVITSLLLGTLIFCAVLGNACVVAA
+IALERSLQNVANYLIGSLAVTDLMVSVLVLPMAALYQVLNKWTLGQVTCDLFIALDVLCC
+TSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLIGFLISIPPMLGWRTPED
+RSDPDACTISKDHGYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVRKVEKKGAGT
+SLGTSSAPPPKKSLNGQPGSGDWRRCAENRAVGTPCTNGAVRQGDDEATLEVIEVHRVGN
+SKEHLPLPSESGSNSYAPACLERKNERNAEAKRKMALARERKTVKTLGIIMGTFILCWLP
+FFIVALVLPFCESSCHMPALLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFC
+RR
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDTSATNMTDDRYWSLTVYSHEHLVLTSVILGLFVLCCIIGNCFVIAAV
+MLERSLHNVANYLILSLAVADLMVAVLVMPLSVVSEISKVWFLHSEVCDMWISVDVLCCT
+ASILHLVAIAMDRYWAVTSIDYIRRRSARRILLMIMVVWIVALFISIPPLFGWRDPNNDP
+DKTGTCIISQDKGYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTE
+ETTLVASPKTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENA
+NGVNSNSSSSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYSRTREK
+LELKRERKAARTLAIITGAFLICWLPFFIIALIGPFVDPEGIPPFARSFVLWLGYFNSLL
+NPIIYTIFSPEFRSAFQKILFGKYRRGHR
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDTSATNMTDDRYWSLTVYSHEHLVLTSVILGLFVLCCIIGNCFVIAAV
+MLERSLHNVANYLILSLAVADLMVAVLVMPLSVVSEISKVWFLHSEVCDMWISVDVLCCT
+ASILHLVAIAMDRYWAVTSIDYIRRRSARRILLMIMVVWIVALFISIPPLFGWRDPNNDP
+DKTGTCIISQDKGYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTE
+ETTLVASPKTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENA
+NGVNSNSSSSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYSRTREK
+LELKRERKAARTLAIITGAFLICWLPFFIIALIGPFVDPEGIPPFARSFVLWLGYFNSLL
+NPIIYTIFSPEFRSAFQKILFGKYRRGHR
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+MEGAEGQEELDWEALYLRLPLQNCSWNSTGWEPNWNVTVVPNTTWWQASAPFDTPAALVR
+AAAKAVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLVMPLGAV
+YEVVQRWTLGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTNIDYIHASTAKRVGMM
+IACVWTVSFFVCIAQLLGWKDPDWNQRVSEDLRCVVSQDVGYQIFATASSFYVPVLIILI
+LYWRIYQTARKRIRRRRGATARGGVGPPPVPAGGALVAGGGSGGIAAAVVAVIGRPLPTI
+SETTTTGFTNVSSNNTSPEKQSCANGLEADPPTTGYGAVAAAYYPSLVRRKPKEAADSKR
+ERKAAKTLAIITGAFVACWLPFFVLAILVPTCDCEVSPVLTSLSLWLGYFNSTLNPVIYT
+VFSPEFRHAFQRLLCGRRVRRRRAPQ
diff --git a/binaries/src/mafft/test/sample.dpparttree b/binaries/src/mafft/test/sample.dpparttree
new file mode 100644 (file)
index 0000000..4a698ea
--- /dev/null
@@ -0,0 +1,576 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+M-----------------------------------------------------------
+-----------------------------------NGTE--GDNFYVPF-----------
+---------------------------------------------SNKTGLARSPYEYPQ
+Y-YLAEPW------------K--------------------------------YSALAAY
+MFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-FTVTMYTS-MN-
+GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN-FRFGNTHAIMGV
+AFTWIMALAC-AAPPLVG-WSRYIP-------EGM----QCSCGPDYYTLNPNFNNESYV
+VYMFVVHFLVPFVIIFFCYGRLLCTV----KE----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAAQQE-------
+------------------------------SASTQKAEKEVTRMVVLMVIGFLVCWVPYA
+SVAFYIFT-HQG-S--DFGATFMTLPAFFAKSSALYNPVIYILMNKQFRNCMITTLC-C-
+--GKNP-------------------LGDDE--SGASTSKT-E--VSSVS-TSPV------
+------------------------------------------------------------
+-------------------SP-A---
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+M-----------------------------------------------------------
+-----------------------------------NGTE--GPNFYVPF-----------
+---------------------------------------------SNITGVVRSPFEQPQ
+Y-YLAEPW------------Q--------------------------------FSMLAAY
+MFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-FTTTLYTS-LH-
+GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN-FRFGENHAIMGV
+AFTWVMALAC-AAPPLVG-WSRYIP-------EGM----QCSCGIDYYTLKPEVNNESFV
+IYMFVVHFTIPMIVIFFCYGQLVFTV----KE----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAQQQE-------
+------------------------------SATTQKAEKEVTRMVIIMVIFFLICWLPYA
+SVAMYIFT-HQG-S--NFGPIFMTLPAFFAKTASIYNPIIYIMMNKQFRNCMLTSLC-C-
+--GKNP-------------------LGDDE--ASATASKT-E--------TSQV------
+------------------------------------------------------------
+-------------------AP-A---
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+M-----------------------------------------------------------
+-----------------------------------NGTE--GINFYVPM-----------
+---------------------------------------------SNKTGVVRSPFEYPQ
+Y-YLAEPW------------K--------------------------------YRLVCCY
+IFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-FTVTFYTA-WN-
+GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN-FRFSATHAMMGI
+AFTWVMAFSC-AAPPLFG-WSRYMP-------EGM----QCSCGPDYYTHNPDYHNESYV
+LYMFVIHFIIPVVVIFFSYGRLICKV----RE----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAQQQE-------
+------------------------------SATTQKAEKEVTRMVILMVLGFMLAWTPYA
+VVAFWIFT-NKG-A--DFTATLMAVPAFFSKSSSLYNPIIYVLMNKQFRNCMITTIC-C-
+--GKNP-------------------FGDEDVSSTVSQSKT-E--VSSVS-SSQV------
+------------------------------------------------------------
+-------------------SP-A---
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+M-----------------------------------------------------------
+-----------------------------------NGTE--GKNFYVPM-----------
+---------------------------------------------SNRTGLVRSPFEYPQ
+Y-YLAEPW------------Q--------------------------------FKILALY
+LFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-FTVTFYTA-IN-
+GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSSSHAFAGI
+AFTWVMALAC-AAPPLFG-WSRYIP-------EGM----QCSCGPDYYTLNPDYNNESYV
+IYMFVCHFILPVAVIFFTYGRLVCTV----KA----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAQQQD-------
+------------------------------SASTQKAEREVTKMVILMVFGFLIAWTPYA
+TVAAWIFF-NKG-A--DFSAKFMAIPAFFSKSSALYNPVIYVLLNKQFRNCMLTTIF-C-
+--GKNP-------------------LGDDE-SSTVSTSKT-E--VSS------V------
+------------------------------------------------------------
+-------------------SP-A---
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+M-----------------------------------------------------------
+-----------------------------------NGTE--GNNFYVPL-----------
+---------------------------------------------SNRTGLVRSPFEYPQ
+Y-YLAEPW------------Q--------------------------------FKLLAVY
+MFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-FTVTFYTA-IN-
+GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSSTHASAGI
+AFTWVMAMAC-AAPPLVG-WSRYIP-------EGI----QCSCGPDYYTLNPEYNNESYV
+LYMFICHFILPVTIIFFTYGRLVCTV----KA----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAQQQD-------
+------------------------------SASTQKAEREVTKMVILMVLGFLVAWTPYA
+TVAAWIFF-NKG-A--AFSAQFMAIPAFFSKTSALYNPVIYVLLNKQFRSCMLTTLF-C-
+--GKNP-------------------LGDEE-SSTVSTSKT-E--VSS------V------
+------------------------------------------------------------
+-------------------SP-A---
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+M-----------------------------------------------------------
+-----------------------------------KQVPEFHEDFYIPIPL---------
+-------------------------------------------DINNLS--AYSPFLVPQ
+D-HLGNQG------------I--------------------------------FMAMSVF
+MFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-SPLSFYSF-FN-
+RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN-FTFKTPHAIAGC
+ILPWISALAA-SLPPLFG-WSRYIP-------EGL----QCSCGPDWYTTNNKYNNESYV
+MFLFCFCFAVPFGTIVFCYGQLLITL----KL----------------------------
+------------------------------------------------------------
+----------------------------------------------AAKAQAD-------
+------------------------------SASTQKAEREVTKMVVVMVLGFLVCWAPYA
+SFSLWIVS-HRG-E--EFDLRMATIPSCLSKASTVYNPVIYVLMNKQFRSCMM-KMV-C-
+--GKN--------------------IEEDE--ASTSSQVT-Q--VSS------V------
+------------------------------------------------------------
+-------------------APEK---
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+M-----------------------------------------------------------
+-----------------------------------RKMS--EEEFYL---F---------
+---------------------------------------------KNISSV--GPWDGPQ
+Y-HIAPVW------------A--------------------------------FYLQAAF
+MGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-VFPVFVAS-CN-
+GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN-FRFSSKHALTVV
+LATWTIGIGV-SIPPFFG-WSRFIP-------EGL----QCSCGPDWYTVGTKYRSESYT
+WFLFIFCFIVPLSLICFSYTQLLRAL----KA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAAQQQE-------
+------------------------------SATTQKAEREVSRMVVVMVGSFCVCYVPYA
+AFAMYMVN-NRN-H--GLDLRLVTIPSFFSKSACIYNPIIYCFMNKQFQACIM-KMV-C-
+--GKA--------------------MTDES--DTCSSQKT-E--VSTVS-STQV------
+------------------------------------------------------------
+-------------------GP-N---
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------DLAETVIA-STISIVNQ-VS-
+GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDAKLAIVGI
+AFSWIWAAVW-TAPPIFG-WSRYWP-------HGL----KTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCITPLSIIVLCYLQVWLAI----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAKQQKE-------
+------------------------------SESTQKAEKEVTRMVVVMVLAFC-------
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+M--------------AQQWSLQRLAGRHPQDSYE--------------------------
+-----------------------------------DSTQ--SSIFTYTN-----------
+---------------------------------------------SNST---RGPFEGPN
+Y-HIAPRW------------V--------------------------------YHLTSVW
+MIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISVVNQ-VY-
+GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN-VRFDAKLAIVGI
+AFSWIWAAVW-TAPPIFG-WSRYWP-------HGL----KTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCITPLSIIVLCYLQVWLAI----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAKQQKE-------
+------------------------------SESTQKAEKEVTRMVVVMVLAFCFCWGPYA
+FFACFAAA-NPG-Y--PFHPLMAALPAFFAKSATIYNPVIYVFMNRQFRNCIL-QLF---
+--GKK--------------------VDDGS--ELSSASKT-E--VSSV---SSV------
+------------------------------------------------------------
+-------------------SP-A---
+>    10== Z68193   1 human Red Opsin <>[]
+M--------------AQQWSLQRLAGRHPQDSYE--------------------------
+-----------------------------------DSTQ--SSIFTYTN-----------
+---------------------------------------------SNST---RGPFEGPN
+Y-HIAPRW------------V--------------------------------YHLTSVW
+MIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISIVNQ-VS-
+GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDAKLAIVGI
+AFSWIWSAVW-TAPPIFG-WSRYWP-------HGL----KTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCIIPLAIIMLCYLQVWLAI----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAKQQKE-------
+------------------------------SESTQKAEKEVTRMVVVMIFAYCVCWGPYT
+FFACFAAA-NPG-Y--AFHPLMAALPAYFAKSATIYNPVIYVFMNRQFRNCIL-QLF---
+--GKK--------------------VDDGS--ELSSASKT-E--VSSV---SSV------
+------------------------------------------------------------
+-------------------SP-A---
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+M--------------TEAWNVAVFAARRSRDD-D--------------------------
+-----------------------------------DTTR--GSVFTYTN-----------
+---------------------------------------------TNNT---RGPFEGPN
+Y-HIAPRW------------V--------------------------------YNLVSFF
+MIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-STISVFNQ-IF-
+GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN-IKFDSKLAIIGI
+VFSWVWAWGW-SAPPIFG-WSRYWP-------HGL----KTSCGPDVFSGSVELGCQSFM
+LTLMITCCFLPLFIIIVCYLQVWMAI----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAAQQKE-------
+------------------------------SESTQKAEREVSRMVVVMIVAFCICWGPYA
+SFVSFAAA-NPG-Y--AFHPLAAALPAYFAKSATIYNPVIYVFMNRQFRNCIM-QLF---
+--GKK--------------------VDDGS--EASTTSRT-E--VSSVS-NSSV------
+------------------------------------------------------------
+-------------------AP-A---
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+M--------------AA-WEAAFAARRRHEE--E--------------------------
+-----------------------------------DTTR--DSVFTYTN-----------
+---------------------------------------------SNNT---RGPFEGPN
+Y-HIAPRW------------V--------------------------------YNLTSVW
+MIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-STISVINQ-IS-
+GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN-IKFDGKLAVAGI
+LFSWLWSCAW-TAPPIFG-WSRYWP-------HGL----KTSCGPDVFSGSSDPGVQSYM
+VVLMVTCCFFPLAIIILCYLQVWLAI----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------VAAQQKE-------
+------------------------------SESTQKAEKEVSRMVVVMIVAYCFCWGPYT
+FFACFAAA-NPG-Y--AFHPLAAALPAYFAKSATIYNPIIYVFMNRQFRNCIL-QLF---
+--GKK--------------------VDDGS--EVST-SRT-E--VSSVS-NSSV------
+------------------------------------------------------------
+-------------------SP-A---
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+M--------------S-----------------S--------------------------
+-----------------------------------NSSQ--AP-----------------
+---------------------------------------------PNGT---PGPFDGPQ
+WPYQAPQS------------T--------------------------------YVGVAVL
+MGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-SSVSLSNN-IN-
+GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD-FQFQRRHAVSGC
+AFTWGWALLW-SAPPLLG-WSSYVP-------EGL----RTSCGPNWYTGGSNN--NSYI
+LSLFVTCFVLPLSLILFSYTNLLLTL----RA----------------------------
+------------------------------------------------------------
+----------------------------------------------AAAQQKE-------
+------------------------------ADTTQRAEREVTRMVIVMVMAFLLCWLPYS
+TFALVVAT-HKG-I--IIQPVLASLPSYFSKTATVYNPIIYVFMNKQFQSCLL-EMLCCG
+YQPQR--------------------TGKAS--PGTPGPHA-D--VTAAGLRNKV------
+------------------------------------------------------------
+-------------------MP-AHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+M--------------------------------ES-G-----------------------
+-----------------------------------NVSS-----------SLFGNVSTAL
+RPEA------------------RLSA---ETRLLGWNVPPEELR----------------
+--HIPEHW------------LT---------YPEPPESM--------------NYLLGTL
+YIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--TPIFIYNS-FH-
+QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--KMTHGKAIAMI
+IFIYMYATPW-VVACYTETWGRFVP-------EGY----LTSCTFDYLT--DNFDTRLFV
+ACIFFFSFVCPTTMITYYYSQIVGHVFSHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------LRDQAKK--MNVES
+L------------------------RS-NVDKNKETAEIRIAKAAITICFLFFCSWTPYG
+VMSLIGAF-GDK-T--LLTPGATMIPACACKMVACIDPFVYAISHPRYRMELQ-------
+--KRCP----WLALNE---KAPE--SSAVA--STSTTQEP-Q------------------
+-------QT---------------------------------------------------
+-------------------TA-A---
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+M--------------------------------EY-H-----------------------
+-----------------------------------NVSS-----------VL-GNVSSVL
+RPDA------------------RLSA---ESRLLGWNVPPDELR----------------
+--HIPEHW------------LI---------YPEPPESM--------------NYLLGTL
+YIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--TPIFIYNS-FH-
+QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--KMTHGKAIAMI
+IFIYLYATPW-VVACYTESWGRFVP-------EGY----LTSCTFDYLT--DNFDTRLFV
+ACIFFFSFVCPTTMITYYYSQIVGHVFSHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------LRDQAKK--MNVDS
+L------------------------RS-NVDKSKEAAEIRIAKAAITICFLFFASWTPYG
+VMSLIGAF-GDK-T--LLTPGATMIPACTCKMVACIDPFVYAISHPRYRMELQ-------
+--KRCP----WLAISE---KAPE--SRAAI--STSTTQEQ-Q------------------
+-------QT---------------------------------------------------
+-------------------TA-A---
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+M--------------------------------EPLC-----------------------
+-----------------------------------NASE-----------PP-------L
+RPEA------------------R-SSGNGDLQFLGWNVPPDQIQ----------------
+--YIPEHW------------LT---------QLEPPASM--------------HYMLGVF
+YIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF--NS-FH-
+RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMN
+IIIWLYCTPW-VVLPLTQFWDRFVP-------EGY----LTSCSFDYLS--DNFDTRLFV
+GTIFFFSFVCPTLMILYYYSQIVGHVFSHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------LREQAKK--MNVES
+L------------------------RS-NVDKSKETAEIRIAKAAITICFLFFVSWTPYG
+VMSLIGAF-GDK-S--LLTQGATMIPACTCKLVACIDPFVYAISHPRYRLELQ-------
+--KRCP----WLGVNE---KSGE--ISSAQ--ST-TTQEQ-Q------------------
+-------QT---------------------------------------------------
+-------------------TA-A---
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+M--------------------------------DALC-----------------------
+-----------------------------------NASE-----------PP-------L
+RPEA------------------RMSSGSDELQFLGWNVPPDQIQ----------------
+--YIPEHW------------LT---------QLEPPASM--------------HYMLGVF
+YIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIFIYNS-FH-
+RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMN
+IIIWLYCTPW-VVLPLTQFWDRFVP-------EGY----LTSCSFDYLS--DNFDTRLFV
+GTIFLFSFVVPTLMILYYYSQIVGHVFNHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------LREQAKK--MNVES
+L------------------------RS-NVDKSKETAEIRIAKAAITICFLFFVSWTPYG
+VMSLIGAF-GDK-S--LLTPGATMIPACTCKLVACIEPFVYAISHPRYRMELQ-------
+--KRCP----WLGVNE---KSGE--ASSAQ--ST-TTQEQTQ------------------
+-------QT---------------------------------------------------
+-------------------SA-A---
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+M--------------------------------------------TNATGPQMAYYGAAS
+MDFGYPE----------------------------GVSI-----------VD--------
+------------------------------------FVRPEIKP----------------
+--YVHQHW------------YN---------YPPVNPMW--------------HYLLGVI
+YLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-VPFFTYNC-FSG
+GVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG-PKLTTGKAVVFA
+LISWVIAIGC-ALPPFFG-WGNYIL-------EGI----LDSCSYDYLT--QDFNTFSYN
+IFIFVFDYFLPAAIIVFSYVFIVKAIFAHEAA----------------------------
+------------------------------------------------------------
+----------------------------------------------MRAQAKK--MNVST
+L------------------------RS-N-EADAQRAEIRIAKTALVNVSLWFICWTPYA
+LISLKGVM-GDT-S--GITPLVSTLPALLAKSCSCYNPFVYAISHPKYRLAIT-------
+--QHLP----WFCVHE---TETKS-NDDSQ--SNSTVAQ---------------------
+------------------------------------------------------------
+-------------------DK-A---
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+M--------------------------------------------ANVTGPQMAFYGSGA
+ATFGYPE----------------------------GMTV-----------AD--------
+------------------------------------FVPDRVKH----------------
+--MVLDHW------------YN---------YPPVNPMW--------------HYLLGVV
+YLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-FPPFCYNC-FSG
+GRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG-PKLTQGKATFMC
+GLAWVISVGW-SLPPFFG-WGSYTL-------EGI----LDSCSYDYFT--RDMNTITYN
+ICIFIFDFFLPASVIVFSYVFIVKAIFAHEAA----------------------------
+------------------------------------------------------------
+----------------------------------------------MRAQAKK--MNVTN
+L------------------------RS-N-EAETQRAEIRIAKTALVNVSLWFICWTPYA
+AITIQGLL-GNA-E--GITPLLTTLPALLAKSCSCYNPFVYAISHPKFRLAIT-------
+--QHLP----WFCVHE---KDPND-VEENQ--SSNTQTQ---------------------
+------------------------------------------------------------
+-------------------EK-S---
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+M--------------------------------E------SFAVAAAQLGPHFAPLS---
+-----------------------------------NGSV-----------VD--------
+------------------------------------KVTPDMAH----------------
+--LISPYW------------NQ---------FPAMDPIW--------------AKILTAY
+MIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINL-YF-
+ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIPLALGKM
+----------------------YVP-------EGN----LTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------MREQAKK--MNVKS
+L------------------------RS-S-EDAEKSAEGKLAKVALVTITLWFMAWTPYL
+VINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALK-------
+--EKCP----CCVFGK---VDDGK-SSDAQ--SQATASEA-E------------------
+------------------------------------------------------------
+-------------------SK-A---
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+M--------------------------------E------SFAVAAAQLGPHFAPLS---
+-----------------------------------NGSV-----------VD--------
+------------------------------------KVTPDMAH----------------
+--LISPYW------------NQ---------FPAMDPIW--------------AKILTAY
+MIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINL-YF-
+ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIPLALGKI
+AYIWFMSSIW-CLAPAFG-WSRYVP-------EGN----LTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------MREQAKK--MNVKS
+L------------------------RS-S-EDAEKSAEGKLAKVALVTITLWFMAWTPYL
+VINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALK-------
+--EKCP----CCVFGK---VDDGK-SSDAQ--SQATASEA-E------------------
+------------------------------------------------------------
+-------------------SK-A---
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+M--------------------------------D------SFAAVATQLGPQFAAPS---
+-----------------------------------NGSV-----------VD--------
+------------------------------------KVTPDMAH----------------
+--LISPYW------------DQ---------FPAMDPIW--------------AKILTAY
+MIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINL-YF-
+ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIPLALGKI
+AYIWFMSTIWCCLAPVFG-WSRYVP-------EGN----LTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------MREQAKK--MNVKS
+L------------------------RS-S-EDADKSAEGKLAKVALVTISLWFMAWTPYL
+VINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALK-------
+--EKCP----CCVFGK---VDDGK-SSEAQ--SQATTSEA-E------------------
+------------------------------------------------------------
+-------------------SK-A---
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+M--------------------------------ER-SHLPETPFDLAHSGPRFQAQSSG-
+-----------------------------------NGSV-----------LD--------
+------------------------------------NVLPDMAH----------------
+--LVNPYW------------SR---------FAPMDPMM--------------SKILGLF
+TLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINF-YY-
+ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTIKTSIMKI
+LFIWMMAVFW-TVMPLIG-WSAYVP-------EGN----LTACSIDYMT--RMWNPRSYL
+ITYSLFVYYTPLFLICYSYWFIIAAVAAHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------MREQAKK--MNVKS
+L------------------------RS-S-EDCDKSAEGKLAKVALTTISLWFMAWTPYL
+VICYFGLF--KI-D--GLTPLTTIWGATFAKTSAVYNPIVYGISHPKYRIVLK-------
+--EKCP----MCVFGN---TDEPKPDAPAS--DTETTSEA-D------------------
+------------------------------------------------------------
+-------------------SK-A---
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+M--------------------------------ER-SLLPEPPLAMALLGPRFEAQTGG-
+-----------------------------------NRSV-----------LD--------
+------------------------------------NVLPDMAP----------------
+--LVNPHW------------SR---------FAPMDPTM--------------SKILGLF
+TLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINF-YY-
+ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTIKTSIMKI
+AFIWMMAVFW-TIMPLIG-WSSYVP-------EGN----LTACSIDYMT--RQWNPRSYL
+ITYSLFVYYTPLFMICYSYWFIIATVAAHEKA----------------------------
+------------------------------------------------------------
+----------------------------------------------MRDQAKK--MNVKS
+L------------------------RS-S-EDCDKSAENKLAKVALTTISLWFMAWTPYL
+IICYFGLF--KI-D--GLTPLTTIWGATFAKTSAVYNPIVYGISHPNDRLVLK-------
+--EKCP----MCVCGT---TDEPKPDAPPS--DTETTSEA-E------------------
+------------------------------------------------------------
+-------------------SK-D---
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+M--------------------------------------------IAVSGPSYEAFSYG-
+---GQAR--------------------------FNNQTV-----------VD--------
+------------------------------------KVPPDMLH----------------
+--LIDANW------------YQ---------YPPLNPMW--------------HGILGFV
+IGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-SPPMVINC-YY-
+ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG-KPLSINGALIRI
+IAIWLFSLGW-TIAPMFG-WNRYVP-------EGN----MTACGTDYFN--RGLLSASYL
+VCYGIWVYFVPLFLIIYSYWFIIQAVAAHEKN----------------------------
+------------------------------------------------------------
+----------------------------------------------MREQAKK--MNVAS
+L------------------------RS-S-ENQNTSAECKLAKVALMTISLWFMAWTPYL
+VINFSGIF--NL-V--KISPLFTIWGSLFAKANAVYNPIVYGISHPKYRAALF-------
+--AKFP----SLAC-A---AEPSS-DAVST--TSGTTTVT-D------------------
+------------------------------------------------------------
+---------------NEK-SN-A---
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+M----------------------------------------------ANQLSYSSLGWP-
+---YQP-----------------------------NASV-----------VD--------
+------------------------------------TMPKEMLY----------------
+--MIHEHW------------YA---------FPPMNPLW--------------YSILGVA
+MIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-MPTMTSNC-FA-
+ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA-APLTHKKATLLL
+LFVWIWSGGW-TILPFFG-WSRYVP-------EGN----LTSCTVDYLT--KDWSSASYV
+VIYGLAVYFLPLITMIYCYFFIVHAVAEHEKQ----------------------------
+------------------------------------------------------------
+----------------------------------------------LREQAKK--MNVAS
+L------------------------RANA-DQQKQSAECRLAKVAMMTVGLWFMAWTPYL
+IISWAGVF--SSGT--RLTPLATIWGSVFAKANSCYNPIVYGISHPRYKAALY-------
+--QRFP----SLACGS---GESGS-DVKSE--ASATTTME-E------------------
+------------------------------------------------------------
+---------------KPKIPE-A---
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+M-----------------------------------------------------------
+---VESTTLV------------------NQTWWY-NPTV-----------D---------
+------------------------------------------------------------
+---IHPHW------------AK---------FDPIPDAV--------------YYSVGIF
+IGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGFPLKTISA-FM-
+KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASKKMSHRRAFLMI
+IFVWMWSIVW-SVGPVFN-WGAYVP-------EGI----LTSCSFDYLS--TDPSTRSFI
+LCMYFCGFMLPIIIIAFCYFNIVMSVSNHEKE----------------------------
+------------------------------------------------------------
+----------------------------------------------MAAMAKR--LNAKE
+L------------------------RK---AQAGASAEMKLAKISMVIITQFMLSWSPYA
+IIALLAQF-GPA-E--WVTPYAAELPVLFAKASAIHNPIVYSVSHPKFREAIQ-------
+--TTFPWLLTCCQFDE---KECED-ANDAE--EEVVASER---GGESRD-AAQMKEMMAM
+MQKMQAQQAAYQPPPPPQGY--PPQGYPPQGAYPPPQGYPPQGYPPQGYPPQGYPPQGAP
+PQVEAPQGAPPQGVDNQA-YQ-A---
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+M-----------------------------------------------------------
+---GRDLR-D------------------NETWWY-NPSI-----------V---------
+------------------------------------------------------------
+---VHPHW------------RE---------FDQVPDAV--------------YYSLGIF
+IGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGFPLMTISC-FL-
+KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASKKMSHRRAFIMI
+IFVWLWSVLW-AIGPIFG-WGAYTL-------EGV----LCNCSFDYIS--RDSTTRSNI
+LCMFILGFFGPILIIFFCYFNIVMSVSNHEKE----------------------------
+------------------------------------------------------------
+----------------------------------------------MAAMAKR--LNAKE
+L------------------------RK---AQAGANAEMRLAKISIVIVSQFLLSWSPYA
+VVALLAQF-GPL-E--WVTPYAAQLPVMFAKASAIHNPMIYSVSHPKFREAIS-------
+--QTFPWVLTCCQFDD---KETED-DKDAE--TEIPAGES-SDAAPSAD-AAQMKEMMAM
+MQKMQQQQAAY----PPQGYAPPPQGYPPQGY--PPQGYPPQGYPPQGYPP---PPQGAP
+PQ-GAPPAAPPQGVDNQA-YQ-A---
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDLY-----------------------------------------------
+-----------------GHLRSFL--LPEVGR---GLPD--------------------L
+SPDGGADPVAGSWAPHLLS---EVTA----------------------------------
+--SPAPTW-----------------------DAPPDNAS--GCGEQINYGRVEKVVIGSI
+LTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIG-
+GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMI
+LSVWLLSASI-TLPPLFG-WAQNVN--DDK---------VCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAAR---------------------------------
+-----------------KSAAKHKFPGFPRVEPDSVI----------------------A
+LNGIVK----------------------LQKEVEECAN--------LSRLLKH-------
+-------------------------ER-K-NISIFKREQKAATTLGIIVGAFTVCWLPFF
+LLSTARPFICGT-SCSCIPLWVERTFLWLGYANSLINPFIYAFFNRDLRTTYR-SLL---
+----------QCQYRN-INRKLSA-AGMHE--ALKLAERP-E--------RPEF-----V
+LQNADY--------CRKKGHD---------------------------------------
+----------------------S---
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+M-----------------------------------------------------------
+------------------------------------------------------------
+--------------PHLLSGFLEVTA----------------------------------
+--SPAPTW-----------------------DAPPDNVS--GCGEQINYGRVEKVVIGSI
+LTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIG-
+GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMI
+LSVWLLSASI-TLPPLFG-WAQNVN--DDK---------VCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAAR---------------------------------
+-----------------KSAAKHKFPGFPRVQPESVI----------------------S
+LNGVVK----------------------LQKEVEECAN--------LSRLLKH-------
+-------------------------ER-K-NISIFKREQKAATTLGIIVGAFTVCWLPFF
+LLSTARPFICGT-SCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRPTSR-SLL---
+----------QCQYRN-INRKLSA-AGMHE--ALKLAERP-E--------RSEF-----V
+LQNSDH--------CGKKGHD---------------------------------------
+----------------------T---
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+M-----------------------------------------------------------
+------------------------------------------------------------
+--------------PHLLSGFLEVTA----------------------------------
+--SPAPTW-----------------------DAPPDNVS--GCGEQINYGRVEKVVIGSI
+LTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIG-
+GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMI
+LSVWLLSASI-TLPPLFG-WAQNVN--DDK---------VCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAAR---------------------------------
+-----------------KSAAKHKFPGFPRVQPESVI----------------------S
+LNGVVK----------------------LQKEVEECAN--------LSRLLKH-------
+-------------------------ER-K-NISIFKREQKAATTLGIIVGAFTVCWLPFF
+LLSTARPFICGT-SCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRTTYR-SLL---
+----------QCQYRN-INRKLSA-AGMHE--ALKLAERP-E--------RSEF-----V
+LQNSDH--------CGKKGHD---------------------------------------
+----------------------T---
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+M-DVLSPGQ---------------------------------------------------
+-----------------GNNTTSPPAPFETGG---NTTG--------------------I
+-------------------------S----------------------------------
+--DVTVSY---------------------------------------------QVITSLL
+LGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQ-VL-
+NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALI
+SLTWLIGFLI-SIPPMLG-WRTPEDRSDPD---------ACTISKDH----------GYT
+IYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK----------------------------
+-----------TVKKVEKTGADTRHGASPAPQPKKSVNGESGSRNWRLGVESKAGGAL-C
+ANGAVRQGDDGAALEVIEVHRVGNSKEHLPLPSEAGPTPCAP-----ASFERK-------
+----NERNA----------------EA-K-RKMALARERKTVKTLGIIMGTFILCWLPFF
+IVALVLPF-CES-SC-HMPTLLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFK-KII---
+----------KCKFCR--------------------------------------------
+------------------------------------------------------------
+----------------------Q---
+>    33=p A35181 serotonin receptor class 1A - rat
+M-DVFSFGQ---------------------------------------------------
+-----------------GNNTTASQEPFGTGG---NVTS--------------------I
+-------------------------S----------------------------------
+--DVTFSY---------------------------------------------QVITSLL
+LGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQ-VL-
+NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALI
+SLTWLIGFLI-SIPPMLG-WRTPEDRSDPD---------ACTISKDH----------GYT
+IYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK----------------------------
+-----------TVRKVEKKGAGTSLGTSSAPPPKKSLNGQPGSGDWRRCAENRAVGTP-C
+TNGAVRQGDDEATLEVIEVHRVGNSKEHLPLPSESGSNSYAP-----ACLERK-------
+----NERNA----------------EA-K-RKMALARERKTVKTLGIIMGTFILCWLPFF
+IVALVLPF-CES-SC-HMPALLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFK-KII---
+----------KCKFCR--------------------------------------------
+------------------------------------------------------------
+----------------------R---
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+M-ANFTFGDLALD-----------------------------------------------
+-------------VARMGGLASTPSGLRSTGL---TTPG--------------------L
+SPTG------------------LVTS----------------------------------
+--DFNDSYGLTGQFINGSHSSRSRDNASAN-DTSATNMTDDRYWSLTVYSHEHLVLTSVI
+LGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSE-IS-
+KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMI
+MVVWIVALFI-SIPPLFG-WRDPNN--DPD------KTGTCIISQDK----------GYT
+IFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVV
+SDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKK----------------NRAKKLPEN
+ANGVNSNSSSSERLKQIQIE-----------TAEAFANGCAEEAS-IAMLERQ-CNNGKK
+ISSNDTPYS----------------RT-R-EKLELKRERKAARTLAIITGAFLICWLPFF
+IIALIGPF-VDP-E--GIPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSAFQ-KIL---
+----------FGKYRR--------------------------------------------
+------------------GH----------------------------------------
+----------------------R---
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+M-ANFTFGDLALD-----------------------------------------------
+-------------VARMGGLASTPSGLRSTGL---TTPG--------------------L
+SPTG------------------LVTS----------------------------------
+--DFNDSYGLTGQFINGSHSSRSRDNASAN-DTSATNMTDDRYWSLTVYSHEHLVLTSVI
+LGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSE-IS-
+KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMI
+MVVWIVALFI-SIPPLFG-WRDPNN--DPD------KTGTCIISQDK----------GYT
+IFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVV
+SDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKK----------------NRAKKLPEN
+ANGVNSNSSSSERLKQIQIE-----------TAEAFANGCAEEAS-IAMLERQ-CNNGKK
+ISSNDTPYS----------------RT-R-EKLELKRERKAARTLAIITGAFLICWLPFF
+IIALIGPF-VDP-E--GIPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSAFQ-KIL---
+----------FGKYRR--------------------------------------------
+------------------GH----------------------------------------
+----------------------R---
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+M-EGAE-GQEELDWEA--------------------------------------------
+---------LYLRLP-----------LQNCSW---NSTG--------------------W
+EPNW------------------NVTV----------------------------------
+--VPNTTW----------------WQASAPFDTPAALVR--------------AAAKAVV
+LGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-MPLGAVYE-VV-
+QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIHASTAKRVGMMI
+ACVWTVSFFV-CIAQLLG-WK------DPDWNQRVSEDLRCVVSQDV----------GYQ
+IFATASSFYVPVLIILILYWRIYQTARKRIRR----------------------------
+-----------------RRGATARGGVGPPPVP---------------------------
+AGGALVAGGGSGGIAAAVVAVIGRP---LPTISETTTTGFTNVSSNNTSPEKQSCANGLE
+A---DPPTTGYGAVAAAYYPSLVRRKP-K-EAADSKRERKAAKTLAIITGAFVACWLPFF
+VLAILVPT-CDC-E---VSPVLTSLSLWLGYFNSTLNPVIYTVFSPEFRHAFQ-RLL---
+----------CGRRVRRR------------------------------------------
+-----------------RAP----------------------------------------
+----------------------Q---
diff --git a/binaries/src/mafft/test/sample.fftns2 b/binaries/src/mafft/test/sample.fftns2
new file mode 100644 (file)
index 0000000..c3f02b2
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+------------------------------------------------------------
+---------MNGTE--GDNFYVP----FSNKTGLARSPYEYPQY-YLAEPWK--------
+-YSALAAYMFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-FTVT
+MYTSMN-GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN-FRFGN
+THAIMGVAFTWIMALAC-AAPPLVG-W-----SRYIPEGMQCSCGPDYYTLNPNFNNESY
+VVYMFVVHFLVPFVIIFFCYGRLLCTV---------------------------------
+------------------------------------------------------------
+------------------------------KEAAAAQQ----------ESASTQKA----
+-------------------------EKEVTRMVVLMVIGFLVCWVPYASVAFYIFTHQGS
+D---FGATFMTLPAFFAKSSALYNPVIYILMNKQFRNCMITTLCCGKN------PLGDDE
+--SGASTSKTEVSSVS-TSPVSPA------------------------------------
+---------------------------------------------------
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+------------------------------------------------------------
+---------MNGTE--GPNFYVP----FSNITGVVRSPFEQPQY-YLAEPWQ--------
+-FSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-FTTT
+LYTSLH-GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN-FRFGE
+NHAIMGVAFTWVMALAC-AAPPLVG-W-----SRYIPEGMQCSCGIDYYTLKPEVNNESF
+VIYMFVVHFTIPMIVIFFCYGQLVFTV---------------------------------
+------------------------------------------------------------
+------------------------------KEAAAQQQ----------ESATTQKA----
+-------------------------EKEVTRMVIIMVIFFLICWLPYASVAMYIFTHQGS
+N---FGPIFMTLPAFFAKTASIYNPIIYIMMNKQFRNCMLTSLCCGKN------PLGDDE
+--ASATASKTE------TSQVAPA------------------------------------
+---------------------------------------------------
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+------------------------------------------------------------
+---------MNGTE--GINFYVP----MSNKTGVVRSPFEYPQY-YLAEPWK--------
+-YRLVCCYIFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-FTVT
+FYTAWN-GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN-FRFSA
+THAMMGIAFTWVMAFSC-AAPPLFG-W-----SRYMPEGMQCSCGPDYYTHNPDYHNESY
+VLYMFVIHFIIPVVVIFFSYGRLICKV---------------------------------
+------------------------------------------------------------
+------------------------------REAAAQQQ----------ESATTQKA----
+-------------------------EKEVTRMVILMVLGFMLAWTPYAVVAFWIFTNKGA
+D---FTATLMAVPAFFSKSSSLYNPIIYVLMNKQFRNCMITTICCGKN------PFGDED
+VSSTVSQSKTEVSSVS-SSQVSPA------------------------------------
+---------------------------------------------------
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+------------------------------------------------------------
+---------MNGTE--GKNFYVP----MSNRTGLVRSPFEYPQY-YLAEPWQ--------
+-FKILALYLFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-FTVT
+FYTAIN-GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSS
+SHAFAGIAFTWVMALAC-AAPPLFG-W-----SRYIPEGMQCSCGPDYYTLNPDYNNESY
+VIYMFVCHFILPVAVIFFTYGRLVCTV---------------------------------
+------------------------------------------------------------
+------------------------------KAAAAQQQ----------DSASTQKA----
+-------------------------EREVTKMVILMVFGFLIAWTPYATVAAWIFFNKGA
+D---FSAKFMAIPAFFSKSSALYNPVIYVLLNKQFRNCMLTTIFCGKN------PLGDDE
+-SSTVSTSKTEVSS------VSPA------------------------------------
+---------------------------------------------------
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+------------------------------------------------------------
+---------MNGTE--GNNFYVP----LSNRTGLVRSPFEYPQY-YLAEPWQ--------
+-FKLLAVYMFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-FTVT
+FYTAIN-GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSS
+THASAGIAFTWVMAMAC-AAPPLVG-W-----SRYIPEGIQCSCGPDYYTLNPEYNNESY
+VLYMFICHFILPVTIIFFTYGRLVCTV---------------------------------
+------------------------------------------------------------
+------------------------------KAAAAQQQ----------DSASTQKA----
+-------------------------EREVTKMVILMVLGFLVAWTPYATVAAWIFFNKGA
+A---FSAQFMAIPAFFSKTSALYNPVIYVLLNKQFRSCMLTTLFCGKN------PLGDEE
+-SSTVSTSKTEVSS------VSPA------------------------------------
+---------------------------------------------------
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+------------------------------------------------------------
+---------MKQVPEFHEDFYIPIPLDINNLS--AYSPFLVPQD-HLGNQGI--------
+-FMAMSVFMFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-SPLS
+FYSFFN-RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN-FTFKT
+PHAIAGCILPWISALAA-SLPPLFG-W-----SRYIPEGLQCSCGPDWYTTNNKYNNESY
+VMFLFCFCFAVPFGTIVFCYGQLLITL---------------------------------
+------------------------------------------------------------
+------------------------------KLAAKAQA----------DSASTQKA----
+-------------------------EREVTKMVVVMVLGFLVCWAPYASFSLWIVSHRGE
+E---FDLRMATIPSCLSKASTVYNPVIYVLMNKQFRSCMM-KMVCGKN-------IEEDE
+--ASTSSQVTQVSS------VAPEK-----------------------------------
+---------------------------------------------------
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+------------------------------------------------------------
+---------MRKMS--EEEFYL-----FKNISSV--GPWDGPQY-HIAPVWA--------
+-FYLQAAFMGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-VFPV
+FVASCN-GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN-FRFSS
+KHALTVVLATWTIGIGV-SIPPFFG-W-----SRFIPEGLQCSCGPDWYTVGTKYRSESY
+TWFLFIFCFIVPLSLICFSYTQLLRAL---------------------------------
+------------------------------------------------------------
+------------------------------KAVAAQQQ----------ESATTQKA----
+-------------------------EREVSRMVVVMVGSFCVCYVPYAAFAMYMVNNRNH
+G---LDLRLVTIPSFFSKSACIYNPIIYCFMNKQFQACIM-KMVCGKA-------MTDES
+--DTCSSQKTEVSTVS-STQVGPN------------------------------------
+---------------------------------------------------
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+-----------------------------------------------DLAETVIA-STIS
+IVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDA
+KLAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSY
+MIVLMVTCCITPLSIIVLCYLQVWLAI---------------------------------
+------------------------------------------------------------
+------------------------------RAVAKQQK----------ESESTQKA----
+-------------------------EKEVTRMVVVMVLAFC-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+----------------------------------------------------------MA
+QQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNS-TRGPFEGPNY-HIAPRWV--------
+-YHLTSVWMIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STIS
+VVNQVY-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN-VRFDA
+KLAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSY
+MIVLMVTCCITPLSIIVLCYLQVWLAI---------------------------------
+------------------------------------------------------------
+------------------------------RAVAKQQK----------ESESTQKA----
+-------------------------EKEVTRMVVVMVLAFCFCWGPYAFFACFAAANPGY
+P---FHPLMAALPAFFAKSATIYNPVIYVFMNRQFRNCILQLF-----------GKKVDD
+GSELSSASKTEVSSV---SSVSPA------------------------------------
+---------------------------------------------------
+>    10== Z68193   1 human Red Opsin <>[]
+----------------------------------------------------------MA
+QQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNS-TRGPFEGPNY-HIAPRWV--------
+-YHLTSVWMIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STIS
+IVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDA
+KLAIVGIAFSWIWSAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSY
+MIVLMVTCCIIPLAIIMLCYLQVWLAI---------------------------------
+------------------------------------------------------------
+------------------------------RAVAKQQK----------ESESTQKA----
+-------------------------EKEVTRMVVVMIFAYCVCWGPYTFFACFAAANPGY
+A---FHPLMAALPAYFAKSATIYNPVIYVFMNRQFRNCILQLF-----------GKKVDD
+GSELSSASKTEVSSV---SSVSPA------------------------------------
+---------------------------------------------------
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+----------------------------------------------------------MT
+EAWNVAVFAARRSRDD-DDTTRGSVFTYTNTNN-TRGPFEGPNY-HIAPRWV--------
+-YNLVSFFMIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-STIS
+VFNQIF-GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN-IKFDS
+KLAIIGIVFSWVWAWGW-SAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSVELGCQSF
+MLTLMITCCFLPLFIIIVCYLQVWMAI---------------------------------
+------------------------------------------------------------
+------------------------------RAVAAQQK----------ESESTQKA----
+-------------------------EREVSRMVVVMIVAFCICWGPYASFVSFAAANPGY
+A---FHPLAAALPAYFAKSATIYNPVIYVFMNRQFRNCIMQLF-----------GKKVDD
+GSEASTTSRTEVSSVS-NSSVAPA------------------------------------
+---------------------------------------------------
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+-----------------------------------------------------------M
+AAWEAAFAARRRHEE--EDTTRDSVFTYTNSNN-TRGPFEGPNY-HIAPRWV--------
+-YNLTSVWMIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-STIS
+VINQIS-GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN-IKFDG
+KLAVAGILFSWLWSCAW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSDPGVQSY
+MVVLMVTCCFFPLAIIILCYLQVWLAI---------------------------------
+------------------------------------------------------------
+------------------------------RAVAAQQK----------ESESTQKA----
+-------------------------EKEVSRMVVVMIVAYCFCWGPYTFFACFAAANPGY
+A---FHPLAAALPAYFAKSATIYNPIIYVFMNRQFRNCILQLF-----------GKKVDD
+GSEVST-SRTEVSSVS-NSSVSPA------------------------------------
+---------------------------------------------------
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+------------------------------------------------------------
+---------------------MSSNSSQAPPNG-TPGPFDGPQWPYQAPQST--------
+-YVGVAVLMGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-SSVS
+LSNNIN-GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD-FQFQR
+RHAVSGCAFTWGWALLW-SAPPLLG-W-----SSYVPEGLRTSCGPNWYTGGSNN--NSY
+ILSLFVTCFVLPLSLILFSYTNLLLTL---------------------------------
+------------------------------------------------------------
+------------------------------RAAAAQQK----------EADTTQRA----
+-------------------------EREVTRMVIVMVMAFLLCWLPYSTFALVVATHKGI
+I---IQPVLASLPSYFSKTATVYNPIIYVFMNKQFQSCLLEMLCCGYQ------PQRTGK
+ASPGTPGPHADVTAAGLRNKVMPAHPV---------------------------------
+---------------------------------------------------
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+------------------------------------------------------MESGNV
+SSSLFGNVSTALRPEARLSA---E-----TRLLGWNVPPEELR--HIPEHWLTYPEPPES
+MNYLLGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--TPIF
+IYNSFH-QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--KMTH
+GKAIAMIIFIYMYATPW-VVACYTETW-----GRFVPEGYLTSCTFDYLT--DNFDTRLF
+VACIFFFSFVCPTTMITYYYSQIVGHVFSH------------------------------
+------------------------------------------------------------
+-----------------------------EKALRDQAKKMNVESLRSNVDKNKETA----
+-------------------------EIRIAKAAITICFLFFCSWTPYGVMSLIGAFGDKT
+L---LTPGATMIPACACKMVACIDPFVYAISHPRYRMELQKRCPWLAL---------NEK
+APESSAVASTSTTQEPQQTTAA--------------------------------------
+---------------------------------------------------
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+------------------------------------------------------MEYHNV
+SSVL-GNVSSVLRPDARLSA---E-----SRLLGWNVPPDELR--HIPEHWLIYPEPPES
+MNYLLGTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--TPIF
+IYNSFH-QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--KMTH
+GKAIAMIIFIYLYATPW-VVACYTESW-----GRFVPEGYLTSCTFDYLT--DNFDTRLF
+VACIFFFSFVCPTTMITYYYSQIVGHVFSH------------------------------
+------------------------------------------------------------
+-----------------------------EKALRDQAKKMNVDSLRSNVDKSKEAA----
+-------------------------EIRIAKAAITICFLFFASWTPYGVMSLIGAFGDKT
+L---LTPGATMIPACTCKMVACIDPFVYAISHPRYRMELQKRCPWLAI---------SEK
+APESRAAISTSTTQEQQQTTAA--------------------------------------
+---------------------------------------------------
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+------------------------------------------------------ME----
+--PLCNASEPPLRPEAR-SSGNGD-----LQFLGWNVPPDQIQ--YIPEHWLTQLEPPAS
+MHYMLGVFYIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF
+--NSFH-RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTF
+TKAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFDTRLF
+VGTIFFFSFVCPTLMILYYYSQIVGHVFSH------------------------------
+------------------------------------------------------------
+-----------------------------EKALREQAKKMNVESLRSNVDKSKETA----
+-------------------------EIRIAKAAITICFLFFVSWTPYGVMSLIGAFGDKS
+L---LTQGATMIPACTCKLVACIDPFVYAISHPRYRLELQKRCPWLGV---------NEK
+SGEISSAQSTTTQEQ-QQTTAA--------------------------------------
+---------------------------------------------------
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+------------------------------------------------------MD----
+--ALCNASEPPLRPEARMSSGSDE-----LQFLGWNVPPDQIQ--YIPEHWLTQLEPPAS
+MHYMLGVFYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF
+IYNSFH-RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTF
+TKAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFDTRLF
+VGTIFLFSFVVPTLMILYYYSQIVGHVFNH------------------------------
+------------------------------------------------------------
+-----------------------------EKALREQAKKMNVESLRSNVDKSKETA----
+-------------------------EIRIAKAAITICFLFFVSWTPYGVMSLIGAFGDKS
+L---LTPGATMIPACTCKLVACIEPFVYAISHPRYRMELQKRCPWLGV---------NEK
+SGEASSAQSTTTQEQTQQTSAA--------------------------------------
+---------------------------------------------------
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+------------------------------------------------------------
+---MTNATGPQMAYYGAASMDFGYPE---GVSIVDFVRPEIKP--YVHQHWYNYPPVNPM
+WHYLLGVIYLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-VPFF
+TYNCFSGGVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG-PKLTT
+GKAVVFALISWVIAIGC-ALPPFFG-W-----GNYILEGILDSCSYDYLT--QDFNTFSY
+NIFIFVFDYFLPAAIIVFSYVFIVKAIFAH------------------------------
+------------------------------------------------------------
+-----------------------------EAAMRAQAKKMNVSTLRS-NEADAQRA----
+-------------------------EIRIAKTALVNVSLWFICWTPYALISLKGVMGDTS
+G---ITPLVSTLPALLAKSCSCYNPFVYAISHPKYRLAITQHLPWFCV------HETETK
+SNDDSQSNSTVAQDKA--------------------------------------------
+---------------------------------------------------
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+------------------------------------------------------------
+---MANVTGPQMAFYGSGAATFGYPE---GMTVADFVPDRVKH--MVLDHWYNYPPVNPM
+WHYLLGVVYLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-FPPF
+CYNCFSGGRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG-PKLTQ
+GKATFMCGLAWVISVGW-SLPPFFG-W-----GSYTLEGILDSCSYDYFT--RDMNTITY
+NICIFIFDFFLPASVIVFSYVFIVKAIFAH------------------------------
+------------------------------------------------------------
+-----------------------------EAAMRAQAKKMNVTNLRS-NEAETQRA----
+-------------------------EIRIAKTALVNVSLWFICWTPYAAITIQGLLGNAE
+G---ITPLLTTLPALLAKSCSCYNPFVYAISHPKFRLAITQHLPWFCV------HEKDPN
+DVEENQSSNTQTQEKS--------------------------------------------
+---------------------------------------------------
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+---------------------------------------------------------MES
+FAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH--LISPYWNQFPAMDPI
+WAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMM
+GINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTI
+PLALGKM---------------------------YVPEGNLTSCGIDYLE--RDWNPRSY
+LIFYSIFVYYIPLFLICYSYWFIIAAVSAH------------------------------
+------------------------------------------------------------
+-----------------------------EKAMREQAKKMNVKSLRS-SEDAEKSA----
+-------------------------EGKLAKVALVTITLWFMAWTPYLVINCMGLFKF-E
+G---LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDG
+K-SSDAQSQATASEAESKA-----------------------------------------
+---------------------------------------------------
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+---------------------------------------------------------MES
+FAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH--LISPYWNQFPAMDPI
+WAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMM
+GINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTI
+PLALGKIAYIWFMSSIW-CLAPAFG-W-----SRYVPEGNLTSCGIDYLE--RDWNPRSY
+LIFYSIFVYYIPLFLICYSYWFIIAAVSAH------------------------------
+------------------------------------------------------------
+-----------------------------EKAMREQAKKMNVKSLRS-SEDAEKSA----
+-------------------------EGKLAKVALVTITLWFMAWTPYLVINCMGLFKF-E
+G---LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDG
+K-SSDAQSQATASEAESKA-----------------------------------------
+---------------------------------------------------
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+---------------------------------------------------------MDS
+FAAVATQLGPQFA-----APS--------NGSVVDKVTPDMAH--LISPYWDQFPAMDPI
+WAKILTAYMIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMM
+GINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTI
+PLALGKIAYIWFMSTIWCCLAPVFG-W-----SRYVPEGNLTSCGIDYLE--RDWNPRSY
+LIFYSIFVYYIPLFLICYSYWFIIAAVSAH------------------------------
+------------------------------------------------------------
+-----------------------------EKAMREQAKKMNVKSLRS-SEDADKSA----
+-------------------------EGKLAKVALVTISLWFMAWTPYLVINCMGLFKF-E
+G---LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDG
+K-SSEAQSQATTSEAESKA-----------------------------------------
+---------------------------------------------------
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+----------------------------------------------------MERSHLPE
+TPFDLAHSGPRFQ-----AQSSG------NGSVLDNVLPDMAH--LVNPYWSRFAPMDPM
+MSKILGLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVM
+IINFYY-ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTI
+KTSIMKILFIWMMAVFW-TVMPLIG-W-----SAYVPEGNLTACSIDYMT--RMWNPRSY
+LITYSLFVYYTPLFLICYSYWFIIAAVAAH------------------------------
+------------------------------------------------------------
+-----------------------------EKAMREQAKKMNVKSLRS-SEDCDKSA----
+-------------------------EGKLAKVALTTISLWFMAWTPYLVICYFGLFKI-D
+G---LTPLTTIWGATFAKTSAVYNPIVYGISHPKYRIVLKEKCPMCVF------GNTDEP
+KPDAPASDTETTSEADSKA-----------------------------------------
+---------------------------------------------------
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+----------------------------------------------------MERSLLPE
+PPLAMALLGPRFE-----AQTGG------NRSVLDNVLPDMAP--LVNPHWSRFAPMDPT
+MSKILGLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVM
+IINFYY-ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTI
+KTSIMKIAFIWMMAVFW-TIMPLIG-W-----SSYVPEGNLTACSIDYMT--RQWNPRSY
+LITYSLFVYYTPLFMICYSYWFIIATVAAH------------------------------
+------------------------------------------------------------
+-----------------------------EKAMRDQAKKMNVKSLRS-SEDCDKSA----
+-------------------------ENKLAKVALTTISLWFMAWTPYLIICYFGLFKI-D
+G---LTPLTTIWGATFAKTSAVYNPIVYGISHPNDRLVLKEKCPMCVC------GTTDEP
+KPDAPPSDTETTSEAESKD-----------------------------------------
+---------------------------------------------------
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+------------------------------------------------------------
+---MIAVSGPSYE-----AFSYGGQARFNNQTVVDKVPPDMLH--LIDANWYQYPPLNPM
+WHGILGFVIGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-SPPM
+VINCYY-ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG-KPLSI
+NGALIRIIAIWLFSLGW-TIAPMFG-W-----NRYVPEGNMTACGTDYFN--RGLLSASY
+LVCYGIWVYFVPLFLIIYSYWFIIQAVAAH------------------------------
+------------------------------------------------------------
+-----------------------------EKNMREQAKKMNVASLRS-SENQNTSA----
+-------------------------ECKLAKVALMTISLWFMAWTPYLVINFSGIFNL-V
+K---ISPLFTIWGSLFAKANAVYNPIVYGISHPKYRAALFAKFPSLAC-------AAEPS
+SDAVSTTSGTTTVTDNEKSNA---------------------------------------
+---------------------------------------------------
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+------------------------------------------------------------
+-----MANQLSYS-----SLGWPYQP---NASVVDTMPKEMLY--MIHEHWYAFPPMNPL
+WYSILGVAMIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-MPTM
+TSNCFA-ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA-APLTH
+KKATLLLLFVWIWSGGW-TILPFFG-W-----SRYVPEGNLTSCTVDYLT--KDWSSASY
+VVIYGLAVYFLPLITMIYCYFFIVHAVAEH------------------------------
+------------------------------------------------------------
+-----------------------------EKQLREQAKKMNVASLRANADQQKQSA----
+-------------------------ECRLAKVAMMTVGLWFMAWTPYLIISWAGVFSSGT
+R---LTPLATIWGSVFAKANSCYNPIVYGISHPRYKAALYQRFPSLAC------GSGESG
+SDVKSEASATTTMEEKPKIPEA--------------------------------------
+---------------------------------------------------
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+------------------------------------------------------------
+----------MVESTTLVNQTWWY-----NPTVD------------IHPHWAKFDPIPDA
+VYYSVGIFIGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGFPLK
+TISAFM-KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASKKMSH
+RRAFLMIIFVWMWSIVW-SVGPVFN-W-----GAYVPEGILTSCSFDYLS--TDPSTRSF
+ILCMYFCGFMLPIIIIAFCYFNIVMSVSNH------------------------------
+------------------------------------------------------------
+-----------------------------EKEMAAMAKRLNAKELR--KAQAGASA----
+-------------------------EMKLAKISMVIITQFMLSWSPYAIIALLAQFGPAE
+W---VTPYAAELPVLFAKASAIHNPIVYSVSHPKFREAIQTTFPWLLTCCQFDEKECEDA
+NDAEEEVVASER--GGESRDAAQMKEMMAMMQKMQAQQAAYQPPPPPQGY--PPQGYPPQ
+GAYPPPQGYPPQGYPPQGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQAYQA
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+------------------------------------------------------------
+-----------MGRDLRDNETWWY-----NPSIV------------VHPHWREFDQVPDA
+VYYSLGIFIGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGFPLM
+TISCFL-KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASKKMSH
+RRAFIMIIFVWLWSVLW-AIGPIFG-W-----GAYTLEGVLCNCSFDYIS--RDSTTRSN
+ILCMFILGFFGPILIIFFCYFNIVMSVSNH------------------------------
+------------------------------------------------------------
+-----------------------------EKEMAAMAKRLNAKELR--KAQAGANA----
+-------------------------EMRLAKISIVIVSQFLLSWSPYAVVALLAQFGPLE
+W---VTPYAAQLPVMFAKASAIHNPMIYSVSHPKFREAISQTFPWVLTCCQFDDKETEDD
+KDAETEIPAGESSDAAPSADAAQMKEMMAMMQKMQQQQAAY----PPQGYAPPPQGYPPQ
+GY--PPQGYPPQGYPPQGYPP---PPQGAPPQ-GAPPAAPPQGVDNQAYQA
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+---------MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDGGADPVAGSWAPHLLS-
+--EVTASPAPTW------------DAPPDNASGCGEQIN-----------------YGRV
+EKVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-MPFV
+SVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNG
+KCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GY
+TIYSTAVAFYIPMSVMLFMYYQIYKAAR--------------------------------
+------------------KSAAKHKFPGFPRVEPDSVIAL--------------------
+-----------------------------NGIVKLQKEVEECANLSRLL-----------
+-------------KHERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGT
+SCSCIPLWVERTFLWLGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMH
+EALKLAERPERPEFVLQNADYCRKKGHDS-------------------------------
+---------------------------------------------------
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+-----------------------------------------------------MPHLLSG
+FLEVTASPAPTW------------DAPPDNVSGCGEQIN-----------------YGRV
+EKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFV
+SVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNG
+KCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GY
+TIYSTAVAFYIPMSVMLFMYYQIYKAAR--------------------------------
+------------------KSAAKHKFPGFPRVQPESVISL--------------------
+-----------------------------NGVVKLQKEVEECANLSRLL-----------
+-------------KHERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGT
+SCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRPTSRSLLQCQYRNINRKLSAAGMH
+EALKLAERPERSEFVLQNSDHCGKKGHDT-------------------------------
+---------------------------------------------------
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+-----------------------------------------------------MPHLLSG
+FLEVTASPAPTW------------DAPPDNVSGCGEQIN-----------------YGRV
+EKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFV
+SVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNG
+KCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GY
+TIYSTAVAFYIPMSVMLFMYYQIYKAAR--------------------------------
+------------------KSAAKHKFPGFPRVQPESVISL--------------------
+-----------------------------NGVVKLQKEVEECANLSRLL-----------
+-------------KHERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGT
+SCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMH
+EALKLAERPERSEFVLQNSDHCGKKGHDT-------------------------------
+---------------------------------------------------
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+----------MDVLSPGQ-------GN----------------------NTTSPPAPFET
+GGNTTGISDVTV-----------------------------------------------S
+YQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMA
+ALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTP
+RRAAALISLTWLIGFLI-SIPPMLG-WRTPEDRSDPDA---CTISKDH----------GY
+TIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK---------------------------
+------------TVKKVEKTGADTRHGASPAPQPKKS-----------VNGESGSR----
+-----NWRLGVESKAGGALCANGAVRQGDDGAALEVIEVHRVGNSKEHLPLPSEAG--PT
+PCAPASFERKNERNAEAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CES
+SCH-MPTLLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFCRQ----------
+------------------------------------------------------------
+---------------------------------------------------
+>    33=p A35181 serotonin receptor class 1A - rat
+----------MDVFSFGQ-------GN----------------------NTTASQEPFGT
+GGNVTSISDVTF-----------------------------------------------S
+YQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMA
+ALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTP
+RRAAALISLTWLIGFLI-SIPPMLG-WRTPEDRSDPDA---CTISKDH----------GY
+TIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK---------------------------
+------------TVRKVEKKGAGTSLGTSSAPPPKKS-----------LNGQPGSG----
+-----DWRRCAENRAVGTPCTNGAVRQGDDEATLEVIEVHRVGNSKEHLPLPSESG--SN
+SYAPACLERKNERNAEAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CES
+SCH-MPALLGAIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFCRR----------
+------------------------------------------------------------
+---------------------------------------------------
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLR----------------------STGLTTPGLSP
+TGLVTSDFNDSYGLTGQFINGSHSSRSRDNASANDTSATN-----MTDDRYWSLTVYSHE
+HLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLS
+VVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSA
+RRILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK----------GY
+TIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSV
+VSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSS-----
+-----SERLKQIQIETAEAFANGCA----EEASIAMLERQ-CNNGKKISSNDTPYS----
+---------RTREKLELK------RERKAARTLAIITGAFLICWLPFFIIALIGPF-VDP
+E-G-IPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSAFQKILFGKYRRGHR--------
+------------------------------------------------------------
+---------------------------------------------------
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLR----------------------STGLTTPGLSP
+TGLVTSDFNDSYGLTGQFINGSHSSRSRDNASANDTSATN-----MTDDRYWSLTVYSHE
+HLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLS
+VVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSA
+RRILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK----------GY
+TIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSV
+VSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSS-----
+-----SERLKQIQIETAEAFANGCA----EEASIAMLERQ-CNNGKKISSNDTPYS----
+---------RTREKLELK------RERKAARTLAIITGAFLICWLPFFIIALIGPF-VDP
+E-G-IPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSAFQKILFGKYRRGHR--------
+------------------------------------------------------------
+---------------------------------------------------
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+-MEGAEGQEELDWEAL--YLRLP--LQ----------------------NCSWNSTGWEP
+NWNVTVVPNTTW---------WQASAPFDTPAALVRAAAK--------------------
+-----AVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-MPLG
+AVYEVV-QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIHASTA
+KRVGMMIACVWTVSFFV-CIAQLLG-WKDPDWNQRVSEDLRCVVSQDV----------GY
+QIFATASSFYVPVLIILILYWRIYQTARKRIR----------------------------
+-----------------RRRGATARGGVGPPP---------VPAGGALVAGGGSGGIAAA
+VVAVIGRPLPTISETTTTGFTNVSS----NNTS---PEKQSCANGLEADPPTTGYGAVAA
+AYYPSLVRRKPKEAADSK------RERKAAKTLAIITGAFVACWLPFFVLAILVPT-CDC
+E---VSPVLTSLSLWLGYFNSTLNPVIYTVFSPEFRHAFQRLLCGRRVRRRRAPQ-----
+------------------------------------------------------------
+---------------------------------------------------
diff --git a/binaries/src/mafft/test/sample.fftnsi b/binaries/src/mafft/test/sample.fftnsi
new file mode 100644 (file)
index 0000000..17e2714
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+------------------------------------------------------------
+---------MNGTE--GDNFYVP----FSNKTGLARSPYEYPQYYLAEPWK---------
+YSALAAYMFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-FTVTM
+YTSMN-GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN-FRFGNT
+HAIMGVAFTWIMALAC-AAPPLVG-W-----SRYIPEGMQCSCGPDYYTLNPNFNNESYV
+VYMFVVHFLVPFVIIFFCYGRLLCTV----------------------------------
+------------------------------------------------------------
+-------------------KEAAAAQQ-----------------------------ESAS
+TQKA----------EKEVTRMVVLMVIGFLVCWVPYASVAFYIFT---HQGSD-FGATFM
+TLPAFFAKSSALYNPVIYILMNKQFRNCMITTLCCGKN------PLGDDE--SGASTSKT
+EVSSVS-TSPVSPA----------------------------------------------
+-----------------------------------------
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+------------------------------------------------------------
+---------MNGTE--GPNFYVP----FSNITGVVRSPFEQPQYYLAEPWQ---------
+FSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-FTTTL
+YTSLH-GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN-FRFGEN
+HAIMGVAFTWVMALAC-AAPPLVG-W-----SRYIPEGMQCSCGIDYYTLKPEVNNESFV
+IYMFVVHFTIPMIVIFFCYGQLVFTV----------------------------------
+------------------------------------------------------------
+-------------------KEAAAQQQ-----------------------------ESAT
+TQKA----------EKEVTRMVIIMVIFFLICWLPYASVAMYIFT---HQGSN-FGPIFM
+TLPAFFAKTASIYNPIIYIMMNKQFRNCMLTSLCCGKN------PLGDDE--ASATASKT
+ETSQ------VAPA----------------------------------------------
+-----------------------------------------
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+------------------------------------------------------------
+---------MNGTE--GINFYVP----MSNKTGVVRSPFEYPQYYLAEPWK---------
+YRLVCCYIFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-FTVTF
+YTAWN-GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN-FRFSAT
+HAMMGIAFTWVMAFSC-AAPPLFG-W-----SRYMPEGMQCSCGPDYYTHNPDYHNESYV
+LYMFVIHFIIPVVVIFFSYGRLICKV----------------------------------
+------------------------------------------------------------
+-------------------REAAAQQQ-----------------------------ESAT
+TQKA----------EKEVTRMVILMVLGFMLAWTPYAVVAFWIFT---NKGAD-FTATLM
+AVPAFFSKSSSLYNPIIYVLMNKQFRNCMITTICCGKN------PFGDEDVSSTVSQSKT
+EVSSVS-SSQVSPA----------------------------------------------
+-----------------------------------------
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+------------------------------------------------------------
+---------MNGTE--GKNFYVP----MSNRTGLVRSPFEYPQYYLAEPWQ---------
+FKILALYLFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-FTVTF
+YTAIN-GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSSS
+HAFAGIAFTWVMALAC-AAPPLFG-W-----SRYIPEGMQCSCGPDYYTLNPDYNNESYV
+IYMFVCHFILPVAVIFFTYGRLVCTV----------------------------------
+------------------------------------------------------------
+-------------------KAAAAQQQ-----------------------------DSAS
+TQKA----------EREVTKMVILMVFGFLIAWTPYATVAAWIFF---NKGAD-FSAKFM
+AIPAFFSKSSALYNPVIYVLLNKQFRNCMLTTIFCGKN------PLGDDE-SSTVSTSKT
+EVSS------VSPA----------------------------------------------
+-----------------------------------------
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+------------------------------------------------------------
+---------MNGTE--GNNFYVP----LSNRTGLVRSPFEYPQYYLAEPWQ---------
+FKLLAVYMFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-FTVTF
+YTAIN-GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-FKFSST
+HASAGIAFTWVMAMAC-AAPPLVG-W-----SRYIPEGIQCSCGPDYYTLNPEYNNESYV
+LYMFICHFILPVTIIFFTYGRLVCTV----------------------------------
+------------------------------------------------------------
+-------------------KAAAAQQQ-----------------------------DSAS
+TQKA----------EREVTKMVILMVLGFLVAWTPYATVAAWIFF---NKGAA-FSAQFM
+AIPAFFSKTSALYNPVIYVLLNKQFRSCMLTTLFCGKN------PLGDEE-SSTVSTSKT
+EVSS------VSPA----------------------------------------------
+-----------------------------------------
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+------------------------------------------------------------
+---------MKQVPEFHEDFYIPIPLDINNLS--AYSPFLVPQDHLGNQGI---------
+FMAMSVFMFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-SPLSF
+YSFFN-RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN-FTFKTP
+HAIAGCILPWISALAA-SLPPLFG-W-----SRYIPEGLQCSCGPDWYTTNNKYNNESYV
+MFLFCFCFAVPFGTIVFCYGQLLITL----------------------------------
+------------------------------------------------------------
+-------------------KLAAKAQA-----------------------------DSAS
+TQKA----------EREVTKMVVVMVLGFLVCWAPYASFSLWIVS---HRGEE-FDLRMA
+TIPSCLSKASTVYNPVIYVLMNKQFRSCMM-KMVCGKN-------IEEDE--ASTSSQVT
+QVSS------VAPEK---------------------------------------------
+-----------------------------------------
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+------------------------------------------------------------
+---------MRKMS--EEEFYL-----FKNISSV--GPWDGPQYHIAPVWA---------
+FYLQAAFMGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-VFPVF
+VASCN-GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN-FRFSSK
+HALTVVLATWTIGIGV-SIPPFFG-W-----SRFIPEGLQCSCGPDWYTVGTKYRSESYT
+WFLFIFCFIVPLSLICFSYTQLLRAL----------------------------------
+------------------------------------------------------------
+-------------------KAVAAQQQ-----------------------------ESAT
+TQKA----------EREVSRMVVVMVGSFCVCYVPYAAFAMYMVN---NRNHG-LDLRLV
+TIPSFFSKSACIYNPIIYCFMNKQFQACIM-KMVCGKA-------MTDES--DTCSSQKT
+EVSTVS-STQVGPN----------------------------------------------
+-----------------------------------------
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+----------------------------------------------DLAETVIA-STISI
+VNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDAK
+LAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCITPLSIIVLCYLQVWLAI----------------------------------
+------------------------------------------------------------
+-------------------RAVAKQQK-----------------------------ESES
+TQKA----------EKEVTRMVVVMVLAFC------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----------------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+----------------------------------------------------------MA
+QQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNS-TRGPFEGPNYHIAPRWV---------
+YHLTSVWMIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISV
+VNQVY-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN-VRFDAK
+LAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCITPLSIIVLCYLQVWLAI----------------------------------
+------------------------------------------------------------
+-------------------RAVAKQQK-----------------------------ESES
+TQKA----------EKEVTRMVVVMVLAFCFCWGPYAFFACFAAA---NPGYP-FHPLMA
+ALPAFFAKSATIYNPVIYVFMNRQFRNCILQLF-----------GKKVDDGSELSSASKT
+EVSSV---SSVSPA----------------------------------------------
+-----------------------------------------
+>    10== Z68193   1 human Red Opsin <>[]
+----------------------------------------------------------MA
+QQWSLQRLAGRHPQDSYEDSTQSSIFTYTNSNS-TRGPFEGPNYHIAPRWV---------
+YHLTSVWMIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISI
+VNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-VRFDAK
+LAIVGIAFSWIWSAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPGVQSYM
+IVLMVTCCIIPLAIIMLCYLQVWLAI----------------------------------
+------------------------------------------------------------
+-------------------RAVAKQQK-----------------------------ESES
+TQKA----------EKEVTRMVVVMIFAYCVCWGPYTFFACFAAA---NPGYA-FHPLMA
+ALPAYFAKSATIYNPVIYVFMNRQFRNCILQLF-----------GKKVDDGSELSSASKT
+EVSSV---SSVSPA----------------------------------------------
+-----------------------------------------
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+----------------------------------------------------------MT
+EAWNVAVFAARRSRD-DDDTTRGSVFTYTNTNN-TRGPFEGPNYHIAPRWV---------
+YNLVSFFMIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-STISV
+FNQIF-GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN-IKFDSK
+LAIIGIVFSWVWAWGW-SAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSVELGCQSFM
+LTLMITCCFLPLFIIIVCYLQVWMAI----------------------------------
+------------------------------------------------------------
+-------------------RAVAAQQK-----------------------------ESES
+TQKA----------EREVSRMVVVMIVAFCICWGPYASFVSFAAA---NPGYA-FHPLAA
+ALPAYFAKSATIYNPVIYVFMNRQFRNCIMQLF-----------GKKVDDGSEASTTSRT
+EVSSVS-NSSVAPA----------------------------------------------
+-----------------------------------------
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+-----------------------------------------------------------M
+AAWEAAFAARRRHE--EEDTTRDSVFTYTNSNN-TRGPFEGPNYHIAPRWV---------
+YNLTSVWMIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-STISV
+INQIS-GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN-IKFDGK
+LAVAGILFSWLWSCAW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSDPGVQSYM
+VVLMVTCCFFPLAIIILCYLQVWLAI----------------------------------
+------------------------------------------------------------
+-------------------RAVAAQQK-----------------------------ESES
+TQKA----------EKEVSRMVVVMIVAYCFCWGPYTFFACFAAA---NPGYA-FHPLAA
+ALPAYFAKSATIYNPIIYVFMNRQFRNCILQLF-----------GKKVDDGSEVST-SRT
+EVSSVS-NSSVSPA----------------------------------------------
+-----------------------------------------
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+------------------------------------------------------------
+----------------------------MSSNSSQAPPNGTPGPFDGPQWP--YQAPQST
+YVGVAVLMGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-SSVSL
+SNNIN-GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD-FQFQRR
+HAVSGCAFTWGWALLW-SAPPLLG-W-----SSYVPEGLRTSCGPNWYTGGS--NNNSYI
+LSLFVTCFVLPLSLILFSYTNLLLTL----------------------------------
+------------------------------------------------------------
+-------------------RAAAAQQK-----------------------------EADT
+TQRA----------EREVTRMVIVMVMAFLLCWLPYSTFALVVAT---HKGII-IQPVLA
+SLPSYFSKTATVYNPIIYVFMNKQFQSCLLEMLCCGYQ------PQRTGKASPGTPGPHA
+DVTAAGLRNKVMPAHPV-------------------------------------------
+-----------------------------------------
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+------------------------------------------------------MESGNV
+SSSLFGNVSTALRPEARLSAE--------TRLLGWNVPPEELR-HIPEHWLTYPEPPESM
+NYLLGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--TPIFI
+YNSFH-QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--KMTHG
+KAIAMIIFIYMYATPW-VVACYTETW-----GRFVPEGYLTSCTFDYLT--DNFDTRLFV
+ACIFFFSFVCPTTMITYYYSQIVGHVFSH-------------------------------
+------------------------------------------------------------
+------------------EKALRDQAKKMNVESLRS-------------------NVDKN
+KETA----------EIRIAKAAITICFLFFCSWTPYGVMSLIGAF---GDKTL-LTPGAT
+MIPACACKMVACIDPFVYAISHPRYRMELQKRCPWLAL---------NEKAPESSAVAST
+STTQEPQQTTAA------------------------------------------------
+-----------------------------------------
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+------------------------------------------------------MEYHNV
+S-SVLGNVSSVLRPDARLSAE--------SRLLGWNVPPDELR-HIPEHWLIYPEPPESM
+NYLLGTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--TPIFI
+YNSFH-QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--KMTHG
+KAIAMIIFIYLYATPW-VVACYTESW-----GRFVPEGYLTSCTFDYLT--DNFDTRLFV
+ACIFFFSFVCPTTMITYYYSQIVGHVFSH-------------------------------
+------------------------------------------------------------
+------------------EKALRDQAKKMNVDSLRS-------------------NVDKS
+KEAA----------EIRIAKAAITICFLFFASWTPYGVMSLIGAF---GDKTL-LTPGAT
+MIPACTCKMVACIDPFVYAISHPRYRMELQKRCPWLAI---------SEKAPESRAAIST
+STTQEQQQTTAA------------------------------------------------
+-----------------------------------------
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+------------------------------------------------------ME----
+--PLCNASEPPLRPEARSSGNGD------LQFLGWNVPPDQIQ-YIPEHWLTQLEPPASM
+HYMLGVFYIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF-
+-NSFH-RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFT
+KAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFDTRLFV
+GTIFFFSFVCPTLMILYYYSQIVGHVFSH-------------------------------
+------------------------------------------------------------
+------------------EKALREQAKKMNVESLRS-------------------NVDKS
+KETA----------EIRIAKAAITICFLFFVSWTPYGVMSLIGAF---GDKSL-LTQGAT
+MIPACTCKLVACIDPFVYAISHPRYRLELQKRCPWLGV---------NEKSGEISSAQST
+TTQEQ-QQTTAA------------------------------------------------
+-----------------------------------------
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+------------------------------------------------------MD----
+--ALCNASEPPLRPEARMSSGSDE-----LQFLGWNVPPDQIQ-YIPEHWLTQLEPPASM
+HYMLGVFYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIFI
+YNSFH-RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFT
+KAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFDTRLFV
+GTIFLFSFVVPTLMILYYYSQIVGHVFNH-------------------------------
+------------------------------------------------------------
+------------------EKALREQAKKMNVESLRS-------------------NVDKS
+KETA----------EIRIAKAAITICFLFFVSWTPYGVMSLIGAF---GDKSL-LTPGAT
+MIPACTCKLVACIEPFVYAISHPRYRMELQKRCPWLGV---------NEKSGEASSAQST
+TTQEQTQQTSAA------------------------------------------------
+-----------------------------------------
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+------------------------------------------------------------
+---MTNATGPQMAYYGAASMDFGYPE---GVSIVDFVRPEIKP-YVHQHWYNYPPVNPMW
+HYLLGVIYLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-VPFFT
+YNCFSGGVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG-PKLTTG
+KAVVFALISWVIAIGC-ALPPFFG-W-----GNYILEGILDSCSYDYLT--QDFNTFSYN
+IFIFVFDYFLPAAIIVFSYVFIVKAIFAH-------------------------------
+------------------------------------------------------------
+------------------EAAMRAQAKKMNVSTLRS--------------------NEAD
+AQRA----------EIRIAKTALVNVSLWFICWTPYALISLKGVM---GDTSG-ITPLVS
+TLPALLAKSCSCYNPFVYAISHPKYRLAITQHLPWFCV------HETETKSNDDSQSNST
+VAQDKA------------------------------------------------------
+-----------------------------------------
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+------------------------------------------------------------
+---MANVTGPQMAFYGSGAATFGYPE---GMTVADFVPDRVKH-MVLDHWYNYPPVNPMW
+HYLLGVVYLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-FPPFC
+YNCFSGGRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG-PKLTQG
+KATFMCGLAWVISVGW-SLPPFFG-W-----GSYTLEGILDSCSYDYFT--RDMNTITYN
+ICIFIFDFFLPASVIVFSYVFIVKAIFAH-------------------------------
+------------------------------------------------------------
+------------------EAAMRAQAKKMNVTNLRS--------------------NEAE
+TQRA----------EIRIAKTALVNVSLWFICWTPYAAITIQGLL---GNAEG-ITPLLT
+TLPALLAKSCSCYNPFVYAISHPKFRLAITQHLPWFCV------HEKDPNDVEENQSSNT
+QTQEKS------------------------------------------------------
+-----------------------------------------
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+---------------------------------------------------------MES
+FAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH-LISPYWNQFPAMDPIW
+AKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMG
+INLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIP
+LALGKM---------------------------YVPEGNLTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAH-------------------------------
+------------------------------------------------------------
+------------------EKAMREQAKKMNVKSLRS--------------------SEDA
+EKSA----------EGKLAKVALVTITLWFMAWTPYLVINCMGLF---KF-EG-LTPLNT
+IWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDGK-SSDAQSQA
+TASEAESKA---------------------------------------------------
+-----------------------------------------
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+---------------------------------------------------------MES
+FAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH-LISPYWNQFPAMDPIW
+AKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMG
+INLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIP
+LALGKIAYIWFMSSIW-CLAPAFG-W-----SRYVPEGNLTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAH-------------------------------
+------------------------------------------------------------
+------------------EKAMREQAKKMNVKSLRS--------------------SEDA
+EKSA----------EGKLAKVALVTITLWFMAWTPYLVINCMGLF---KF-EG-LTPLNT
+IWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDGK-SSDAQSQA
+TASEAESKA---------------------------------------------------
+-----------------------------------------
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+---------------------------------------------------------MDS
+FAAVATQLGPQFA-----APS--------NGSVVDKVTPDMAH-LISPYWDQFPAMDPIW
+AKILTAYMIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMG
+INLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-RPMTIP
+LALGKIAYIWFMSTIWCCLAPVFG-W-----SRYVPEGNLTSCGIDYLE--RDWNPRSYL
+IFYSIFVYYIPLFLICYSYWFIIAAVSAH-------------------------------
+------------------------------------------------------------
+------------------EKAMREQAKKMNVKSLRS--------------------SEDA
+DKSA----------EGKLAKVALVTISLWFMAWTPYLVINCMGLF---KF-EG-LTPLNT
+IWGACFAKSAACYNPIVYGISHPKYRLALKEKCPCCVF------GKVDDGK-SSEAQSQA
+TTSEAESKA---------------------------------------------------
+-----------------------------------------
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+----------------------------------------------------MERSHLPE
+TPFDLAHSGPRFQ-----AQSSG------NGSVLDNVLPDMAH-LVNPYWSRFAPMDPMM
+SKILGLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMI
+INFYY-ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTIK
+TSIMKILFIWMMAVFW-TVMPLIG-W-----SAYVPEGNLTACSIDYMT--RMWNPRSYL
+ITYSLFVYYTPLFLICYSYWFIIAAVAAH-------------------------------
+------------------------------------------------------------
+------------------EKAMREQAKKMNVKSLRS--------------------SEDC
+DKSA----------EGKLAKVALTTISLWFMAWTPYLVICYFGLF---KI-DG-LTPLTT
+IWGATFAKTSAVYNPIVYGISHPKYRIVLKEKCPMCVF------GNTDEPKPDAPASDTE
+TTSEADSKA---------------------------------------------------
+-----------------------------------------
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+----------------------------------------------------MERSLLPE
+PPLAMALLGPRFE-----AQTGG------NRSVLDNVLPDMAP-LVNPHWSRFAPMDPTM
+SKILGLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMI
+INFYY-ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING-TPMTIK
+TSIMKIAFIWMMAVFW-TIMPLIG-W-----SSYVPEGNLTACSIDYMT--RQWNPRSYL
+ITYSLFVYYTPLFMICYSYWFIIATVAAH-------------------------------
+------------------------------------------------------------
+------------------EKAMRDQAKKMNVKSLRS--------------------SEDC
+DKSA----------ENKLAKVALTTISLWFMAWTPYLIICYFGLF---KI-DG-LTPLTT
+IWGATFAKTSAVYNPIVYGISHPNDRLVLKEKCPMCVC------GTTDEPKPDAPPSDTE
+TTSEAESKD---------------------------------------------------
+-----------------------------------------
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+------------------------------------------------------------
+---MIAVSGPSYE-----AFSYGGQARFNNQTVVDKVPPDMLH-LIDANWYQYPPLNPMW
+HGILGFVIGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-SPPMV
+INCYY-ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG-KPLSIN
+GALIRIIAIWLFSLGW-TIAPMFG-W-----NRYVPEGNMTACGTDYFN--RGLLSASYL
+VCYGIWVYFVPLFLIIYSYWFIIQAVAAH-------------------------------
+------------------------------------------------------------
+------------------EKNMREQAKKMNVASLRS--------------------SENQ
+NTSA----------ECKLAKVALMTISLWFMAWTPYLVINFSGIF---NL-VK-ISPLFT
+IWGSLFAKANAVYNPIVYGISHPKYRAALFAKFPSLAC-------AAEPSSDAVSTTSGT
+TTVTDNEKSNA-------------------------------------------------
+-----------------------------------------
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+------------------------------------------------------------
+-----MANQLSYS-----SLGWPYQP---NASVVDTMPKEMLY-MIHEHWYAFPPMNPLW
+YSILGVAMIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-MPTMT
+SNCFA-ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA-APLTHK
+KATLLLLFVWIWSGGW-TILPFFG-W-----SRYVPEGNLTSCTVDYLT--KDWSSASYV
+VIYGLAVYFLPLITMIYCYFFIVHAVAEH-------------------------------
+------------------------------------------------------------
+------------------EKQLREQAKKMNVASLRA-------------------NADQQ
+KQSA----------ECRLAKVAMMTVGLWFMAWTPYLIISWAGVF---SSGTR-LTPLAT
+IWGSVFAKANSCYNPIVYGISHPRYKAALYQRFPSLAC------GSGESGSDVKSEASAT
+TTMEEKPKIPEA------------------------------------------------
+-----------------------------------------
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+------------------------------------------------------------
+----------MVESTTLVNQTWWY-----NPTVD-----------IHPHWAKFDPIPDAV
+YYSVGIFIGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGFPLKT
+ISAFM-KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASKKMSHR
+RAFLMIIFVWMWSIVW-SVGPVFN-W-----GAYVPEGILTSCSFDYLS--TDPSTRSFI
+LCMYFCGFMLPIIIIAFCYFNIVMSVSNH-------------------------------
+------------------------------------------------------------
+------------------EKEMAAMAKRLNAKELR---------------------KAQA
+GASA----------EMKLAKISMVIITQFMLSWSPYAIIALLAQF---GPAEW-VTPYAA
+ELPVLFAKASAIHNPIVYSVSHPKFREAIQTTFPWLLTCCQFDEKECEDANDAEEEVVAS
+ER--GGESRDAAQMKEMMAMMQKMQAQQAAYQPPPPPQGY--PPQGYPPQGAYPPPQGYP
+PQGYPPQGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQAYQA
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+------------------------------------------------------------
+-----------MGRDLRDNETWWY-----NPSIV-----------VHPHWREFDQVPDAV
+YYSLGIFIGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGFPLMT
+ISCFL-KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASKKMSHR
+RAFIMIIFVWLWSVLW-AIGPIFG-W-----GAYTLEGVLCNCSFDYIS--RDSTTRSNI
+LCMFILGFFGPILIIFFCYFNIVMSVSNH-------------------------------
+------------------------------------------------------------
+------------------EKEMAAMAKRLNAKELR---------------------KAQA
+GANA----------EMRLAKISIVIVSQFLLSWSPYAVVALLAQF---GPLEW-VTPYAA
+QLPVMFAKASAIHNPMIYSVSHPKFREAISQTFPWVLTCCQFDDKETEDDKDAETEIPAG
+ESSDAAPSADAAQMKEMMAMMQKMQQQQAAY----PPQGYAPPPQGYPPQGY--PPQGYP
+PQGYPPQGYPP---PPQGAPPQ-GAPPAAPPQGVDNQAYQA
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+---------MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDGGADPVAGSWAPHLLS-
+--EVTASPAPTWDAPPDNASGCGEQINYGRVE----------------------------
+KVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVS
+VTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGK
+CMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRVEPDSVIAL-----------
+------------------------------------------------------------
+------------------NGIVKLQKEVEECANLSR-------------------LLKHE
+RKNI-----SIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSC-IPLWVE
+RTFLWLGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMHEALKLAERPE
+RPEFVLQNADYCRKKGHDS-----------------------------------------
+-----------------------------------------
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+-----------------------------------------------------MPHLLSG
+FLEVTASPAPTWDAPPDNVSGCGEQINYGRVE----------------------------
+KVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVS
+VTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGK
+CMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRVQPESVISL-----------
+------------------------------------------------------------
+------------------NGVVKLQKEVEECANLSR-------------------LLKHE
+RKNI-----SIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSC-IPLWVE
+RTCLWLGYANSLINPFIYAFFNRDLRPTSRSLLQCQYRNINRKLSAAGMHEALKLAERPE
+RSEFVLQNSDHCGKKGHDT-----------------------------------------
+-----------------------------------------
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+-----------------------------------------------------MPHLLSG
+FLEVTASPAPTWDAPPDNVSGCGEQINYGRVE----------------------------
+KVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVS
+VTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGK
+CMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF----------GYT
+IYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKFPGFPRVQPESVISL-----------
+------------------------------------------------------------
+------------------NGVVKLQKEVEECANLSR-------------------LLKHE
+RKNI-----SIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSC-IPLWVE
+RTCLWLGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMHEALKLAERPE
+RSEFVLQNSDHCGKKGHDT-----------------------------------------
+-----------------------------------------
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+MDVLSPGQGN---------------------------------------NTTSPPAPFET
+GGNTTGISDVTVSY----------------------------------------------
+QVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAA
+LYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPR
+RAAALISLTWLIGFLI-SIPPMLG-WRTP---EDRSDPDACTISKDH----------GYT
+IYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK----------------------------
+-----------TVKKVEKTGADTRHGASPAPQPKKS----------VNGESGSRNWRLGV
+ESKAGGALCANGAVRQGDDGAALEVIEVHRVGNSKEHLPLPSEAGPTPCA--PASFERKN
+ERNAEAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF---CESSCHMPTLLG
+AIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFCRQ--------------------
+------------------------------------------------------------
+-----------------------------------------
+>    33=p A35181 serotonin receptor class 1A - rat
+MDVFSFGQGN---------------------------------------NTTASQEPFGT
+GGNVTSISDVTFSY----------------------------------------------
+QVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAA
+LYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPR
+RAAALISLTWLIGFLI-SIPPMLG-WRTP---EDRSDPDACTISKDH----------GYT
+IYSTFGAFYIPLLLMLVLYGRIFRAARFRIRK----------------------------
+-----------TVRKVEKKGAGTSLGTSSAPPPKKS----------LNGQPGSGDWRRCA
+ENRAVGTPCTNGAVRQGDDEATLEVIEVHRVGNSKEHLPLPSESGSNSYA--PACLERKN
+ERNAEAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF---CESSCHMPALLG
+AIINWLGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKFCRR--------------------
+------------------------------------------------------------
+-----------------------------------------
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLR----------------------STGLTTPGLSP
+TGLVTSDFNDSYGLTGQFINGSHSSRSRDNASANDTSATN----MTDDRYWSLTVYSHEH
+LVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSV
+VSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSAR
+RILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK----------GYT
+IFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVV
+SDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQ
+IQIETAEAFANGCA----EEASIAMLERQ-CNNGKK-------------------ISSND
+TPYSRTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF---VDPEG-IPPFAR
+SFVLWLGYFNSLLNPIIYTIFSPEFRSAFQKILFGKYRRGHR------------------
+------------------------------------------------------------
+-----------------------------------------
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLR----------------------STGLTTPGLSP
+TGLVTSDFNDSYGLTGQFINGSHSSRSRDNASANDTSATN----MTDDRYWSLTVYSHEH
+LVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSV
+VSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSAR
+RILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK----------GYT
+IFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVV
+SDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQ
+IQIETAEAFANGCA----EEASIAMLERQ-CNNGKK-------------------ISSND
+TPYSRTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF---VDPEG-IPPFAR
+SFVLWLGYFNSLLNPIIYTIFSPEFRSAFQKILFGKYRRGHR------------------
+------------------------------------------------------------
+-----------------------------------------
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+---------------------------MEGAEGQEELDWEALYLRLPLQNCSWNSTGWEP
+NWNVTVVPNTTWWQ--------------------ASAPFDTPAALVR-------------
+AAAKAVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-MPLGA
+VYEVV-QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIHASTAK
+RVGMMIACVWTVSFFV-CIAQLLG-WKDPDWNQRVSEDLRCVVSQDV----------GYQ
+IFATASSFYVPVLIILILYWRIYQTARKRIRR----------------------------
+-----------------RRGATARGGVGPPPVPAGGALVA------GGGSGGIAAAVVAV
+IGRPLPTISETTTTGFTNVSSNNTSPEKQSCANGLEADPPTTGYGAVAAAYYPSLVRRKP
+KEAA------DSKRERKAAKTLAIITGAFVACWLPFFVLAILVPT---CDCE--VSPVLT
+SLSLWLGYFNSTLNPVIYTVFSPEFRHAFQRLLCGRRVRRRRAPQ---------------
+------------------------------------------------------------
+-----------------------------------------
diff --git a/binaries/src/mafft/test/sample.gins1 b/binaries/src/mafft/test/sample.gins1
new file mode 100644 (file)
index 0000000..3901982
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+--------------------MNGTE--GDNFYVPFSNKTG--LARSP-------------
+-------------------------------YEYPQY-YLAEPW----------------
+------KYSALAAYMFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLF
+G-FTVTMYTSMN-GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN
+F-RFGNTHAIMGVAFTWIMALAC-AAPPLVG-WS-----RYIPEGMQCSCGPDYYTLNPN
+FNNESYVVYMFVVHFLVPFVIIFFCYGRLLCTVKEAAAAQQESA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEKEVTRMVVLMVIGFLVCWVPYASVAFYIFT--HQGSD-FGATFMTLPAF
+FAKSSALYNPVIYILMNKQFRNCMITTL-----CCGKNPLGDDE-SG-ASTSKTEVSSVS
+T-----------------------------------------------------------
+-----------------------------------SPV-------SP-A
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+--------------------MNGTE--GPNFYVPFSNITG--VVRSP-------------
+-------------------------------FEQPQY-YLAEPW----------------
+------QFSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFG
+G-FTTTLYTSLH-GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN
+F-RFGENHAIMGVAFTWVMALAC-AAPPLVG-WS-----RYIPEGMQCSCGIDYYTLKPE
+VNNESFVIYMFVVHFTIPMIVIFFCYGQLVFTVKEAAAQQQESA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----TTQKAEKEVTRMVIIMVIFFLICWLPYASVAMYIFT--HQGSN-FGPIFMTLPAF
+FAKTASIYNPIIYIMMNKQFRNCMLTSL-----CCGKNPLGDDE-AS-ATASKTE-----
+T-----------------------------------------------------------
+-----------------------------------SQV-------AP-A
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+--------------------MNGTE--GINFYVPMSNKTG--VVRSP-------------
+-------------------------------FEYPQY-YLAEPW----------------
+------KYRLVCCYIFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACF
+G-FTVTFYTAWN-GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN
+F-RFSATHAMMGIAFTWVMAFSC-AAPPLFG-WS-----RYMPEGMQCSCGPDYYTHNPD
+YHNESYVLYMFVIHFIIPVVVIFFSYGRLICKVREAAAQQQESA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----TTQKAEKEVTRMVILMVLGFMLAWTPYAVVAFWIFT--NKGAD-FTATLMAVPAF
+FSKSSSLYNPIIYVLMNKQFRNCMITTI-----CCGKNPFGDEDVSSTVSQSKTEVSSVS
+S-----------------------------------------------------------
+-----------------------------------SQV-------SP-A
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+--------------------MNGTE--GKNFYVPMSNRTG--LVRSP-------------
+-------------------------------FEYPQY-YLAEPW----------------
+------QFKILALYLFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCF
+G-FTVTFYTAIN-GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS
+F-KFSSSHAFAGIAFTWVMALAC-AAPPLFG-WS-----RYIPEGMQCSCGPDYYTLNPD
+YNNESYVIYMFVCHFILPVAVIFFTYGRLVCTVKAAAAQQQDSA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEREVTKMVILMVFGFLIAWTPYATVAAWIFF--NKGAD-FSAKFMAIPAF
+FSKSSALYNPVIYVLLNKQFRNCMLTTI-----FCGKNPLGDDE-SSTVSTSKTEVSS--
+------------------------------------------------------------
+-------------------------------------V-------SP-A
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+--------------------MNGTE--GNNFYVPLSNRTG--LVRSP-------------
+-------------------------------FEYPQY-YLAEPW----------------
+------QFKLLAVYMFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCF
+G-FTVTFYTAIN-GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS
+F-KFSSTHASAGIAFTWVMAMAC-AAPPLVG-WS-----RYIPEGIQCSCGPDYYTLNPE
+YNNESYVLYMFICHFILPVTIIFFTYGRLVCTVKAAAAQQQDSA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEREVTKMVILMVLGFLVAWTPYATVAAWIFF--NKGAA-FSAQFMAIPAF
+FSKTSALYNPVIYVLLNKQFRSCMLTTL-----FCGKNPLGDEE-SSTVSTSKTEVSS--
+------------------------------------------------------------
+-------------------------------------V-------SP-A
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+--------------------MKQVPEFHEDFYIPIPLDINNLSAYSP-------------
+-------------------------------FLVPQD-HLGNQG----------------
+------IFMAMSVFMFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIF
+G-SPLSFYSFFN-RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN
+F-TFKTPHAIAGCILPWISALAA-SLPPLFG-WS-----RYIPEGLQCSCGPDWYTTNNK
+YNNESYVMFLFCFCFAVPFGTIVFCYGQLLITLKLAAKAQADSA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEREVTKMVVVMVLGFLVCWAPYASFSLWIVS--HRGEE-FDLRMATIPSC
+LSKASTVYNPVIYVLMNKQFRSCMM-KM-----VCGKN-IEEDE-AS-TSSQVTQVSS--
+------------------------------------------------------------
+-------------------------------------V-------APEK
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+--------------------MRKMS--EEEFYL-FKNISS----VGP-------------
+-------------------------------WDGPQY-HIAPVW----------------
+------AFYLQAAFMGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIF
+S-VFPVFVASCN-GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN
+F-RFSSKHALTVVLATWTIGIGV-SIPPFFG-WS-----RFIPEGLQCSCGPDWYTVGTK
+YRSESYTWFLFIFCFIVPLSLICFSYTQLLRALKAVAAQQQESA----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----TTQKAEREVSRMVVVMVGSFCVCYVPYAAFAMYMVN--NRNHG-LDLRLVTIPSF
+FSKSACIYNPIIYCFMNKQFQACIM-KM-----VCGKA-MTDES-DT-CSSQKTEVSTVS
+S-----------------------------------------------------------
+-----------------------------------TQV-------GP-N
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+-----------------------------------------------------DLAETVI
+A-STISIVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN
+V-RFDAKLAIVGIAFSWIWAAVW-TAPPIFG-WS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCITPLSIIVLCYLQVWLAIRAVAKQQKESE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEKEVTRMVVVMVLAFC----------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------------------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+MAQQWS-LQRLAGRHPQDSYEDSTQ--SSIFTYTNSNST-----RGP-------------
+-------------------------------FEGPNY-HIAPRW----------------
+------VYHLTSVWMIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVI
+A-STISVVNQVY-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN
+V-RFDAKLAIVGIAFSWIWAAVW-TAPPIFG-WS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCITPLSIIVLCYLQVWLAIRAVAKQQKESE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEKEVTRMVVVMVLAFCFCWGPYAFFACFAAA--NPGYP-FHPLMAALPAF
+FAKSATIYNPVIYVFMNRQFRNCILQLF-------GKKVDDGSE-LS--SASKTEVSSV-
+------------------------------------------------------------
+-----------------------------------SSV-------SP-A
+>    10== Z68193   1 human Red Opsin <>[]
+MAQQWS-LQRLAGRHPQDSYEDSTQ--SSIFTYTNSNST-----RGP-------------
+-------------------------------FEGPNY-HIAPRW----------------
+------VYHLTSVWMIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVI
+A-STISIVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN
+V-RFDAKLAIVGIAFSWIWSAVW-TAPPIFG-WS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCIIPLAIIMLCYLQVWLAIRAVAKQQKESE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEKEVTRMVVVMIFAYCVCWGPYTFFACFAAA--NPGYA-FHPLMAALPAY
+FAKSATIYNPVIYVFMNRQFRNCILQLF-------GKKVDDGSE-LS--SASKTEVSSV-
+------------------------------------------------------------
+-----------------------------------SSV-------SP-A
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+MTEAWNVAVFAARRSRDD--DDTTR--GSVFTYTNTNNT-----RGP-------------
+-------------------------------FEGPNY-HIAPRW----------------
+------VYNLVSFFMIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLV
+A-STISVFNQIF-GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN
+I-KFDSKLAIIGIVFSWVWAWGW-SAPPIFG-WS-----RYWPHGLKTSCGPDVFSGSVE
+LGCQSFMLTLMITCCFLPLFIIIVCYLQVWMAIRAVAAQQKESE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEREVSRMVVVMIVAFCICWGPYASFVSFAAA--NPGYA-FHPLAAALPAY
+FAKSATIYNPVIYVFMNRQFRNCIMQLF-------GKKVDDGSE-AS--TTSRTEVSSVS
+N-----------------------------------------------------------
+-----------------------------------SSV-------AP-A
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+MA-AWE-AAFAARRRHEE--EDTTR--DSVFTYTNSNNT-----RGP-------------
+-------------------------------FEGPNY-HIAPRW----------------
+------VYNLTSVWMIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVI
+A-STISVINQIS-GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN
+I-KFDGKLAVAGILFSWLWSCAW-TAPPIFG-WS-----RYWPHGLKTSCGPDVFSGSSD
+PGVQSYMVVLMVTCCFFPLAIIILCYLQVWLAIRAVAAQQKESE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----STQKAEKEVSRMVVVMIVAYCFCWGPYTFFACFAAA--NPGYA-FHPLAAALPAY
+FAKSATIYNPIIYVFMNRQFRNCILQLF-------GKKVDDGSE-VS--T-SRTEVSSVS
+N-----------------------------------------------------------
+-----------------------------------SSV-------SP-A
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+------------------------M--SSNSSQAPPNGT-----PGP-------------
+-------------------------------FDGPQWPYQAPQS----------------
+------TYVGVAVLMGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLC
+G-SSVSLSNNIN-GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD
+F-QFQRRHAVSGCAFTWGWALLW-SAPPLLG-WS-----SYVPEGLRTSCGPNWYTGGSN
+--NNSYILSLFVTCFVLPLSLILFSYTNLLLTLRAAAAQQKEAD----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----TTQRAEREVTRMVIVMVMAFLLCWLPYSTFALVVAT--HKGII-IQPVLASLPSY
+FSKTATVYNPIIYVFMNKQFQSCLLEML-----CCGYQPQRTGK-AS--PGTPGPHADVT
+A-----------------------------------------------------------
+-----------------------------------AGLRNKVMPAHP-V
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+MESGNVSSSLFGNVSTALRPE----ARLSA---E---TRLLGWNVPP-------------
+-------------------------------EELR---HIPEHWLTYPE-----------
+--PPESMNYLLGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK
+--TPIFIYNSFH-QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG
+--KMTHGKAIAMIIFIYMYATPW-VVACYTETWG-----RFVPEGYLTSCTFDYLTDN--
+FDTRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKNKETAEIRIAKAAITICFLFFCSWTPYGVMSLIGAF--GDKTL-LTPGATMIPAC
+ACKMVACIDPFVYAISHPRYRMELQKRCPWL--ALNEKAPESSA----VASTST---TQE
+P-----------------------------------------------------------
+-----------------------------------QQT-------TA-A
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+MEYHNVSSVL-GNVSSVLRPD----ARLSA---E---SRLLGWNVPP-------------
+-------------------------------DELR---HIPEHWLIYPE-----------
+--PPESMNYLLGTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK
+--TPIFIYNSFH-QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG
+--KMTHGKAIAMIIFIYLYATPW-VVACYTESWG-----RFVPEGYLTSCTFDYLTDN--
+FDTRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKKMNVDSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKEAAEIRIAKAAITICFLFFASWTPYGVMSLIGAF--GDKTL-LTPGATMIPAC
+TCKMVACIDPFVYAISHPRYRMELQKRCPWL--AISEKAPESRA----AISTST---TQE
+Q-----------------------------------------------------------
+-----------------------------------QQT-------TA-A
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+ME------PLCNASEPPLRPE----AR-SSGNGD---LQFLGWNVPP-------------
+-------------------------------DQIQ---YIPEHWLTQLE-----------
+--PPASMHYMLGVFYIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK
+--APIF--NSFH-RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR
+--NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--
+FDTRLFVGTIFFFSFVCPTLMILYYYSQIVGHVFSHEKALREQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVMSLIGAF--GDKSL-LTQGATMIPAC
+TCKLVACIDPFVYAISHPRYRLELQKRCPWL--GVNEKSGEISS----AQSTTT---QEQ
+------------------------------------------------------------
+-----------------------------------QQT-------TA-A
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+MD------ALCNASEPPLRPE----ARMSSGSDE---LQFLGWNVPP-------------
+-------------------------------DQIQ---YIPEHWLTQLE-----------
+--PPASMHYMLGVFYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK
+--APIFIYNSFH-RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR
+--NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--
+FDTRLFVGTIFLFSFVVPTLMILYYYSQIVGHVFNHEKALREQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVMSLIGAF--GDKSL-LTPGATMIPAC
+TCKLVACIEPFVYAISHPRYRMELQKRCPWL--GVNEKSGEASS----AQSTTT---QEQ
+T-----------------------------------------------------------
+-----------------------------------QQT-------SA-A
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+MT-----------NATGPQMAYYGAASMDFGYPE---GVSIVDFVRP-------------
+-------------------------------EIKP---YVHQHWYNYPP-----------
+--VNPMWHYLLGVIYLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTT
+N-VPFFTYNCFSGGVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG
+P-KLTTGKAVVFALISWVIAIGC-ALPPFFG-WG-----NYILEGILDSCSYDYLTQD--
+FNTFSYNIFIFVFDYFLPAAIIVFSYVFIVKAIFAHEAAMRAQAKKMNVSTLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-NEADAQRAEIRIAKTALVNVSLWFICWTPYALISLKGVM--GDTSG-ITPLVSTLPAL
+LAKSCSCYNPFVYAISHPKYRLAITQHLPWF--CVHETETKSND----DSQSNS---TVA
+Q-----------------------------------------------------------
+---------------------------------------------DK-A
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+MA-----------NVTGPQMAFYGSGAATFGYPE---GMTVADFVPD-------------
+-------------------------------RVKH---MVLDHWYNYPP-----------
+--VNPMWHYLLGVVYLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTT
+N-FPPFCYNCFSGGRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG
+P-KLTQGKATFMCGLAWVISVGW-SLPPFFG-WG-----SYTLEGILDSCSYDYFTRD--
+MNTITYNICIFIFDFFLPASVIVFSYVFIVKAIFAHEAAMRAQAKKMNVTNLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-NEAETQRAEIRIAKTALVNVSLWFICWTPYAAITIQGLL--GNAEG-ITPLLTTLPAL
+LAKSCSCYNPFVYAISHPKFRLAITQHLPWF--CVHEKDPNDVE----ENQSSN---TQT
+Q-----------------------------------------------------------
+---------------------------------------------EK-S
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTP-------------
+-------------------------------DMAH---LISPYWNQFPA-----------
+--MDPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKM---------------------------YVPEGNLTSCGIDYLERD--
+WNPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----DAQSQA-TASEA
+E-----------------------------------------------------------
+---------------------------------------------SK-A
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTP-------------
+-------------------------------DMAH---LISPYWNQFPA-----------
+--MDPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKIAYIWFMSSIW-CLAPAFG-WS-----RYVPEGNLTSCGIDYLERD--
+WNPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----DAQSQA-TASEA
+E-----------------------------------------------------------
+---------------------------------------------SK-A
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+MD-----SFAAVATQLGPQFA-----APS--------NGSVVDKVTP-------------
+-------------------------------DMAH---LISPYWDQFPA-----------
+--MDPIWAKILTAYMIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKIAYIWFMSTIWCCLAPVFG-WS-----RYVPEGNLTSCGIDYLERD--
+WNPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDADKSAEGKLAKVALVTISLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----EAQSQA-TTSEA
+E-----------------------------------------------------------
+---------------------------------------------SK-A
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+MERSHLPETPFDLAHSGPRFQ-----AQSSG------NGSVLDNVLP-------------
+-------------------------------DMAH---LVNPYWSRFAP-----------
+--MDPMMSKILGLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMAS
+Q-SPVMIINFYY-ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING
+T-PMTIKTSIMKILFIWMMAVFW-TVMPLIG-WS-----AYVPEGNLTACSIDYMTRM--
+WNPRSYLITYSLFVYYTPLFLICYSYWFIIAAVAAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDCDKSAEGKLAKVALTTISLWFMAWTPYLVICYFGLF--KI-DG-LTPLTTIWGAT
+FAKTSAVYNPIVYGISHPKYRIVLKEKCPMC--VFGNTDEPKPD----APASDTETTSEA
+D-----------------------------------------------------------
+---------------------------------------------SK-A
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+MERSLLPEPPLAMALLGPRFE-----AQTGG------NRSVLDNVLP-------------
+-------------------------------DMAP---LVNPHWSRFAP-----------
+--MDPTMSKILGLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMAS
+Q-SPVMIINFYY-ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING
+T-PMTIKTSIMKIAFIWMMAVFW-TIMPLIG-WS-----SYVPEGNLTACSIDYMTRQ--
+WNPRSYLITYSLFVYYTPLFMICYSYWFIIATVAAHEKAMRDQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDCDKSAENKLAKVALTTISLWFMAWTPYLIICYFGLF--KI-DG-LTPLTTIWGAT
+FAKTSAVYNPIVYGISHPNDRLVLKEKCPMC--VCGTTDEPKPD----APPSDTETTSEA
+E-----------------------------------------------------------
+---------------------------------------------SK-D
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+MI-----------AVSGPSYE-----AFSYGGQARFNNQTVVDKVPP-------------
+-------------------------------DMLH---LIDANWYQYPP-----------
+--LNPMWHGILGFVIGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFC
+M-SPPMVINCYY-ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG
+K-PLSINGALIRIIAIWLFSLGW-TIAPMFG-WN-----RYVPEGNMTACGTDYFNRG--
+LLSASYLVCYGIWVYFVPLFLIIYSYWFIIQAVAAHEKNMREQAKKMNVASLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SENQNTSAECKLAKVALMTISLWFMAWTPYLVINFSGIF--NL-VK-ISPLFTIWGSL
+FAKANAVYNPIVYGISHPKYRAALFAKFPSL--AC-AAEPSSDA----VSTTSG-TTTVT
+D-----------------------------------------------------------
+----------------------------------NEK--------SN-A
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+M-------------ANQLSYS-----SLGWPYQP---NASVVDTMPK-------------
+-------------------------------EMLY---MIHEHWYAFPP-----------
+--MNPLWYSILGVAMIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAF
+M-MPTMTSNCFA-ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA
+A-PLTHKKATLLLLFVWIWSGGW-TILPFFG-WS-----RYVPEGNLTSCTVDYLTKD--
+WSSASYVVIYGLAVYFLPLITMIYCYFFIVHAVAEHEKQLREQAKKMNVASLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+ANADQQKQSAECRLAKVAMMTVGLWFMAWTPYLIISWAGVF--SSGTR-LTPLATIWGSV
+FAKANSCYNPIVYGISHPRYKAALYQRFPSL--ACGSGESGSDV----KSEASA-TTTME
+E-----------------------------------------------------------
+----------------------------------KPKI-------PE-A
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+MV-------------ESTTLV-----NQTWWY-----NPTV-------------------
+--------------------------------------DIHPHWAKFDP-----------
+--IPDAVYYSVGIFIGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAI
+NGFPLKTISAFM-KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAA
+SKKMSHRRAFLMIIFVWMWSIVW-SVGPVFN-WG-----AYVPEGILTSCSFDYLSTD--
+PSTRSFILCMYFCGFMLPIIIIAFCYFNIVMSVSNHEKEMAAMAKRLNAKELR-------
+------------------------------------------------------------
+------------------------------------------------------------
+K-AQ-AGASAEMKLAKISMVIITQFMLSWSPYAIIALLAQF--GPAEW-VTPYAAELPVL
+FAKASAIHNPIVYSVSHPKFREAIQTTFPWLLTCCQFDEKECED----ANDAEEEVVASE
+R--GGESRDAAQMKEMMAMMQKMQAQQAAYQP---PPPPQGYPPQGYPPQGAYPPPQGYP
+PQGYPPQGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQA-------YQ-A
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+MG-------------RDLR-D-----NETWWY-----NPSI-------------------
+--------------------------------------VVHPHWREFDQ-----------
+--VPDAVYYSLGIFIGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLV
+NGFPLMTISCFL-KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAA
+SKKMSHRRAFIMIIFVWLWSVLW-AIGPIFG-WG-----AYTLEGVLCNCSFDYISRD--
+STTRSNILCMFILGFFGPILIIFFCYFNIVMSVSNHEKEMAAMAKRLNAKELR-------
+------------------------------------------------------------
+------------------------------------------------------------
+K-AQ-AGANAEMRLAKISIVIVSQFLLSWSPYAVVALLAQF--GPLEW-VTPYAAQLPVM
+FAKASAIHNPMIYSVSHPKFREAISQTFPWVLTCCQFDDKETED----DKDAETEIPAGE
+SSDAAPSADAAQMKEMMAMMQKMQQQQAAYPPQGYAPPPQGYPPQGYPPQGY--PPQGYP
+PQGYPP---PPQGAPPQGAPP------AAPPQGVDNQA-------YQ-A
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDG-----------------GADPVAGS
+WAPHLLS------------------------EVTAS---PAPTW---DAPPDNASGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLFG-WA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVEPDSVIALNG------------------------------------------------
+----IVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTFLW
+LGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMHEALKLAERPERPEFV
+L-----------------------------------------------------------
+-----------------------------------QNADYCRKKGHD-S
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+------------------------------------------------------------
+-MPHLLSGFL---------------------EVTAS---PAPTW---DAPPDNVSGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLFG-WA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVQPESVISLNG------------------------------------------------
+----VVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLW
+LGYANSLINPFIYAFFNRDLRPTSRSLLQCQYRNINRKLSAAGMHEALKLAERPERSEFV
+L-----------------------------------------------------------
+-----------------------------------QNSDHCGKKGHD-T
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+------------------------------------------------------------
+-MPHLLSGFL---------------------EVTAS---PAPTW---DAPPDNVSGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLFG-WA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVQPESVISLNG------------------------------------------------
+----VVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLW
+LGYANSLINPFIYAFFNRDLRTTYRSLLQCQYRNINRKLSAAGMHEALKLAERPERSEFV
+L-----------------------------------------------------------
+-----------------------------------QNSDHCGKKGHD-T
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+MDVLSPG-----------------------------------------------------
+--------------------QGNNT------TSPPAPFETGGNTTGISD-----------
+--VTVSYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVL
+V-LPMAALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDY
+VNKRTPRRAAALISLTWLIGFLI-SIPPMLG-WRTPEDRSDPD---ACTISKDH------
+----GYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVKKVEKTGADTRHGASPAPQ
+PKK-----SVNG--ESGSRNWRLGVESKAGGALCANGAVRQGDDGAAL--EVIEVHRVGN
+SKEHLPLPSEAGPTPCAPAS------------------FERKNERNA-------------
+EAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CESSCH-MPTLLGAIINW
+LGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKF----------------------------
+------------------------------------------------------------
+-------------------------------------------CR---Q
+>    33=p A35181 serotonin receptor class 1A - rat
+MDVFSFG-----------------------------------------------------
+--------------------QGNNT------TASQEPFGTGGNVTSISD-----------
+--VTFSYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVL
+V-LPMAALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDY
+VNKRTPRRAAALISLTWLIGFLI-SIPPMLG-WRTPEDRSDPD---ACTISKDH------
+----GYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVRKVEKKGAGTSLGTSSAPP
+PKK-----SLNG--QPGSGDWRRCAENRAVGTPCTNGAVRQGDDEATL--EVIEVHRVGN
+SKEHLPLPSESGSNSYAPAC------------------LERKNERNA-------------
+EAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CESSCH-MPALLGAIINW
+LGYSNSLLNPVIYAYFNKDFQNAFKKIIKCKF----------------------------
+------------------------------------------------------------
+-------------------------------------------CR---R
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRD-----------NASANDT------SATNM---TDDRYWSLTV-----------
+--YSHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVL
+V-MPLSVVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDY
+IRRRSARRILLMIMVVWIVALFI-SIPPLFG-WRDPNN--DPDKTGTCIISQDK------
+----GYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASP
+KTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSS
+SSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYS-------------
+RTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF-VDPE-G-IPPFARSFVLW
+LGYFNSLLNPIIYTIFSPEFRSAFQKILFGKY----------------------------
+------------------------------------------------------------
+-------------------------------------------RRGH-R
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRD-----------NASANDT------SATNM---TDDRYWSLTV-----------
+--YSHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVL
+V-MPLSVVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDY
+IRRRSARRILLMIMVVWIVALFI-SIPPLFG-WRDPNN--DPDKTGTCIISQDK------
+----GYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASP
+KTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSS
+SSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYS-------------
+RTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF-VDPE-G-IPPFARSFVLW
+LGYFNSLLNPIIYTIFSPEFRSAFQKILFGKY----------------------------
+------------------------------------------------------------
+-------------------------------------------RRGH-R
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+M--------------------------------------------------------EGA
+EGQEELDWEALYLRLPLQNCSWNSTGWEPNWNVTVV---PNTTWWQASAPFDTP------
+--AALVRAAAKAVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACL
+V-MPLGAVYEVV-QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDY
+IHASTAKRVGMMIACVWTVSFFV-CIAQLLG-WKDPDWNQRVSEDLRCVVSQDV------
+----GYQIFATASSFYVPVLIILILYWRIYQTARKRIRR------RRGATARGGVGPPPV
+PAG---------------------------------GALVAGGGSGGIAAAVVAV-----
+IGRPLPTISETTTTGFTNVSSNNTSPE--KQSCANGLEADPPTTGYGAVAAAYYPSLVRR
+KPKEAADSKRERKAAKTLAIITGAFVACWLPFFVLAILVPT-CD--CE-VSPVLTSLSLW
+LGYFNSTLNPVIYTVFSPEFRHAFQRLLCGRR----------------------------
+------------------------------------------------------------
+----------------------------------------VRRRRAP-Q
diff --git a/binaries/src/mafft/test/sample.ginsi b/binaries/src/mafft/test/sample.ginsi
new file mode 100644 (file)
index 0000000..d632978
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+M-------------------NGTE--GDNFYVPFSNKTGLA--RSPYEYPQY-YL-----
+------------------------------------------------------------
+--AEPWKYSALAAYMFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLF
+G-FTVTMYTSMN-GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN
+F-RFGNTHAIMGVAFTWIMALAC-AAPPLV-GWS-----RYIPEGMQCSCGPDYYTLNPN
+FNNESYVVYMFVVHFLVPFVIIFFCYGRLLCTVKEAAAAQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESASTQKAEKEVTRMVVLMVIGFLVCWVPYASVAFYIFT--HQGSD-FGATFMTLPAF
+FAKSSALYNPVIYILMNKQFRNCMITTL-----CCGKNPLGDDE--SGASTSKTEVSSVS
+T-----------------------------------------------------------
+-----------------------------------SPVSPA
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+M-------------------NGTE--GPNFYVPFSNITGVV--RSPFEQPQY-YL-----
+------------------------------------------------------------
+--AEPWQFSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFG
+G-FTTTLYTSLH-GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN
+F-RFGENHAIMGVAFTWVMALAC-AAPPLV-GWS-----RYIPEGMQCSCGIDYYTLKPE
+VNNESFVIYMFVVHFTIPMIVIFFCYGQLVFTVKEAAAQQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESATTQKAEKEVTRMVIIMVIFFLICWLPYASVAMYIFT--HQGSN-FGPIFMTLPAF
+FAKTASIYNPIIYIMMNKQFRNCMLTSL-----CCGKNPLGDDE--ASATASKTET----
+------------------------------------------------------------
+-----------------------------------SQVAPA
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+M-------------------NGTE--GINFYVPMSNKTGVV--RSPFEYPQY-YL-----
+------------------------------------------------------------
+--AEPWKYRLVCCYIFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACF
+G-FTVTFYTAWN-GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN
+F-RFSATHAMMGIAFTWVMAFSC-AAPPLF-GWS-----RYMPEGMQCSCGPDYYTHNPD
+YHNESYVLYMFVIHFIIPVVVIFFSYGRLICKVREAAAQQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESATTQKAEKEVTRMVILMVLGFMLAWTPYAVVAFWIFT--NKGAD-FTATLMAVPAF
+FSKSSSLYNPIIYVLMNKQFRNCMITTI-----CCGKNPFGDEDVSSTVSQSKTEVSSVS
+S-----------------------------------------------------------
+-----------------------------------SQVSPA
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+M-------------------NGTE--GKNFYVPMSNRTGLV--RSPFEYPQY-YL-----
+------------------------------------------------------------
+--AEPWQFKILALYLFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCF
+G-FTVTFYTAIN-GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS
+F-KFSSSHAFAGIAFTWVMALAC-AAPPLF-GWS-----RYIPEGMQCSCGPDYYTLNPD
+YNNESYVIYMFVCHFILPVAVIFFTYGRLVCTVKAAAAQQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--DSASTQKAEREVTKMVILMVFGFLIAWTPYATVAAWIFF--NKGAD-FSAKFMAIPAF
+FSKSSALYNPVIYVLLNKQFRNCMLTTI-----FCGKNPLGDDE-SSTVSTSKTEVSS--
+------------------------------------------------------------
+-------------------------------------VSPA
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+M-------------------NGTE--GNNFYVPLSNRTGLV--RSPFEYPQY-YL-----
+------------------------------------------------------------
+--AEPWQFKLLAVYMFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCF
+G-FTVTFYTAIN-GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS
+F-KFSSTHASAGIAFTWVMAMAC-AAPPLV-GWS-----RYIPEGIQCSCGPDYYTLNPE
+YNNESYVLYMFICHFILPVTIIFFTYGRLVCTVKAAAAQQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--DSASTQKAEREVTKMVILMVLGFLVAWTPYATVAAWIFF--NKGAA-FSAQFMAIPAF
+FSKTSALYNPVIYVLLNKQFRSCMLTTL-----FCGKNPLGDEE-SSTVSTSKTEVSS--
+------------------------------------------------------------
+-------------------------------------VSPA
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+M-------------------KQVPEFHEDFYIPIPLDINNLSAYSPFLVPQD-HL-----
+------------------------------------------------------------
+--GNQGIFMAMSVFMFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIF
+G-SPLSFYSFFN-RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN
+F-TFKTPHAIAGCILPWISALAA-SLPPLF-GWS-----RYIPEGLQCSCGPDWYTTNNK
+YNNESYVMFLFCFCFAVPFGTIVFCYGQLLITLKLAAKAQA-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--DSASTQKAEREVTKMVVVMVLGFLVCWAPYASFSLWIVS--HRGEE-FDLRMATIPSC
+LSKASTVYNPVIYVLMNKQFRSCMMKMV------CGKNIEEDEA---STSSQVTQVSSVA
+P-----------------------------------------------------------
+---------------------------------------EK
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+M-------------------RKMS--EEEFYLFKNISS-----VGPWDGPQY-HI-----
+------------------------------------------------------------
+--APVWAFYLQAAFMGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIF
+S-VFPVFVASCN-GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN
+F-RFSSKHALTVVLATWTIGIGV-SIPPFF-GWS-----RFIPEGLQCSCGPDWYTVGTK
+YRSESYTWFLFIFCFIVPLSLICFSYTQLLRALKAVAAQQQ-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESATTQKAEREVSRMVVVMVGSFCVCYVPYAAFAMYMVN--NRNHG-LDLRLVTIPSF
+FSKSACIYNPIIYCFMNKQFQACIMKMV------CGKAMTDESD---TCSSQKTEVSTVS
+S-----------------------------------------------------------
+-----------------------------------TQVGPN
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+-----------------------------------------------------DLAETVI
+A-STISIVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN
+V-RFDAKLAIVGIAFSWIWAAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCITPLSIIVLCYLQVWLAIRAVAKQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESESTQKAEKEVTRMVVVMVLAFC----------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+-----------------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+MAQQWSLQRLAGRHPQDSYEDSTQ--SSIFTYTNSNST-----RGPFEGPNY-HI-----
+------------------------------------------------------------
+--APRWVYHLTSVWMIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVI
+A-STISVVNQVY-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN
+V-RFDAKLAIVGIAFSWIWAAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCITPLSIIVLCYLQVWLAIRAVAKQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESESTQKAEKEVTRMVVVMVLAFCFCWGPYAFFACFAAA--NPGYP-FHPLMAALPAF
+FAKSATIYNPVIYVFMNRQFRNCILQLF-------GKKVDDGSE-LS--SASKTEVSSV-
+------------------------------------------------------------
+-----------------------------------SSVSPA
+>    10== Z68193   1 human Red Opsin <>[]
+MAQQWSLQRLAGRHPQDSYEDSTQ--SSIFTYTNSNST-----RGPFEGPNY-HI-----
+------------------------------------------------------------
+--APRWVYHLTSVWMIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVI
+A-STISIVNQVS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN
+V-RFDAKLAIVGIAFSWIWSAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSY
+PGVQSYMIVLMVTCCIIPLAIIMLCYLQVWLAIRAVAKQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESESTQKAEKEVTRMVVVMIFAYCVCWGPYTFFACFAAA--NPGYA-FHPLMAALPAY
+FAKSATIYNPVIYVFMNRQFRNCILQLF-------GKKVDDGSE-LS--SASKTEVSSV-
+------------------------------------------------------------
+-----------------------------------SSVSPA
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+MTEAWNVAVFAARRSRDD-DDTTR--GSVFTYTNTNNT-----RGPFEGPNY-HI-----
+------------------------------------------------------------
+--APRWVYNLVSFFMIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLV
+A-STISVFNQIF-GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN
+I-KFDSKLAIIGIVFSWVWAWGW-SAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSVE
+LGCQSFMLTLMITCCFLPLFIIIVCYLQVWMAIRAVAAQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESESTQKAEREVSRMVVVMIVAFCICWGPYASFVSFAAA--NPGYA-FHPLAAALPAY
+FAKSATIYNPVIYVFMNRQFRNCIMQLF-------GKKVDDGSE-AS--TTSRTEVSSVS
+N-----------------------------------------------------------
+-----------------------------------SSVAPA
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+MA-AWE-AAFAARRRHEE-EDTTR--DSVFTYTNSNNT-----RGPFEGPNY-HI-----
+------------------------------------------------------------
+--APRWVYNLTSVWMIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVI
+A-STISVINQIS-GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN
+I-KFDGKLAVAGILFSWLWSCAW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSD
+PGVQSYMVVLMVTCCFFPLAIIILCYLQVWLAIRAVAAQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--ESESTQKAEKEVSRMVVVMIVAYCFCWGPYTFFACFAAA--NPGYA-FHPLAAALPAY
+FAKSATIYNPIIYVFMNRQFRNCILQLF-------GKKVDDGSE-VS---TSRTEVSSVS
+N-----------------------------------------------------------
+-----------------------------------SSVSPA
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+M-------------------------SSNSSQAPPNGT-----PGPFDGPQWPYQ-----
+------------------------------------------------------------
+--APQSTYVGVAVLMGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLC
+G-SSVSLSNNIN-GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD
+F-QFQRRHAVSGCAFTWGWALLW-SAPPLL-GWS-----SYVPEGLRTSCGPNWYTGGS-
+-NNNSYILSLFVTCFVLPLSLILFSYTNLLLTLRAAAAQQK-------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--EADTTQRAEREVTRMVIVMVMAFLLCWLPYSTFALVVAT--HKGII-IQPVLASLPSY
+FSKTATVYNPIIYVFMNKQFQSCLLEML-----CCGYQPQRTGKASPGTPGPHADVTAAG
+L-----------------------------------------------------------
+-------------------------------RNKVMPAHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+MESGNVSSSLFGNVSTALRPEARLSAE----------TRLLGWNVPPEELR---H-----
+---------------------------------------IPEHWLTYPE-----------
+--PPESMNYLLGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK
+--TPIFIYNSFH-QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG
+--KMTHGKAIAMIIFIYMYATPW-VVACYTETWG-----RFVPEGYLTSCTFDYLTDNF-
+-DTRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKNKETAEIRIAKAAITICFLFFCSWTPYGVMSLIGAF--GDKTL-LTPGATMIPAC
+ACKMVACIDPFVYAISHPRYRMELQKRCPWL--ALNEKAPE-------SSAVASTSTTQE
+P-----------------------------------------------------------
+-----------------------------------QQTTAA
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+MEYHNVSSVL-GNVSSVLRPDARLSAE----------SRLLGWNVPPDELR---H-----
+---------------------------------------IPEHWLIYPE-----------
+--PPESMNYLLGTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK
+--TPIFIYNSFH-QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG
+--KMTHGKAIAMIIFIYLYATPW-VVACYTESWG-----RFVPEGYLTSCTFDYLTDNF-
+-DTRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKKMNVDSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKEAAEIRIAKAAITICFLFFASWTPYGVMSLIGAF--GDKTL-LTPGATMIPAC
+TCKMVACIDPFVYAISHPRYRMELQKRCPWL--AISEKAPE-------SRAAISTSTTQE
+Q-----------------------------------------------------------
+-----------------------------------QQTTAA
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+ME------PLCNASEPPLRPEAR-SSGNGD-------LQFLGWNVPPDQIQ---Y-----
+---------------------------------------IPEHWLTQLE-----------
+--PPASMHYMLGVFYIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK
+--APIF--NSFH-RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR
+--NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDNF-
+-DTRLFVGTIFFFSFVCPTLMILYYYSQIVGHVFSHEKALREQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVMSLIGAF--GDKSL-LTQGATMIPAC
+TCKLVACIDPFVYAISHPRYRLELQKRCPWL--GVNEKSGE-------ISSAQSTTTQEQ
+------------------------------------------------------------
+-----------------------------------QQTTAA
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+MD------ALCNASEPPLRPEARMSSGSDE-------LQFLGWNVPPDQIQ---Y-----
+---------------------------------------IPEHWLTQLE-----------
+--PPASMHYMLGVFYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK
+--APIFIYNSFH-RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR
+--NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDNF-
+-DTRLFVGTIFLFSFVVPTLMILYYYSQIVGHVFNHEKALREQAKKMNVESLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+SNVDKSKETAEIRIAKAAITICFLFFVSWTPYGVMSLIGAF--GDKSL-LTPGATMIPAC
+TCKLVACIEPFVYAISHPRYRMELQKRCPWL--GVNEKSGE-------ASSAQSTTTQEQ
+T-----------------------------------------------------------
+-----------------------------------QQTSAA
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+MT-----------NATGPQMAYYGAASMDFGYPE---GVSIVDFVRPEIKP---Y-----
+---------------------------------------VHQHWYNYPP-----------
+--VNPMWHYLLGVIYLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTT
+N-VPFFTYNCFSGGVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG
+P-KLTTGKAVVFALISWVIAIGC-ALPPFF-GWG-----NYILEGILDSCSYDYLTQDF-
+-NTFSYNIFIFVFDYFLPAAIIVFSYVFIVKAIFAHEAAMRAQAKKMNVSTLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-NEADAQRAEIRIAKTALVNVSLWFICWTPYALISLKGVM--GDTSG-ITPLVSTLPAL
+LAKSCSCYNPFVYAISHPKYRLAITQHLPWF--CVHETETK-------SNDDSQSNSTVA
+Q-----------------------------------------------------------
+--------------------------------------DKA
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+MA-----------NVTGPQMAFYGSGAATFGYPE---GMTVADFVPDRVKH---M-----
+---------------------------------------VLDHWYNYPP-----------
+--VNPMWHYLLGVVYLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTT
+N-FPPFCYNCFSGGRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG
+P-KLTQGKATFMCGLAWVISVGW-SLPPFF-GWG-----SYTLEGILDSCSYDYFTRDM-
+-NTITYNICIFIFDFFLPASVIVFSYVFIVKAIFAHEAAMRAQAKKMNVTNLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-NEAETQRAEIRIAKTALVNVSLWFICWTPYAAITIQGLL--GNAEG-ITPLLTTLPAL
+LAKSCSCYNPFVYAISHPKFRLAITQHLPWF--CVHEKDPN-------DVEENQSSNTQT
+Q-----------------------------------------------------------
+--------------------------------------EKS
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH---L-----
+---------------------------------------ISPYWNQFPA-----------
+--MDPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKM---------------------------YVPEGNLTSCGIDYLERDW-
+-NPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----DAQSQA-TASEA
+E-----------------------------------------------------------
+--------------------------------------SKA
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTPDMAH---L-----
+---------------------------------------ISPYWNQFPA-----------
+--MDPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKIAYIWFMSSIW-CLAPAF-GWS-----RYVPEGNLTSCGIDYLERDW-
+-NPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDAEKSAEGKLAKVALVTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----DAQSQA-TASEA
+E-----------------------------------------------------------
+--------------------------------------SKA
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+MD-----SFAAVATQLGPQFA-----APS--------NGSVVDKVTPDMAH---L-----
+---------------------------------------ISPYWDQFPA-----------
+--MDPIWAKILTAYMIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMIT
+N-TPMMGINLYF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG
+R-PMTIPLALGKIAYIWFMSTIWCCLAPVF-GWS-----RYVPEGNLTSCGIDYLERDW-
+-NPRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDADKSAEGKLAKVALVTISLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGAC
+FAKSAACYNPIVYGISHPKYRLALKEKCPCC--VFGKVDDGKSS----EAQSQA-TTSEA
+E-----------------------------------------------------------
+--------------------------------------SKA
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+MERSHLPETPFDLAHSGPRFQ-----AQSSG------NGSVLDNVLPDMAH---L-----
+---------------------------------------VNPYWSRFAP-----------
+--MDPMMSKILGLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMAS
+Q-SPVMIINFYY-ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING
+T-PMTIKTSIMKILFIWMMAVFW-TVMPLI-GWS-----AYVPEGNLTACSIDYMTRMW-
+-NPRSYLITYSLFVYYTPLFLICYSYWFIIAAVAAHEKAMREQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDCDKSAEGKLAKVALTTISLWFMAWTPYLVICYFGLF--KI-DG-LTPLTTIWGAT
+FAKTSAVYNPIVYGISHPKYRIVLKEKCPMC--VFGNTDEPKPD----APASDTETTSEA
+D-----------------------------------------------------------
+--------------------------------------SKA
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+MERSLLPEPPLAMALLGPRFE-----AQTGG------NRSVLDNVLPDMAP---L-----
+---------------------------------------VNPHWSRFAP-----------
+--MDPTMSKILGLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMAS
+Q-SPVMIINFYY-ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING
+T-PMTIKTSIMKIAFIWMMAVFW-TIMPLI-GWS-----SYVPEGNLTACSIDYMTRQW-
+-NPRSYLITYSLFVYYTPLFMICYSYWFIIATVAAHEKAMRDQAKKMNVKSLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SEDCDKSAENKLAKVALTTISLWFMAWTPYLIICYFGLF--KI-DG-LTPLTTIWGAT
+FAKTSAVYNPIVYGISHPNDRLVLKEKCPMC--VCGTTDEPKPD----APPSDTETTSEA
+E-----------------------------------------------------------
+--------------------------------------SKD
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+MI-----------AVSGPSYE-----AFSYGGQARFNNQTVVDKVPPDMLH---L-----
+---------------------------------------IDANWYQYPP-----------
+--LNPMWHGILGFVIGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFC
+M-SPPMVINCYY-ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG
+K-PLSINGALIRIIAIWLFSLGW-TIAPMF-GWN-----RYVPEGNMTACGTDYFNRGL-
+-LSASYLVCYGIWVYFVPLFLIIYSYWFIIQAVAAHEKNMREQAKKMNVASLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+S-SENQNTSAECKLAKVALMTISLWFMAWTPYLVINFSGIF--NL-VK-ISPLFTIWGSL
+FAKANAVYNPIVYGISHPKYRAALFAKFPSL--ACAA--EPSSD----AVSTTSGTTTVT
+D-----------------------------------------------------------
+-----------------------------------NEKSNA
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+MA------------------NQLSYSSLGWPYQP---NASVVDTMPKEMLY---M-----
+---------------------------------------IHEHWYAFPP-----------
+--MNPLWYSILGVAMIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAF
+M-MPTMTSNCFA-ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA
+A-PLTHKKATLLLLFVWIWSGGW-TILPFF-GWS-----RYVPEGNLTSCTVDYLTKDW-
+-SSASYVVIYGLAVYFLPLITMIYCYFFIVHAVAEHEKQLREQAKKMNVASLR-------
+------------------------------------------------------------
+------------------------------------------------------------
+ANADQQKQSAECRLAKVAMMTVGLWFMAWTPYLIISWAGVF--SSGTR-LTPLATIWGSV
+FAKANSCYNPIVYGISHPRYKAALYQRFPSL--ACGSGESGSDV----KSEASATTTMEE
+K-----------------------------------------------------------
+-----------------------------------PKIPEA
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+MV------------------ESTTLVNQTWWYNPTVD-----------------------
+---------------------------------------IHPHWAKFDP-----------
+--IPDAVYYSVGIFIGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAI
+NGFPLKTISAFM-KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAA
+SKKMSHRRAFLMIIFVWMWSIVW-SVGPVF-NWG-----AYVPEGILTSCSFDYLSTDP-
+-STRSFILCMYFCGFMLPIIIIAFCYFNIVMSVSNHEKEMAAMAKRLNAKELR-------
+------------------------------------------------------------
+------------------------------------------------------------
+--KAQAGASAEMKLAKISMVIITQFMLSWSPYAIIALLAQF--GPAEW-VTPYAAELPVL
+FAKASAIHNPIVYSVSHPKFREAIQTTFPWLLTCCQFDEKECED----ANDAEEEVVASE
+R--GGESRDAAQMKEMMAMMQKMQAQQAAYQP---PPPPQGYPPQGYPPQGAYPPPQGYP
+PQGYPPQGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQAYQA
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+MG------------------RDLR-DNETWWYNPSIV-----------------------
+---------------------------------------VHPHWREFDQ-----------
+--VPDAVYYSLGIFIGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLV
+NGFPLMTISCFL-KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAA
+SKKMSHRRAFIMIIFVWLWSVLW-AIGPIF-GWG-----AYTLEGVLCNCSFDYISRDS-
+-TTRSNILCMFILGFFGPILIIFFCYFNIVMSVSNHEKEMAAMAKRLNAKELR-------
+------------------------------------------------------------
+------------------------------------------------------------
+--KAQAGANAEMRLAKISIVIVSQFLLSWSPYAVVALLAQF--GPLEW-VTPYAAQLPVM
+FAKASAIHNPMIYSVSHPKFREAISQTFPWVLTCCQFDDKETED----DKDAETEIPAGE
+SSDAAPSADAAQMKEMMAMMQKMQQQQAAYPPQGYAPPPQGYPPQGYPPQGY--PPQGYP
+PQGYPP---PPQGAPPQGAPP------AAPPQGVDNQAYQA
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMD-----------------VNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDGGADPVAGS
+WAPHLLS------------------------EVTAS---PAPTW---DAPPDNASGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLF-GWA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVEPDSVIALNG------------------------------------------------
+----IVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTFLW
+LGYANSLINPFIYAFFNRDLRTTYRSLL-----QCQYRNINRKLSAAGMHEALKLAERPE
+RPEFV-------------------------------------------------------
+---------------------------LQNADYCRKKGHDS
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+M-----------------------------------------------------------
+--PHLLS---------------------GFLEVTAS---PAPTW---DAPPDNVSGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLF-GWA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVQPESVISLNG------------------------------------------------
+----VVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLW
+LGYANSLINPFIYAFFNRDLRPTSRSLL-----QCQYRNINRKLSAAGMHEALKLAERPE
+RSEFV-------------------------------------------------------
+---------------------------LQNSDHCGKKGHDT
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+M-----------------------------------------------------------
+--PHLLS---------------------GFLEVTAS---PAPTW---DAPPDNVSGCGEQ
+INYGRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVA
+V-MPFVSVTDLIGGKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTY
+PVRQNGKCMAKMILSVWLLSASI-TLPPLF-GWA-----QNVNDDKVCLISQDF------
+----GYTIYSTAVAFYIPMSVMLFMYYQIYKAARKSAAKHKF--------------PGFP
+RVQPESVISLNG------------------------------------------------
+----VVKLQKE------------------VEECAN------------------LSRLLKH
+ERKNISIFKREQKAATTLGIIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLW
+LGYANSLINPFIYAFFNRDLRTTYRSLL-----QCQYRNINRKLSAAGMHEALKLAERPE
+RSEFV-------------------------------------------------------
+---------------------------LQNSDHCGKKGHDT
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+M-----------------------------------------------------------
+--------------------DVLSPGQGNNTTSPPAPFETGGNTTGISD-----------
+--VTVSYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVL
+V-LPMAALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDY
+VNKRTPRRAAALISLTWLIGFLI-SIPPML-GWRTP---EDRSDPDACTISKDH------
+----GYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVKKVEKTGADTRHGASPAPQ
+PKK---------SVNGESGSRNWRLGVESKAGGALCANGAVRQGDDGAALEVIEVHRVGN
+SKEHLPLPSEAGPTPCAPASFERKNERNA-------------------------------
+EAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CESSCH-MPTLLGAIINW
+LGYSNSLLNPVIYAYFNKDFQNAFKKII-----KCKF-----------------------
+------------------------------------------------------------
+--------------------------------------CRQ
+>    33=p A35181 serotonin receptor class 1A - rat
+M-----------------------------------------------------------
+--------------------DVFSFGQGNNTTASQEPFGTGGNVTSISD-----------
+--VTFSYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVL
+V-LPMAALYQVL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDY
+VNKRTPRRAAALISLTWLIGFLI-SIPPML-GWRTP---EDRSDPDACTISKDH------
+----GYTIYSTFGAFYIPLLLMLVLYGRIFRAARFRIRKTVRKVEKKGAGTSLGTSSAPP
+PKK---------SLNGQPGSGDWRRCAENRAVGTPCTNGAVRQGDDEATLEVIEVHRVGN
+SKEHLPLPSESGSNSYAPACLERKNERNA-------------------------------
+EAKRKMALARERKTVKTLGIIMGTFILCWLPFFIVALVLPF-CESSCH-MPALLGAIINW
+LGYSNSLLNPVIYAYFNKDFQNAFKKII-----KCKF-----------------------
+------------------------------------------------------------
+--------------------------------------CRR
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRD-----------------NASANDTSATNM---TDDRYWSLTV-----------
+--YSHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVL
+V-MPLSVVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDY
+IRRRSARRILLMIMVVWIVALFI-SIPPLF-GWRDP--NNDPDKTGTCIISQDK------
+----GYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASP
+KTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSS
+SSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYS-------------
+RTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF--VDPEG-IPPFARSFVLW
+LGYFNSLLNPIIYTIFSPEFRSAFQKIL-----FGKY-----------------------
+------------------------------------------------------------
+------------------------------------RRGHR
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRD-----------------NASANDTSATNM---TDDRYWSLTV-----------
+--YSHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVL
+V-MPLSVVSEIS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDY
+IRRRSARRILLMIMVVWIVALFI-SIPPLF-GWRDP--NNDPDKTGTCIISQDK------
+----GYTIFSTVGAFYLPMLVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASP
+KTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSS
+SSERLKQIQIETAEAFANGCAEEASIAMLERQCNNGKKISSNDTPYS-------------
+RTREKLELKRERKAARTLAIITGAFLICWLPFFIIALIGPF--VDPEG-IPPFARSFVLW
+LGYFNSLLNPIIYTIFSPEFRSAFQKIL-----FGKY-----------------------
+------------------------------------------------------------
+------------------------------------RRGHR
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+M--------------------------------------------------------EGA
+EGQEELDWEALYLRLPLQNCSWNSTGWEPNWNVTVV---PNTTWWQASAPFDTP------
+--AALVRAAAKAVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACL
+V-MPLGAVYEVV-QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDY
+IHASTAKRVGMMIACVWTVSFFV-CIAQLL-GWKDPDWNQRVSEDLRCVVSQDV------
+----GYQIFATASSFYVPVLIILILYWRIYQTARKRIRRRRGATARGGV--------GPP
+PVPAGGALVAGGGSGG------------------------------------IAAAVVAV
+IGRPLPTISETTTTGFTNVSSNNTSPE--KQSCANGLEADPPTTGYGAVAAAYYPSLVRR
+KPKEAADSKRERKAAKTLAIITGAFVACWLPFFVLAILVPT---CDCE-VSPVLTSLSLW
+LGYFNSTLNPVIYTVFSPEFRHAFQRLL-----CGRR-----------------------
+------------------------------------------------------------
+---------------------------------VRRRRAPQ
diff --git a/binaries/src/mafft/test/sample.lins1 b/binaries/src/mafft/test/sample.lins1
new file mode 100644 (file)
index 0000000..8860bcf
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+MN--------------------GTE--GDNFYVPFSNKTG--LARSP-------------
+--------------------YEYPQY-YLAEPW---------KYSA-----LAAYMFFLI
+LVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-FTVTMYTSMN-GYFV--
+FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGNF-RFGNTHAIMGVAFTWIM
+ALAC-AAPPLV-GWS-----RYIPEGMQCSCGPDYYTLNPNFNNESYVVYMFVVHFLVPF
+VIIFFCYGRLLCTVKEAAAAQQESA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEKEVTRMVV
+LMVIGFLVCWVPYASVAFYIFT--HQGSD-FGATFMTLPAFFAKSSALYNPVIYILMNKQ
+FRNCMITTL-----CCGKNPLGDDE-SG-ASTSKTEVS----------------------
+------------------------------------------------------------
+----------------SVS-TSPVSPA---
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+MN--------------------GTE--GPNFYVPFSNITG--VVRSP-------------
+--------------------FEQPQY-YLAEPW---------QFSM-----LAAYMFLLI
+VLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-FTTTLYTSLH-GYFV--
+FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSNF-RFGENHAIMGVAFTWVM
+ALAC-AAPPLV-GWS-----RYIPEGMQCSCGIDYYTLKPEVNNESFVIYMFVVHFTIPM
+IVIFFCYGQLVFTVKEAAAQQQESA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------TTQKAEKEVTRMVI
+IMVIFFLICWLPYASVAMYIFT--HQGSN-FGPIFMTLPAFFAKTASIYNPIIYIMMNKQ
+FRNCMLTSL-----CCGKNPLGDDE-AS-ATASKTETS----------------------
+------------------------------------------------------------
+----------------QVA-PA--------
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+MN--------------------GTE--GINFYVPMSNKTG--VVRSP-------------
+--------------------FEYPQY-YLAEPW---------KYRL-----VCCYIFFLI
+STGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-FTVTFYTAWN-GYFV--
+FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGNF-RFSATHAMMGIAFTWVM
+AFSC-AAPPLF-GWS-----RYMPEGMQCSCGPDYYTHNPDYHNESYVLYMFVIHFIIPV
+VVIFFSYGRLICKVREAAAQQQESA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------TTQKAEKEVTRMVI
+LMVLGFMLAWTPYAVVAFWIFT--NKGAD-FTATLMAVPAFFSKSSSLYNPIIYVLMNKQ
+FRNCMITTI-----CCGKNPFGDEDVSSTVSQSKTEVS----------------------
+------------------------------------------------------------
+----------------SVS-SSQVSPA---
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+MN--------------------GTE--GKNFYVPMSNRTG--LVRSP-------------
+--------------------FEYPQY-YLAEPW---------QFKI-----LALYLFFLM
+SMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-FTVTFYTAIN-GYFV--
+LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGSF-KFSSSHAFAGIAFTWVM
+ALAC-AAPPLF-GWS-----RYIPEGMQCSCGPDYYTLNPDYNNESYVIYMFVCHFILPV
+AVIFFTYGRLVCTVKAAAAQQQDSA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEREVTKMVI
+LMVFGFLIAWTPYATVAAWIFF--NKGAD-FSAKFMAIPAFFSKSSALYNPVIYVLLNKQ
+FRNCMLTTI-----FCGKNPLGDDE-SSTVSTSKTEVS----------------------
+------------------------------------------------------------
+----------------SVS-PA--------
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+MN--------------------GTE--GNNFYVPLSNRTG--LVRSP-------------
+--------------------FEYPQY-YLAEPW---------QFKL-----LAVYMFFLI
+CLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-FTVTFYTAIN-GYFA--
+LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGSF-KFSSTHASAGIAFTWVM
+AMAC-AAPPLV-GWS-----RYIPEGIQCSCGPDYYTLNPEYNNESYVLYMFICHFILPV
+TIIFFTYGRLVCTVKAAAAQQQDSA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEREVTKMVI
+LMVLGFLVAWTPYATVAAWIFF--NKGAA-FSAQFMAIPAFFSKTSALYNPVIYVLLNKQ
+FRSCMLTTL-----FCGKNPLGDEE-SSTVSTSKTEVS----------------------
+------------------------------------------------------------
+----------------SVS-PA--------
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+MK--------------------QVPEFHEDFYIPIPLDINNLSAYSP-------------
+--------------------FLVPQD-HLGNQG---------IFMA-----MSVFMFFIF
+IGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-SPLSFYSFFN-RYFI--
+FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGNF-TFKTPHAIAGCILPWIS
+ALAA-SLPPLF-GWS-----RYIPEGLQCSCGPDWYTTNNKYNNESYVMFLFCFCFAVPF
+GTIVFCYGQLLITLKLAAKAQADSA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEREVTKMVV
+VMVLGFLVCWAPYASFSLWIVS--HRGEE-FDLRMATIPSCLSKASTVYNPVIYVLMNKQ
+FRSCMM-KM-----VCGKN-IEEDE-AS-TSSQVTQVS----------------------
+------------------------------------------------------------
+----------------SVA-PEK-------
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+MR--------------------KMS--EEEFYL-----FKNISSVGP-------------
+--------------------WDGPQY-HIAPVW---------AFYL-----QAAFMGTVF
+LIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-VFPVFVASCN-GYFV--
+FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGNF-RFSSKHALTVVLATWTI
+GIGV-SIPPFF-GWS-----RFIPEGLQCSCGPDWYTVGTKYRSESYTWFLFIFCFIVPL
+SLICFSYTQLLRALKAVAAQQQESA-----------------------------------
+------------------------------------------------------------
+----------------------------------------------TTQKAEREVSRMVV
+VMVGSFCVCYVPYAAFAMYMVN--NRNHG-LDLRLVTIPSFFSKSACIYNPIIYCFMNKQ
+FQACIM-KM-----VCGKA-MTDES-DT-CSSQKTEVS----------------------
+------------------------------------------------------------
+----------------TVS-STQVGPN---
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+----------------------------------DLAETVIA-STISIVNQVS-GYFV--
+LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGNV-RFDAKLAIVGIAFSWIW
+AAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCITPL
+SIIVLCYLQVWLAIRAVAKQQKESE-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEKEVTRMVV
+VMVLAFC-----------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+MAQQWS-LQRLAGRHPQDSYEDSTQ--SSIFTY-----TNSNSTRGP-------------
+--------------------FEGPNY-HIAPRW---------VYHL-----TSVWMIFVV
+IASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISVVNQVY-GYFV--
+LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGNV-RFDAKLAIVGIAFSWIW
+AAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCITPL
+SIIVLCYLQVWLAIRAVAKQQKESE-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEKEVTRMVV
+VMVLAFCFCWGPYAFFACFAAA--NPGYP-FHPLMAALPAFFAKSATIYNPVIYVFMNRQ
+FRNCILQLF----------GKKVDDGSELSSASKTEVS----------------------
+------------------------------------------------------------
+----------------SV---SSVSPA---
+>    10== Z68193   1 human Red Opsin <>[]
+MAQQWS-LQRLAGRHPQDSYEDSTQ--SSIFTY-----TNSNSTRGP-------------
+--------------------FEGPNY-HIAPRW---------VYHL-----TSVWMIFVV
+TASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISIVNQVS-GYFV--
+LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGNV-RFDAKLAIVGIAFSWIW
+SAVW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCIIPL
+AIIMLCYLQVWLAIRAVAKQQKESE-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEKEVTRMVV
+VMIFAYCVCWGPYTFFACFAAA--NPGYA-FHPLMAALPAYFAKSATIYNPVIYVFMNRQ
+FRNCILQLF----------GKKVDDGSELSSASKTEVS----------------------
+------------------------------------------------------------
+----------------SV---SSVSPA---
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+MTEAWNVAVFAARRSRDD--DDTTR--GSVFTY-----TNTNNTRGP-------------
+--------------------FEGPNY-HIAPRW---------VYNL-----VSFFMIIVV
+IASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-STISVFNQIF-GYFI--
+LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGNI-KFDSKLAIIGIVFSWVW
+AWGW-SAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSVELGCQSFMLTLMITCCFLPL
+FIIIVCYLQVWMAIRAVAAQQKESE-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEREVSRMVV
+VMIVAFCICWGPYASFVSFAAA--NPGYA-FHPLAAALPAYFAKSATIYNPVIYVFMNRQ
+FRNCIMQLF----------GKKVDDGSEASTTSRTEVS----------------------
+------------------------------------------------------------
+----------------SVS-NSSVAPA---
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+MA-AWE-AAFAARRRHEE--EDTTR--DSVFTY-----TNSNNTRGP-------------
+--------------------FEGPNY-HIAPRW---------VYNL-----TSVWMIFVV
+AASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-STISVINQIS-GYFI--
+LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGNI-KFDGKLAVAGILFSWLW
+SCAW-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSDPGVQSYMVVLMVTCCFFPL
+AIIILCYLQVWLAIRAVAAQQKESE-----------------------------------
+------------------------------------------------------------
+----------------------------------------------STQKAEKEVSRMVV
+VMIVAYCFCWGPYTFFACFAAA--NPGYA-FHPLAAALPAYFAKSATIYNPIIYVFMNRQ
+FRNCILQLF----------GKKVDDGSEVST-SRTEVS----------------------
+------------------------------------------------------------
+----------------SVS-NSSVSPA---
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+MS--------------------------SNSSQ-----APPNGTPGP-------------
+--------------------FDGPQWPYQAPQS---------TYVG-----VAVLMGTVV
+ACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-SSVSLSNNIN-GFFV--
+FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGDF-QFQRRHAVSGCAFTWGW
+ALLW-SAPPLL-GWS-----SYVPEGLRTSCGPNWYTGGSN--NNSYILSLFVTCFVLPL
+SLILFSYTNLLLTLRAAAAQQKEAD-----------------------------------
+------------------------------------------------------------
+----------------------------------------------TTQRAEREVTRMVI
+VMVMAFLLCWLPYSTFALVVAT--HKGII-IQPVLASLPSYFSKTATVYNPIIYVFMNKQ
+FQSCLLEML-----CCGYQPQRTGKASPGTPGPHADVT----------------------
+------------------------------------------------------------
+----------------AAGLRNKVMPAHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+MESGNVSSSLFGNVSTALRPE----ARLSA---E---TRLLGWNVPP-------------
+--------------------EELR---HIPEHWLTYPEPPESMNYL-----LGTLYIFFT
+LMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--TPIFIYNSFH-QGYA--
+LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--KMTHGKAIAMIIFIYMY
+ATPW-VVACYTETWG-----RFVPEGYLTSCTFDYLTDN--FDTRLFVACIFFFSFVCPT
+TMITYYYSQIVGHVFSHEKALRDQAKKMNVESLR--------------------------
+------------------------------------------------------------
+-----------------------------------------SNVDKNKETAEIRIAKAAI
+TICFLFFCSWTPYGVMSLIGAF--GDKTL-LTPGATMIPACACKMVACIDPFVYAISHPR
+YRMELQKRCPWL--ALNEKAPESSAVASTST-TQEPQQT---------------------
+------------------------------------------------------------
+----------------TAA-----------
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+MEYHNVSSVL-GNVSSVLRPD----ARLSA---E---SRLLGWNVPP-------------
+--------------------DELR---HIPEHWLIYPEPPESMNYL-----LGTLYIFFT
+VISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--TPIFIYNSFH-QGYA--
+LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--KMTHGKAIAMIIFIYLY
+ATPW-VVACYTESWG-----RFVPEGYLTSCTFDYLTDN--FDTRLFVACIFFFSFVCPT
+TMITYYYSQIVGHVFSHEKALRDQAKKMNVDSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------SNVDKSKEAAEIRIAKAAI
+TICFLFFASWTPYGVMSLIGAF--GDKTL-LTPGATMIPACTCKMVACIDPFVYAISHPR
+YRMELQKRCPWL--AISEKAPESRAAISTST-TQEQQQT---------------------
+------------------------------------------------------------
+----------------TAA-----------
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+ME------PLCNASEPPLRPE----AR-SSGNGD---LQFLGWNVPP-------------
+--------------------DQIQ---YIPEHWLTQLEPPASMHYM-----LGVFYIFLF
+CASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF--NSFH-RGFAIY
+LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMNIIIWLY
+CTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--FDTRLFVGTIFFFSFVCPT
+LMILYYYSQIVGHVFSHEKALREQAKKMNVESLR--------------------------
+------------------------------------------------------------
+-----------------------------------------SNVDKSKETAEIRIAKAAI
+TICFLFFVSWTPYGVMSLIGAF--GDKSL-LTQGATMIPACTCKLVACIDPFVYAISHPR
+YRLELQKRCPWL--GVNEKSGEISSAQSTTT-QEQQQTT---------------------
+------------------------------------------------------------
+----------------AA------------
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+MD------ALCNASEPPLRPE----ARMSSGSDE---LQFLGWNVPP-------------
+--------------------DQIQ---YIPEHWLTQLEPPASMHYM-----LGVFYIFLF
+FASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIFIYNSFH-RGFA--
+LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMNIIIWLY
+CTPW-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--FDTRLFVGTIFLFSFVVPT
+LMILYYYSQIVGHVFNHEKALREQAKKMNVESLR--------------------------
+------------------------------------------------------------
+-----------------------------------------SNVDKSKETAEIRIAKAAI
+TICFLFFVSWTPYGVMSLIGAF--GDKSL-LTPGATMIPACTCKLVACIEPFVYAISHPR
+YRMELQKRCPWL--GVNEKSGEASSAQSTTT-QEQTQQT---------------------
+------------------------------------------------------------
+----------------SAA-----------
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+M-----------TNATGPQMAYYGAASMDFGYPE---GVSIVDFVRP-------------
+--------------------EIKP---YVHQHWYNYPPVNPMWHYL-----LGVIYLFLG
+TVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-VPFFTYNCFSGGVWM--
+FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNGP-KLTTGKAVVFALISWVI
+AIGC-ALPPFF-GWG-----NYILEGILDSCSYDYLTQD--FNTFSYNIFIFVFDYFLPA
+AIIVFSYVFIVKAIFAHEAAMRAQAKKMNVSTLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-NEADAQRAEIRIAKTAL
+VNVSLWFICWTPYALISLKGVM--GDTSG-ITPLVSTLPALLAKSCSCYNPFVYAISHPK
+YRLAITQHLPWF--CVHETETKSNDDSQSNS-TVAQDK----------------------
+------------------------------------------------------------
+------------------A-----------
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+M-----------ANVTGPQMAFYGSGAATFGYPE---GMTVADFVPD-------------
+--------------------RVKH---MVLDHWYNYPPVNPMWHYL-----LGVVYLFLG
+VISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-FPPFCYNCFSGGRWM--
+FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNGP-KLTQGKATFMCGLAWVI
+SVGW-SLPPFF-GWG-----SYTLEGILDSCSYDYFTRD--MNTITYNICIFIFDFFLPA
+SVIVFSYVFIVKAIFAHEAAMRAQAKKMNVTNLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-NEAETQRAEIRIAKTAL
+VNVSLWFICWTPYAAITIQGLL--GNAEG-ITPLLTTLPALLAKSCSCYNPFVYAISHPK
+FRLAITQHLPWF--CVHEKDPNDVEENQSSN-TQTQEK----------------------
+------------------------------------------------------------
+------------------S-----------
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTP-------------
+--------------------DMAH---LISPYWNQFPAMDPIWAKI-----LTAYMIMIG
+MISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--
+LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKM------
+---------------------YVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPL
+FLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SEDAEKSAEGKLAKVAL
+VTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGACFAKSAACYNPIVYGISHPK
+YRLALKEKCPCC--VFGKVDDGKSSDAQSQA-TASEAE----------------------
+------------------------------------------------------------
+----------------SKA-----------
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+ME-----SFAVAAAQLGPHFA-----PLS--------NGSVVDKVTP-------------
+--------------------DMAH---LISPYWNQFPAMDPIWAKI-----LTAYMIMIG
+MISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--
+LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKIAYIWFM
+SSIW-CLAPAF-GWS-----RYVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPL
+FLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SEDAEKSAEGKLAKVAL
+VTITLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGACFAKSAACYNPIVYGISHPK
+YRLALKEKCPCC--VFGKVDDGKSSDAQSQA-TASEAE----------------------
+------------------------------------------------------------
+----------------SKA-----------
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+MD-----SFAAVATQLGPQFA-----APS--------NGSVVDKVTP-------------
+--------------------DMAH---LISPYWDQFPAMDPIWAKI-----LTAYMIIIG
+MISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--
+LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKIAYIWFM
+STIWCCLAPVF-GWS-----RYVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPL
+FLICYSYWFIIAAVSAHEKAMREQAKKMNVKSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SEDADKSAEGKLAKVAL
+VTISLWFMAWTPYLVINCMGLF--KF-EG-LTPLNTIWGACFAKSAACYNPIVYGISHPK
+YRLALKEKCPCC--VFGKVDDGKSSEAQSQA-TTSEAE----------------------
+------------------------------------------------------------
+----------------SKA-----------
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+MERSHLPETPFDLAHSGPRFQ-----AQSSG------NGSVLDNVLP-------------
+--------------------DMAH---LVNPYWSRFAPMDPMMSKI-----LGLFTLAIM
+IISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINFYY-ETWV--
+LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGINGT-PMTIKTSIMKILFIWMM
+AVFW-TVMPLI-GWS-----AYVPEGNLTACSIDYMTRM--WNPRSYLITYSLFVYYTPL
+FLICYSYWFIIAAVAAHEKAMREQAKKMNVKSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SEDCDKSAEGKLAKVAL
+TTISLWFMAWTPYLVICYFGLF--KI-DG-LTPLTTIWGATFAKTSAVYNPIVYGISHPK
+YRIVLKEKCPMC--VFGNTDEPKPDAPASDTETTSEAD----------------------
+------------------------------------------------------------
+----------------SKA-----------
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+MERSLLPEPPLAMALLGPRFE-----AQTGG------NRSVLDNVLP-------------
+--------------------DMAP---LVNPHWSRFAPMDPTMSKI-----LGLFTLVIL
+IISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINFYY-ETWV--
+LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGINGT-PMTIKTSIMKIAFIWMM
+AVFW-TIMPLI-GWS-----SYVPEGNLTACSIDYMTRQ--WNPRSYLITYSLFVYYTPL
+FMICYSYWFIIATVAAHEKAMRDQAKKMNVKSLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SEDCDKSAENKLAKVAL
+TTISLWFMAWTPYLIICYFGLF--KI-DG-LTPLTTIWGATFAKTSAVYNPIVYGISHPN
+DRLVLKEKCPMC--VCGTTDEPKPDAPPSDTETTSEAE----------------------
+------------------------------------------------------------
+----------------SKD-----------
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+M-----------IAVSGPSYE-----AFSYGGQARFNNQTVVDKVPP-------------
+--------------------DMLH---LIDANWYQYPPLNPMWHGI-----LGFVIGMLG
+FVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-SPPMVINCYY-ETWV--
+LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSGK-PLSINGALIRIIAIWLF
+SLGW-TIAPMF-GWN-----RYVPEGNMTACGTDYFNRG--LLSASYLVCYGIWVYFVPL
+FLIIYSYWFIIQAVAAHEKNMREQAKKMNVASLR--------------------------
+------------------------------------------------------------
+-----------------------------------------S-SENQNTSAECKLAKVAL
+MTISLWFMAWTPYLVINFSGIF--NL-VK-ISPLFTIWGSLFAKANAVYNPIVYGISHPK
+YRAALFAKFPSL--AC-AAEPSSDAVSTTSG-TTTVTDN---------------------
+------------------------------------------------------------
+-------------EK-SNA-----------
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+M-------------ANQLSYS-----SLGWPYQP---NASVVDTMPK-------------
+--------------------EMLY---MIHEHWYAFPPMNPLWYSI-----LGVAMIILG
+IICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-MPTMTSNCFA-ETWI--
+LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAAA-PLTHKKATLLLLFVWIW
+SGGW-TILPFF-GWS-----RYVPEGNLTSCTVDYLTKD--WSSASYVVIYGLAVYFLPL
+ITMIYCYFFIVHAVAEHEKQLREQAKKMNVASLR--------------------------
+------------------------------------------------------------
+-----------------------------------------ANADQQKQSAECRLAKVAM
+MTVGLWFMAWTPYLIISWAGVF--SSGTR-LTPLATIWGSVFAKANSCYNPIVYGISHPR
+YKAALYQRFPSL--ACGSGESGSDVKSEASA-TTTMEEK---------------------
+------------------------------------------------------------
+-------------PKIPEA-----------
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+M-------------VESTTLV-----NQTWWY-----NPTV-------------------
+---------------------------DIHPHWAKFDPIPDAVYYS-----VGIFIGVVG
+IIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGFPLKTISAFM-KKWI--
+FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASKKMSHRRAFLMIIFVWMW
+SIVW-SVGPVF-NWG-----AYVPEGILTSCSFDYLSTD--PSTRSFILCMYFCGFMLPI
+IIIAFCYFNIVMSVSNHEKEMAAMAKRLNAKELR--------------------------
+------------------------------------------------------------
+-----------------------------------------K-AQ-AGASAEMKLAKISM
+VIITQFMLSWSPYAIIALLAQF--GPAEW-VTPYAAELPVLFAKASAIHNPIVYSVSHPK
+FREAIQTTFPWLLTCCQFDEKECEDANDAEE-EVVASER--GGESRDAAQMKEMMAMMQK
+MQAQQAAYQP---PPPPQGYPPQGYPPQGAYPPPQGYPPQGYPPQGYPPQGYPPQGAPPQ
+VEAPQGAPPQGVDNQAYQA-----------
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+M-------------GRDLR-D-----NETWWY-----NPSI-------------------
+---------------------------VVHPHWREFDQVPDAVYYS-----LGIFIGICG
+IIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGFPLMTISCFL-KKWI--
+FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASKKMSHRRAFIMIIFVWLW
+SVLW-AIGPIF-GWG-----AYTLEGVLCNCSFDYISRD--STTRSNILCMFILGFFGPI
+LIIFFCYFNIVMSVSNHEKEMAAMAKRLNAKELR--------------------------
+------------------------------------------------------------
+-----------------------------------------K-AQ-AGANAEMRLAKISI
+VIVSQFLLSWSPYAVVALLAQF--GPLEW-VTPYAAQLPVMFAKASAIHNPMIYSVSHPK
+FREAISQTFPWVLTCCQFDDKETEDDKDAET-EIPAGESSDAAPSADAAQMKEMMAMMQK
+MQQQQAAYPPQGYAPPPQGYPPQGYPPQGY--PPQGYPPQGYPP---PPQGAPPQGAPP-
+-----AAPPQGVDNQAYQA-----------
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDG----GADPVAGSWAPHLLS---EVT
+ASPAPTWDAPPDNA------SGCGE----------QINYGRVEKVV-----IGSILTLIT
+LLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--
+FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLL
+SASI-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPM
+SVMLFMYYQIYKAARKSAAKHKF--------------PGFPRVEPDSVIALNG-------
+---------------------------------------------IVKLQKE--------
+----------VEECAN------------------LSRLLKHERKNISIFKREQKAATTLG
+IIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTFLWLGYANSLINPFIYAFFNRD
+LRTTYRSLL-----QCQYRNINRKLSAAGMHEALKLAERPERPEFVLQNADYCRKKGHDS
+------------------------------------------------------------
+------------------------------
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+M------------------------------------------------PHLLSGFLEVT
+ASPAPTWDAPPDNV------SGCGE----------QINYGRVEKVV-----IGSILTLIT
+LLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--
+FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLL
+SASI-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPM
+SVMLFMYYQIYKAARKSAAKHKF--------------PGFPRVQPESVISLNG-------
+---------------------------------------------VVKLQKE--------
+----------VEECAN------------------LSRLLKHERKNISIFKREQKAATTLG
+IIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRD
+LRPTSRSLL-----QCQYRNINRKLSAAGMHEALKLAERPERSEFVLQNSDHCGKKGHDT
+------------------------------------------------------------
+------------------------------
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+M------------------------------------------------PHLLSGFLEVT
+ASPAPTWDAPPDNV------SGCGE----------QINYGRVEKVV-----IGSILTLIT
+LLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--
+FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLL
+SASI-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPM
+SVMLFMYYQIYKAARKSAAKHKF--------------PGFPRVQPESVISLNG-------
+---------------------------------------------VVKLQKE--------
+----------VEECAN------------------LSRLLKHERKNISIFKREQKAATTLG
+IIVGAFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRD
+LRTTYRSLL-----QCQYRNINRKLSAAGMHEALKLAERPERSEFVLQNSDHCGKKGHDT
+------------------------------------------------------------
+------------------------------
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+MDVLSPG-----------------------------------------------------
+---------QGNNT------TSPPAPFETGGNTTGISDVTVSYQVI-----TSLLLGTLI
+FCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQVL-NKWT--
+LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLI
+GFLI-SIPPML-GWRTPEDRSDPD---ACTISKDH----------GYTIYSTFGAFYIPL
+LLMLVLYGRIFRAARFRIRKTVKKVEKTGADTRHGASPAPQPKK-----SVNG--ESGSR
+NWRLGVESKAGGALCANGAVRQGDDGAAL--EVIEVHRVGNSKEHLPLPSEAGPTPCAPA
+S------------------FERKNERNA-------------EAKRKMALARERKTVKTLG
+IIMGTFILCWLPFFIVALVLPF-CESSCH-MPTLLGAIINWLGYSNSLLNPVIYAYFNKD
+FQNAFKKII-----KCKFCR--Q-------------------------------------
+------------------------------------------------------------
+------------------------------
+>    33=p A35181 serotonin receptor class 1A - rat
+MDVFSFG-----------------------------------------------------
+---------QGNNT------TASQEPFGTGGNVTSISDVTFSYQVI-----TSLLLGTLI
+FCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQVL-NKWT--
+LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLI
+GFLI-SIPPML-GWRTPEDRSDPD---ACTISKDH----------GYTIYSTFGAFYIPL
+LLMLVLYGRIFRAARFRIRKTVRKVEKKGAGTSLGTSSAPPPKK-----SLNG--QPGSG
+DWRRCAENRAVGTPCTNGAVRQGDDEATL--EVIEVHRVGNSKEHLPLPSESGSNSYAPA
+C------------------LERKNERNA-------------EAKRKMALARERKTVKTLG
+IIMGTFILCWLPFFIVALVLPF-CESSCH-MPALLGAIINWLGYSNSLLNPVIYAYFNKD
+FQNAFKKII-----KCKFCR--R-------------------------------------
+------------------------------------------------------------
+------------------------------
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDT------SATNM---TDDRYWSLTVYSHEHLVL-----TSVILGLFV
+LCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSEIS-KVWF--
+LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMIMVVWIV
+ALFI-SIPPLF-GWRDPNN--DPDKTGTCIISQDK----------GYTIFSTVGAFYLPM
+LVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVVSDCNGCNSPDST
+TEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQIQIETAEAFANG
+CAEEASIAMLERQCNNGKKISSNDTPYS-------------RTREKLELKRERKAARTLA
+IITGAFLICWLPFFIIALIGPF-VDPE-G-IPPFARSFVLWLGYFNSLLNPIIYTIFSPE
+FRSAFQKIL-----FGKYRRGHR-------------------------------------
+------------------------------------------------------------
+------------------------------
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDT------SATNM---TDDRYWSLTVYSHEHLVL-----TSVILGLFV
+LCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSEIS-KVWF--
+LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMIMVVWIV
+ALFI-SIPPLF-GWRDPNN--DPDKTGTCIISQDK----------GYTIFSTVGAFYLPM
+LVMMIIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVVSDCNGCNSPDST
+TEKKKRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQIQIETAEAFANG
+CAEEASIAMLERQCNNGKKISSNDTPYS-------------RTREKLELKRERKAARTLA
+IITGAFLICWLPFFIIALIGPF-VDPE-G-IPPFARSFVLWLGYFNSLLNPIIYTIFSPE
+FRSAFQKIL-----FGKYRRGHR-------------------------------------
+------------------------------------------------------------
+------------------------------
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+MEG-AEGQEELDWEAL--------------------------------------------
+YLRLPLQNCSWNSTGWEPNWNVTVV---PNTTWWQASAPFDTPAALVRAAAKAVVLGLLI
+LATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-MPLGAVYEVV-QRWT--
+LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIHASTAKRVGMMIACVWTV
+SFFV-CIAQLL-GWKDPDWNQRVSEDLRCVVSQDV----------GYQIFATASSFYVPV
+LIILILYWRIYQTARKRIRR------RRGATARGGVGPPPVPAG----------------
+-----------------GALVAGGGSGGIAAAVVAV-----IGRPLPTISETTTTGFTNV
+SSNNTSPE--KQSCANGLEADPPTTGYGAVAAAYYPSLVRRKPKEAADSKRERKAAKTLA
+IITGAFVACWLPFFVLAILVPT-CD--CE-VSPVLTSLSLWLGYFNSTLNPVIYTVFSPE
+FRHAFQRLL-----CGRRVRRRRA----------------------------------PQ
+------------------------------------------------------------
+------------------------------
diff --git a/binaries/src/mafft/test/sample.linsi b/binaries/src/mafft/test/sample.linsi
new file mode 100644 (file)
index 0000000..252c31f
--- /dev/null
@@ -0,0 +1,468 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+MN----------------------GTEGDNFYVPFSNKTGLA--RSPYEYPQY-------
+------------------YLAEPW-------------------KYSALAAYMFFLILVGF
+PVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-FTVTMYTSMN-GYFV--FGPT
+MCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGNF-RFGNTHAIMGVAFTWIMALAC
+-AAPPLV-GWS-----RYIPEGMQCSCGPDYYTLNPNFNNESYVVYMFVVHFLVPFVIIF
+FCYGRLLCTVKEAAAAQQESA---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEKEVTRMVVLMVI
+GFLVCWVPYASVAFYIFT--HQGSD-FGATFMTLPAFFAKSSALYNPVIYILMNKQFRNC
+MITTL-----CCGKNPLGDDESG--AS-TSKTEVS-------------------------
+------------------------------------------------------------
+-SVS-TSPVSPA---
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+MN----------------------GTEGPNFYVPFSNITGVV--RSPFEQPQY-------
+------------------YLAEPW-------------------QFSMLAAYMFLLIVLGF
+PINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-FTTTLYTSLH-GYFV--FGPT
+GCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSNF-RFGENHAIMGVAFTWVMALAC
+-AAPPLV-GWS-----RYIPEGMQCSCGIDYYTLKPEVNNESFVIYMFVVHFTIPMIVIF
+FCYGQLVFTVKEAAAQQQESA---------------------------------------
+------------------------------------------------------------
+------------------------------------------TTQKAEKEVTRMVIIMVI
+FFLICWLPYASVAMYIFT--HQGSN-FGPIFMTLPAFFAKTASIYNPIIYIMMNKQFRNC
+MLTSL-----CCGKNPLGDDEAS--AT-ASKTETS-------------------------
+------------------------------------------------------------
+-QVA-PA--------
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+MN----------------------GTEGINFYVPMSNKTGVV--RSPFEYPQY-------
+------------------YLAEPW-------------------KYRLVCCYIFFLISTGL
+PINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-FTVTFYTAWN-GYFV--FGPV
+GCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGNF-RFSATHAMMGIAFTWVMAFSC
+-AAPPLF-GWS-----RYMPEGMQCSCGPDYYTHNPDYHNESYVLYMFVIHFIIPVVVIF
+FSYGRLICKVREAAAQQQESA---------------------------------------
+------------------------------------------------------------
+------------------------------------------TTQKAEKEVTRMVILMVL
+GFMLAWTPYAVVAFWIFT--NKGAD-FTATLMAVPAFFSKSSSLYNPIIYVLMNKQFRNC
+MITTI-----CCGKNPFGDEDVSSTVS-QSKTEVS-------------------------
+------------------------------------------------------------
+-SVS-SSQVSPA---
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+MN----------------------GTEGKNFYVPMSNRTGLV--RSPFEYPQY-------
+------------------YLAEPW-------------------QFKILALYLFFLMSMGL
+PINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-FTVTFYTAIN-GYFV--LGPT
+GCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGSF-KFSSSHAFAGIAFTWVMALAC
+-AAPPLF-GWS-----RYIPEGMQCSCGPDYYTLNPDYNNESYVIYMFVCHFILPVAVIF
+FTYGRLVCTVKAAAAQQQDSA---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEREVTKMVILMVF
+GFLIAWTPYATVAAWIFF--NKGAD-FSAKFMAIPAFFSKSSALYNPVIYVLLNKQFRNC
+MLTTI-----FCGKNPLGDDESS-TVS-TSKTEVS-------------------------
+------------------------------------------------------------
+-SVS-PA--------
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+MN----------------------GTEGNNFYVPLSNRTGLV--RSPFEYPQY-------
+------------------YLAEPW-------------------QFKLLAVYMFFLICLGL
+PINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-FTVTFYTAIN-GYFA--LGPT
+GCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGSF-KFSSTHASAGIAFTWVMAMAC
+-AAPPLV-GWS-----RYIPEGIQCSCGPDYYTLNPEYNNESYVLYMFICHFILPVTIIF
+FTYGRLVCTVKAAAAQQQDSA---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEREVTKMVILMVL
+GFLVAWTPYATVAAWIFF--NKGAA-FSAQFMAIPAFFSKTSALYNPVIYVLLNKQFRSC
+MLTTL-----FCGKNPLGDEESS-TVS-TSKTEVS-------------------------
+------------------------------------------------------------
+-SVS-PA--------
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+MK--------------------QVPEFHEDFYIPIPLDINNLSAYSPFLVPQD-------
+------------------HLGNQG-------------------IFMAMSVFMFFIFIGGA
+SINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-SPLSFYSFFN-RYFI--FGAT
+ACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGNF-TFKTPHAIAGCILPWISALAA
+-SLPPLF-GWS-----RYIPEGLQCSCGPDWYTTNNKYNNESYVMFLFCFCFAVPFGTIV
+FCYGQLLITLKLAAKAQADSA---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEREVTKMVVVMVL
+GFLVCWAPYASFSLWIVS--HRGEE-FDLRMATIPSCLSKASTVYNPVIYVLMNKQFRSC
+MMKMV------CGKN-IEEDEAS--TS-SQVTQVS-------------------------
+------------------------------------------------------------
+-SVA-PEK-------
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+MR----------------------KMSEEEFYL-----FKNISSVGPWDGPQY-------
+------------------HIAPVW-------------------AFYLQAAFMGTVFLIGF
+PLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-VFPVFVASCN-GYFV--FGRH
+VCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGNF-RFSSKHALTVVLATWTIGIGV
+-SIPPFF-GWS-----RFIPEGLQCSCGPDWYTVGTKYRSESYTWFLFIFCFIVPLSLIC
+FSYTQLLRALKAVAAQQQESA---------------------------------------
+------------------------------------------------------------
+------------------------------------------TTQKAEREVSRMVVVMVG
+SFCVCYVPYAAFAMYMVN--NRNHG-LDLRLVTIPSFFSKSACIYNPIIYCFMNKQFQAC
+IMKMV------CGKA---MTDESDTCS-SQKTEVS-------------------------
+------------------------------------------------------------
+-TVS-STQVGPN---
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------DLAETVIA-STISIVNQVS-GYFV--LGHP
+MCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGNV-RFDAKLAIVGIAFSWIWAAVW
+-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCITPLSIIV
+LCYLQVWLAIRAVAKQQKESE---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEKEVTRMVVVMVL
+AFC---------------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+MAQQWSLQRLAGRHPQDS-YEDSTQ--SSIFTY-----TNSNSTRGPFEGPNY-------
+------------------HIAPRW-------------------VYHLTSVWMIFVVIASV
+FTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISVVNQVY-GYFV--LGHP
+MCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGNV-RFDAKLAIVGIAFSWIWAAVW
+-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCITPLSIIV
+LCYLQVWLAIRAVAKQQKESE---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEKEVTRMVVVMVL
+AFCFCWGPYAFFACFAAA--NPGYP-FHPLMAALPAFFAKSATIYNPVIYVFMNRQFRNC
+ILQLF----------GKKVDDGSELSS-ASKTEVS-------------------------
+------------------------------------------------------------
+-SVS---SVSPA---
+>    10== Z68193   1 human Red Opsin <>[]
+MAQQWSLQRLAGRHPQDS-YEDSTQ--SSIFTY-----TNSNSTRGPFEGPNY-------
+------------------HIAPRW-------------------VYHLTSVWMIFVVTASV
+FTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-STISIVNQVS-GYFV--LGHP
+MCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGNV-RFDAKLAIVGIAFSWIWSAVW
+-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSYPGVQSYMIVLMVTCCIIPLAIIM
+LCYLQVWLAIRAVAKQQKESE---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEKEVTRMVVVMIF
+AYCVCWGPYTFFACFAAA--NPGYA-FHPLMAALPAYFAKSATIYNPVIYVFMNRQFRNC
+ILQLF----------GKKVDDGSELSS-ASKTEVS-------------------------
+------------------------------------------------------------
+-SVS---SVSPA---
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+MTEAWNVAVFAARRSRDD--DDTTR--GSVFTY-----TNTNNTRGPFEGPNY-------
+------------------HIAPRW-------------------VYNLVSFFMIIVVIASC
+FTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-STISVFNQIF-GYFI--LGHP
+LCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGNI-KFDSKLAIIGIVFSWVWAWGW
+-SAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSVELGCQSFMLTLMITCCFLPLFIII
+VCYLQVWMAIRAVAAQQKESE---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEREVSRMVVVMIV
+AFCICWGPYASFVSFAAA--NPGYA-FHPLAAALPAYFAKSATIYNPVIYVFMNRQFRNC
+IMQLF----------GKKVDDGSEAST-TSRTEVS-------------------------
+------------------------------------------------------------
+-SVS-NSSVAPA---
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+MA-AWE-AAFAARRRHEE--EDTTR--DSVFTY-----TNSNNTRGPFEGPNY-------
+------------------HIAPRW-------------------VYNLTSVWMIFVVAASV
+FTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-STISVINQIS-GYFI--LGHP
+MCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGNI-KFDGKLAVAGILFSWLWSCAW
+-TAPPIF-GWS-----RYWPHGLKTSCGPDVFSGSSDPGVQSYMVVLMVTCCFFPLAIII
+LCYLQVWLAIRAVAAQQKESE---------------------------------------
+------------------------------------------------------------
+------------------------------------------STQKAEKEVSRMVVVMIV
+AYCFCWGPYTFFACFAAA--NPGYA-FHPLAAALPAYFAKSATIYNPIIYVFMNRQFRNC
+ILQLF----------GKKVDDGSEVST--SRTEVS-------------------------
+------------------------------------------------------------
+-SVS-NSSVSPA---
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+MS-------------------------------SNSSQAPPNGTPGPFDGPQWP------
+------------------YQAPQS-------------------TYVGVAVLMGTVVACAS
+VVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-SSVSLSNNIN-GFFV--FGRR
+MCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGDF-QFQRRHAVSGCAFTWGWALLW
+-SAPPLL-GWS-----SYVPEGLRTSCGPNWYTGGS--NNNSYILSLFVTCFVLPLSLIL
+FSYTNLLLTLRAAAAQQKEAD---------------------------------------
+------------------------------------------------------------
+------------------------------------------TTQRAEREVTRMVIVMVM
+AFLLCWLPYSTFALVVAT--HKGII-IQPVLASLPSYFSKTATVYNPIIYVFMNKQFQSC
+LLEML-----CCGYQPQRTGKASPGTP-GPHADVT-------------------------
+------------------------------------------------------------
+-AAGLRNKVMPAHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+MESGNVSSSLFGNVSTALRPEARLSAE----------TRLLGWNVPPEELR---------
+------------------HIPEHWLTYP----------EPPESMNYLLGTLYIFFTLMSM
+LGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--TPIFIYNSFH-QGYA--LGHL
+GCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--KMTHGKAIAMIIFIYMYATPW
+-VVACYTETWG-----RFVPEGYLTSCTFDYLTDN--FDTRLFVACIFFFSFVCPTTMIT
+YYYSQIVGHVFSHEKALRDQAKKMNVESLR------------------------------
+------------------------------------------------------------
+-------------------------------------SNVDKNKETAEIRIAKAAITICF
+LFFCSWTPYGVMSLIGAF--GDKTL-LTPGATMIPACACKMVACIDPFVYAISHPRYRME
+LQKRCPWL--ALNEKAPESSAVASTST-TQEPQQT-------------------------
+------------------------------------------------------------
+-TAA-----------
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+MEYHNVSSVL-GNVSSVLRPDARLSAE----------SRLLGWNVPPDELR---------
+------------------HIPEHWLIYP----------EPPESMNYLLGTLYIFFTVISM
+IGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--TPIFIYNSFH-QGYA--LGHL
+GCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--KMTHGKAIAMIIFIYLYATPW
+-VVACYTESWG-----RFVPEGYLTSCTFDYLTDN--FDTRLFVACIFFFSFVCPTTMIT
+YYYSQIVGHVFSHEKALRDQAKKMNVDSLR------------------------------
+------------------------------------------------------------
+-------------------------------------SNVDKSKEAAEIRIAKAAITICF
+LFFASWTPYGVMSLIGAF--GDKTL-LTPGATMIPACTCKMVACIDPFVYAISHPRYRME
+LQKRCPWL--AISEKAPESRAAISTST-TQEQQQT-------------------------
+------------------------------------------------------------
+-TAA-----------
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+ME------PLCNASEPPLRPEAR-SSGNGD-------LQFLGWNVPPDQIQ---------
+------------------YIPEHWLTQL----------EPPASMHYMLGVFYIFLFCAST
+VGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIF--NSFH-RGFAIYLGNT
+WCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMNIIIWLYCTPW
+-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--FDTRLFVGTIFFFSFVCPTLMIL
+YYYSQIVGHVFSHEKALREQAKKMNVESLR------------------------------
+------------------------------------------------------------
+-------------------------------------SNVDKSKETAEIRIAKAAITICF
+LFFVSWTPYGVMSLIGAF--GDKSL-LTQGATMIPACTCKLVACIDPFVYAISHPRYRLE
+LQKRCPWL--GVNEKSGEISSAQSTTT-QEQQQTT-------------------------
+------------------------------------------------------------
+-AA------------
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+MD------ALCNASEPPLRPEARMSSGSDE-------LQFLGWNVPPDQIQ---------
+------------------YIPEHWLTQL----------EPPASMHYMLGVFYIFLFFAST
+LGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--APIFIYNSFH-RGFA--LGNT
+WCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--NMTFTKAVIMNIIIWLYCTPW
+-VVLPLTQFWD-----RFVPEGYLTSCSFDYLSDN--FDTRLFVGTIFLFSFVVPTLMIL
+YYYSQIVGHVFNHEKALREQAKKMNVESLR------------------------------
+------------------------------------------------------------
+-------------------------------------SNVDKSKETAEIRIAKAAITICF
+LFFVSWTPYGVMSLIGAF--GDKSL-LTPGATMIPACTCKLVACIEPFVYAISHPRYRME
+LQKRCPWL--GVNEKSGEASSAQSTTT-QEQTQQT-------------------------
+------------------------------------------------------------
+-SAA-----------
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+M-----------TNATGPQMAYYGAASMDFGYPE---GVSIVDFVRPEIKP---------
+------------------YVHQHWYNYP----------PVNPMWHYLLGVIYLFLGTVSI
+FGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-VPFFTYNCFSGGVWM--FSPQ
+YCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNGP-KLTTGKAVVFALISWVIAIGC
+-ALPPFF-GWG-----NYILEGILDSCSYDYLTQD--FNTFSYNIFIFVFDYFLPAAIIV
+FSYVFIVKAIFAHEAAMRAQAKKMNVSTLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-NEADAQRAEIRIAKTALVNVS
+LWFICWTPYALISLKGVM--GDTSG-ITPLVSTLPALLAKSCSCYNPFVYAISHPKYRLA
+ITQHLPWF--CVHETETKSNDDSQSNS-TVAQDKA-------------------------
+------------------------------------------------------------
+---------------
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+M-----------ANVTGPQMAFYGSGAATFGYPE---GMTVADFVPDRVKH---------
+------------------MVLDHWYNYP----------PVNPMWHYLLGVVYLFLGVISI
+AGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-FPPFCYNCFSGGRWM--FSGT
+YCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNGP-KLTQGKATFMCGLAWVISVGW
+-SLPPFF-GWG-----SYTLEGILDSCSYDYFTRD--MNTITYNICIFIFDFFLPASVIV
+FSYVFIVKAIFAHEAAMRAQAKKMNVTNLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-NEAETQRAEIRIAKTALVNVS
+LWFICWTPYAAITIQGLL--GNAEG-ITPLLTTLPALLAKSCSCYNPFVYAISHPKFRLA
+ITQHLPWF--CVHEKDPNDVEENQSSN-TQTQEKS-------------------------
+------------------------------------------------------------
+---------------
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+ME-----SFAVAAAQLGPHFAPLS-------------NGSVVDKVTPDMAH---------
+------------------LISPYWNQFP----------AMDPIWAKILTAYMIMIGMISW
+CGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--LGPM
+MCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKM----------
+-----------------YVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPLFLIC
+YSYWFIIAAVSAHEKAMREQAKKMNVKSLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SEDAEKSAEGKLAKVALVTIT
+LWFMAWTPYLVINCMGLF---KFEG-LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLA
+LKEKCPCC--VFGKVDDGKSSDAQSQA-TASEAESKA-----------------------
+------------------------------------------------------------
+---------------
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+ME-----SFAVAAAQLGPHFAPLS-------------NGSVVDKVTPDMAH---------
+------------------LISPYWNQFP----------AMDPIWAKILTAYMIMIGMISW
+CGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--LGPM
+MCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKIAYIWFMSSIW
+-CLAPAF-GWS-----RYVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPLFLIC
+YSYWFIIAAVSAHEKAMREQAKKMNVKSLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SEDAEKSAEGKLAKVALVTIT
+LWFMAWTPYLVINCMGLF---KFEG-LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLA
+LKEKCPCC--VFGKVDDGKSSDAQSQA-TASEAESKA-----------------------
+------------------------------------------------------------
+---------------
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+MD-----SFAAVATQLGPQFAAPS-------------NGSVVDKVTPDMAH---------
+------------------LISPYWDQFP----------AMDPIWAKILTAYMIIIGMISW
+CGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-TPMMGINLYF-ETWV--LGPM
+MCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAGR-PMTIPLALGKIAYIWFMSTIW
+CCLAPVF-GWS-----RYVPEGNLTSCGIDYLERD--WNPRSYLIFYSIFVYYIPLFLIC
+YSYWFIIAAVSAHEKAMREQAKKMNVKSLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SEDADKSAEGKLAKVALVTIS
+LWFMAWTPYLVINCMGLF---KFEG-LTPLNTIWGACFAKSAACYNPIVYGISHPKYRLA
+LKEKCPCC--VFGKVDDGKSSEAQSQA-TTSEAESKA-----------------------
+------------------------------------------------------------
+---------------
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+MERSHLPETPFDLAHSGPRFQAQSSG-----------NGSVLDNVLPDMAH---------
+------------------LVNPYWSRFA----------PMDPMMSKILGLFTLAIMIISC
+CGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINFYY-ETWV--LGPL
+WCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGINGT-PMTIKTSIMKILFIWMMAVFW
+-TVMPLI-GWS-----AYVPEGNLTACSIDYMTRM--WNPRSYLITYSLFVYYTPLFLIC
+YSYWFIIAAVAAHEKAMREQAKKMNVKSLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SEDCDKSAEGKLAKVALTTIS
+LWFMAWTPYLVICYFGLF---KIDG-LTPLTTIWGATFAKTSAVYNPIVYGISHPKYRIV
+LKEKCPMC--VFGNTDEPKPDAPASDTETTSEADSKA-----------------------
+------------------------------------------------------------
+---------------
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+MERSLLPEPPLAMALLGPRFEAQTGG-----------NRSVLDNVLPDMAP---------
+------------------LVNPHWSRFA----------PMDPTMSKILGLFTLVILIISC
+CGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-SPVMIINFYY-ETWV--LGPL
+WCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGINGT-PMTIKTSIMKIAFIWMMAVFW
+-TIMPLI-GWS-----SYVPEGNLTACSIDYMTRQ--WNPRSYLITYSLFVYYTPLFMIC
+YSYWFIIATVAAHEKAMRDQAKKMNVKSLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SEDCDKSAENKLAKVALTTIS
+LWFMAWTPYLIICYFGLF---KIDG-LTPLTTIWGATFAKTSAVYNPIVYGISHPNDRLV
+LKEKCPMC--VCGTTDEPKPDAPPSDTETTSEAESKD-----------------------
+------------------------------------------------------------
+---------------
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+M-----------IAVSGPSYEAFSYGGQARFN-----NQTVVDKVPPDMLH---------
+------------------LIDANWYQYP----------PLNPMWHGILGFVIGMLGFVSA
+MGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-SPPMVINCYY-ETWV--LGPL
+FCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSGK-PLSINGALIRIIAIWLFSLGW
+-TIAPMF-GWN-----RYVPEGNMTACGTDYFNRG--LLSASYLVCYGIWVYFVPLFLII
+YSYWFIIQAVAAHEKNMREQAKKMNVASLR------------------------------
+------------------------------------------------------------
+-------------------------------------S-SENQNTSAECKLAKVALMTIS
+LWFMAWTPYLVINFSGIF---NLVK-ISPLFTIWGSLFAKANAVYNPIVYGISHPKYRAA
+LFAKFPSL--ACAA-EPSSDAVSTTSG-TTTVTDNEKSNA--------------------
+------------------------------------------------------------
+---------------
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+M------ANQLSYSSLGWPYQP---------------NASVVDTMPKEMLY---------
+------------------MIHEHWYAFP----------PMNPLWYSILGVAMIILGIICV
+LGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-MPTMTSNCFA-ETWI--LGPF
+MCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAAA-PLTHKKATLLLLFVWIWSGGW
+-TILPFF-GWS-----RYVPEGNLTSCTVDYLTKD--WSSASYVVIYGLAVYFLPLITMI
+YCYFFIVHAVAEHEKQLREQAKKMNVASLR------------------------------
+------------------------------------------------------------
+-------------------------------------ANADQQKQSAECRLAKVAMMTVG
+LWFMAWTPYLIISWAGVF--SSGTR-LTPLATIWGSVFAKANSCYNPIVYGISHPRYKAA
+LYQRFPSL--ACGSGESGSDVKSEASA-TTTMEEKPKIPEA-------------------
+------------------------------------------------------------
+---------------
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+M-------------------------------VESTTLVNQTWWYNPTV-----------
+------------------DIHPHWAKFD----------PIPDAVYYSVGIFIGVVGIIGI
+LGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGFPLKTISAFM-KKWI--FGKV
+ACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASKKMSHRRAFLMIIFVWMWSIVW
+-SVGPVF-NWG-----AYVPEGILTSCSFDYLSTD--PSTRSFILCMYFCGFMLPIIIIA
+FCYFNIVMSVSNHEKEMAAMAKRLNAKELR------------------------------
+------------------------------------------------------------
+---------------------------------------KAQAGASAEMKLAKISMVIIT
+QFMLSWSPYAIIALLAQF--GPAEW-VTPYAAELPVLFAKASAIHNPIVYSVSHPKFREA
+IQTTFPWLLTCCQFDEKECEDANDAEE-EVVASER--GGESRDAAQMKEMMAMMQKMQAQ
+QAAYQP---PPPPQGYPPQGYPPQGAYPPPQGYPPQGYPPQGYPPQGYPPQGAPPQVEAP
+QGAPPQGVDNQAYQA
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+M--------------------------------GRDLRDNETWWYNPSI-----------
+------------------VVHPHWREFD----------QVPDAVYYSLGIFIGICGIIGC
+GGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGFPLMTISCFL-KKWI--FGFA
+ACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASKKMSHRRAFIMIIFVWLWSVLW
+-AIGPIF-GWG-----AYTLEGVLCNCSFDYISRD--STTRSNILCMFILGFFGPILIIF
+FCYFNIVMSVSNHEKEMAAMAKRLNAKELR------------------------------
+------------------------------------------------------------
+---------------------------------------KAQAGANAEMRLAKISIVIVS
+QFLLSWSPYAVVALLAQF--GPLEW-VTPYAAQLPVMFAKASAIHNPMIYSVSHPKFREA
+ISQTFPWVLTCCQFDDKETEDDKDAET-EIPAGESSDAAPSADAAQMKEMMAMMQKMQQQ
+QAAYPPQGYAPPPQGYPPQGYPPQGY--PPQGYPPQGYPP---PPQGAPPQGAPP-----
+-AAPPQGVDNQAYQA
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDLYGHLRSFLLPEVGRGLPDLSPDGGADPVAGSWAPHLLS---EVTA---
+------------------SPAPTWDAPPDNASGCGEQINYGRVEKVVIGSILTLITLLTI
+AGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--FGHF
+FCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLLSASI
+-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPMSVML
+FMYYQIYKAARKSAAKHKFP--------------GFPRVEPDSVIALNGIVKLQKEVEE-
+------------------------------------------------------------
+---------------------------CANLSRLLKHERKNISIFKREQKAATTLGIIVG
+AFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTFLWLGYANSLINPFIYAFFNRDLRTT
+YRSLL-----QCQYRNINRKLSAAGMH-EALKLAERPERPEFVLQNADYCRKKGHDS---
+------------------------------------------------------------
+---------------
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+M--------------------------------------------PHLLSGFLEVTA---
+------------------SPAPTWDAPPDNVSGCGEQINYGRVEKVVIGSILTLITLLTI
+AGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--FGHF
+FCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLLSASI
+-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPMSVML
+FMYYQIYKAARKSAAKHKFP--------------GFPRVQPESVISLNGVVKLQKEVEE-
+------------------------------------------------------------
+---------------------------CANLSRLLKHERKNISIFKREQKAATTLGIIVG
+AFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRPT
+SRSLL-----QCQYRNINRKLSAAGMH-EALKLAERPERSEFVLQNSDHCGKKGHDT---
+------------------------------------------------------------
+---------------
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+M--------------------------------------------PHLLSGFLEVTA---
+------------------SPAPTWDAPPDNVSGCGEQINYGRVEKVVIGSILTLITLLTI
+AGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-MPFVSVTDLIGGKWI--FGHF
+FCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPVRQNGKCMAKMILSVWLLSASI
+-TLPPLF-GWA-----QNVNDDKVCLISQDF----------GYTIYSTAVAFYIPMSVML
+FMYYQIYKAARKSAAKHKFP--------------GFPRVQPESVISLNGVVKLQKEVEE-
+------------------------------------------------------------
+---------------------------CANLSRLLKHERKNISIFKREQKAATTLGIIVG
+AFTVCWLPFFLLSTARPFICGTSCSCIPLWVERTCLWLGYANSLINPFIYAFFNRDLRTT
+YRSLL-----QCQYRNINRKLSAAGMH-EALKLAERPERSEFVLQNSDHCGKKGHDT---
+------------------------------------------------------------
+---------------
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+MDVLSPGQGNNTTSPPAPF-----------------------------------------
+------------------ETGGNTTGIS----------DVTVSYQVITSLLLGTLIFCAV
+LGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQVL-NKWT--LGQV
+TCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLIGFLI
+-SIPPML-GWRTP---EDRSDPDACTISKDH----------GYTIYSTFGAFYIPLLLML
+VLYGRIFRAARFRIRKTVKKVEKTGADTRHGASPAPQPKKS---------VNGESGSRNW
+RLGVESKAGGALCANGAVRQGDDGAALEVIEVHRVGNSKEHLPLPSEAGPTPCAPASFER
+KNERNA-------------------------------EAKRKMALARERKTVKTLGIIMG
+TFILCWLPFFIVALVLPF-CESSCH-MPTLLGAIINWLGYSNSLLNPVIYAYFNKDFQNA
+FKKII-----KCKFCRQ-------------------------------------------
+------------------------------------------------------------
+---------------
+>    33=p A35181 serotonin receptor class 1A - rat
+MDVFSFGQGNNTTASQEPF-----------------------------------------
+------------------GTGGNVTSIS----------DVTFSYQVITSLLLGTLIFCAV
+LGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-LPMAALYQVL-NKWT--LGQV
+TCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVNKRTPRRAAALISLTWLIGFLI
+-SIPPML-GWRTP---EDRSDPDACTISKDH----------GYTIYSTFGAFYIPLLLML
+VLYGRIFRAARFRIRKTVRKVEKKGAGTSLGTSSAPPPKKS---------LNGQPGSGDW
+RRCAENRAVGTPCTNGAVRQGDDEATLEVIEVHRVGNSKEHLPLPSESGSNSYAPACLER
+KNERNA-------------------------------EAKRKMALARERKTVKTLGIIMG
+TFILCWLPFFIVALVLPF-CESSCH-MPALLGAIINWLGYSNSLLNPVIYAYFNKDFQNA
+FKKII-----KCKFCRR-------------------------------------------
+------------------------------------------------------------
+---------------
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDTSATNMTDDRYWSLT----------VYSHEHLVLTSVILGLFVLCCI
+IGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSEIS-KVWF--LHSE
+VCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMIMVVWIVALFI
+-SIPPLF-GWRDP--NNDPDKTGTCIISQDK----------GYTIFSTVGAFYLPMLVMM
+IIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVVSDCNGCNSPDSTTEKK
+KRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQIQIETAEAFANGCAEE
+ASIAMLERQCNNGKKISSNDTPYS-------------RTREKLELKRERKAARTLAIITG
+AFLICWLPFFIIALIGPF--VDPEG-IPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSA
+FQKIL-----FGKYRRGHR-----------------------------------------
+------------------------------------------------------------
+---------------
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+MANFTFGDLALDVARMGGLASTPSGLRSTGLTTPGLSPTGLVTSDFNDSYGLTGQFINGS
+HSSRSRDNASANDTSATNMTDDRYWSLT----------VYSHEHLVLTSVILGLFVLCCI
+IGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-MPLSVVSEIS-KVWF--LHSE
+VCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIRRRSARRILLMIMVVWIVALFI
+-SIPPLF-GWRDP--NNDPDKTGTCIISQDK----------GYTIFSTVGAFYLPMLVMM
+IIYIRIWLVARSRIRKDKFQMTKARLKTEETTLVASPKTEYSVVSDCNGCNSPDSTTEKK
+KRRAPFKSYGCSPRPERKKNRAKKLPENANGVNSNSSSSERLKQIQIETAEAFANGCAEE
+ASIAMLERQCNNGKKISSNDTPYS-------------RTREKLELKRERKAARTLAIITG
+AFLICWLPFFIIALIGPF--VDPEG-IPPFARSFVLWLGYFNSLLNPIIYTIFSPEFRSA
+FQKIL-----FGKYRRGHR-----------------------------------------
+------------------------------------------------------------
+---------------
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+MEGAEGQEELDWEALYLRLPLQNCSWNSTGWEPNWNVTV---------------------
+------------------VPNTTWWQASAPF-----DTPAALVRAAAKAVVLGLLILATV
+VGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-MPLGAVYEVV-QRWT--LGPE
+LCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIHASTAKRVGMMIACVWTVSFFV
+-CIAQLL-GWKDPDWNQRVSEDLRCVVSQDV----------GYQIFATASSFYVPVLIIL
+ILYWRIYQTARKRIRRRRGATARGGV--------GPPPVPAGGALVAGGGSGG-------
+-----------------------------IAAAVVAVIGRPLPTISETTTTGFTNVSSNN
+TSPE--KQSCANGLEADPPTTGYGAVAAAYYPSLVRRKPKEAADSKRERKAAKTLAIITG
+AFVACWLPFFVLAILVPT---CDCE-VSPVLTSLSLWLGYFNSTLNPVIYTVFSPEFRHA
+FQRLL-----CGRRVRRRRAPQ--------------------------------------
+------------------------------------------------------------
+---------------
diff --git a/binaries/src/mafft/test/sample.parttree b/binaries/src/mafft/test/sample.parttree
new file mode 100644 (file)
index 0000000..e82ff0e
--- /dev/null
@@ -0,0 +1,540 @@
+>     1== M63632   1 Lampetra japonica rhodopsin <>[BBRC174,1125-1132'91]
+M-----------------------------------------------------------
+------------------------------NGTE--GDNFYV----PF------------
+--------------------------SNKTGLARSPYEYPQY-YLA-----EPWK-----
+----YSALAAYMFFLILVGFPVNFLTLFVTVQHKKLRTPLNYILLNLAMANLFMVLFG-F
+TVTMYTS-MN-GYFV--FGPTMCSIEGFFATLGGEVALWSLVVLAIERYIVICKPMGN-F
+RFGNTHAIMGVAFTWIMALAC-AAPPLVG-W-----SRYIPEGMQCSCGPDYYTLNPNFN
+NESYVVYMFVVHFLVPFVIIFFCYGRLLCTV----KEAAAAQQE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SASTQKAEKEVTRMV
+VLMVIGFLVCWVPYASVAFYIFT-HQG-S--DFGATFMTLPAFFAKSSALYNPVIYILMN
+KQFRNCMITTLC-C---GKNP------------------------------LGDDE--SG
+ASTSKT-E--VSSVS-TSPV----------------------------------------
+---------------------------------------------SP-A---
+>     2== U22180   1 rat opsin <rod>[J.Mol.Neurosci.5(3),207-209'94]
+M-----------------------------------------------------------
+------------------------------NGTE--GPNFYV----PF------------
+--------------------------SNITGVVRSPFEQPQY-YLA-----EPWQ-----
+----FSMLAAYMFLLIVLGFPINFLTLYVTVQHKKLRTPLNYILLNLAVADLFMVFGG-F
+TTTLYTS-LH-GYFV--FGPTGCNLEGFFATLGGEIGLWSLVVLAIERYVVVCKPMSN-F
+RFGENHAIMGVAFTWVMALAC-AAPPLVG-W-----SRYIPEGMQCSCGIDYYTLKPEVN
+NESFVIYMFVVHFTIPMIVIFFCYGQLVFTV----KEAAAQQQE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SATTQKAEKEVTRMV
+IIMVIFFLICWLPYASVAMYIFT-HQG-S--NFGPIFMTLPAFFAKTASIYNPIIYIMMN
+KQFRNCMLTSLC-C---GKNP------------------------------LGDDE--AS
+ATASKT-E--------TSQV----------------------------------------
+---------------------------------------------AP-A---
+>     3== M92038   1 chicken green sensitive cone opsin <retina>[PNAS89,5932-5936'9
+M-----------------------------------------------------------
+------------------------------NGTE--GINFYV----PM------------
+--------------------------SNKTGVVRSPFEYPQY-YLA-----EPWK-----
+----YRLVCCYIFFLISTGLPINLLTLLVTFKHKKLRQPLNYILVNLAVADLFMACFG-F
+TVTFYTA-WN-GYFV--FGPVGCAVEGFFATLGGQVALWSLVVLAIERYIVVCKPMGN-F
+RFSATHAMMGIAFTWVMAFSC-AAPPLFG-W-----SRYMPEGMQCSCGPDYYTHNPDYH
+NESYVLYMFVIHFIIPVVVIFFSYGRLICKV----REAAAQQQE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SATTQKAEKEVTRMV
+ILMVLGFMLAWTPYAVVAFWIFT-NKG-A--DFTATLMAVPAFFSKSSSLYNPIIYVLMN
+KQFRNCMITTIC-C---GKNP------------------------------FGDEDVSST
+VSQSKT-E--VSSVS-SSQV----------------------------------------
+---------------------------------------------SP-A---
+>     4=p A45229 opsin, green-sensitive (clone GFgr-1) - goldfish
+M-----------------------------------------------------------
+------------------------------NGTE--GKNFYV----PM------------
+--------------------------SNRTGLVRSPFEYPQY-YLA-----EPWQ-----
+----FKILALYLFFLMSMGLPINGLTLVVTAQHKKLRQPLNFILVNLAVAGTIMVCFG-F
+TVTFYTA-IN-GYFV--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-F
+KFSSSHAFAGIAFTWVMALAC-AAPPLFG-W-----SRYIPEGMQCSCGPDYYTLNPDYN
+NESYVIYMFVCHFILPVAVIFFTYGRLVCTV----KAAAAQQQD----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SASTQKAEREVTKMV
+ILMVFGFLIAWTPYATVAAWIFF-NKG-A--DFSAKFMAIPAFFSKSSALYNPVIYVLLN
+KQFRNCMLTTIF-C---GKNP------------------------------LGDDE-SST
+VSTSKT-E--VSS------V----------------------------------------
+---------------------------------------------SP-A---
+>     5=p B45229 opsin, green-sensitive (clone GFgr-2) - goldfish
+M-----------------------------------------------------------
+------------------------------NGTE--GNNFYV----PL------------
+--------------------------SNRTGLVRSPFEYPQY-YLA-----EPWQ-----
+----FKLLAVYMFFLICLGLPINGLTLICTAQHKKLRQPLNFILVNLAVAGAIMVCFG-F
+TVTFYTA-IN-GYFA--LGPTGCAVEGFMATLGGEVALWSLVVLAIERYIVVCKPMGS-F
+KFSSTHASAGIAFTWVMAMAC-AAPPLVG-W-----SRYIPEGIQCSCGPDYYTLNPEYN
+NESYVLYMFICHFILPVTIIFFTYGRLVCTV----KAAAAQQQD----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SASTQKAEREVTKMV
+ILMVLGFLVAWTPYATVAAWIFF-NKG-A--AFSAQFMAIPAFFSKTSALYNPVIYVLLN
+KQFRSCMLTTLF-C---GKNP------------------------------LGDEE-SST
+VSTSKT-E--VSS------V----------------------------------------
+---------------------------------------------SP-A---
+>     6== L11864   1 Carassius auratus blue cone opsin <retina>[Biochemistry32,208-
+M-----------------------------------------------------------
+------------------------------KQVPEFHEDFYI----PIPL----------
+------------------------DINNLS--AYSPFLVPQD-HLG-----NQGI-----
+----FMAMSVFMFFIFIGGASINILTILCTIQFKKLRSHLNYILVNLSIANLFVAIFG-S
+PLSFYSF-FN-RYFI--FGATACKIEGFLATLGGMVGLWSLAVVAFERWLVICKPLGN-F
+TFKTPHAIAGCILPWISALAA-SLPPLFG-W-----SRYIPEGLQCSCGPDWYTTNNKYN
+NESYVMFLFCFCFAVPFGTIVFCYGQLLITL----KLAAKAQAD----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SASTQKAEREVTKMV
+VVMVLGFLVCWAPYASFSLWIVS-HRG-E--EFDLRMATIPSCLSKASTVYNPVIYVLMN
+KQFRSCMM-KMV-C---GKN-------------------------------IEEDE--AS
+TSSQVT-Q--VSS------V----------------------------------------
+---------------------------------------------APEK---
+>     7== M13299   1 human BCP <>[Science232(4747),193-202'86]
+M-----------------------------------------------------------
+------------------------------RKMS--EEEFYL-------F----------
+--------------------------KNISSV--GPWDGPQY-HIA-----PVWA-----
+----FYLQAAFMGTVFLIGFPLNAMVLVATLRYKKLRQPLNYILVNVSFGGFLLCIFS-V
+FPVFVAS-CN-GYFV--FGRHVCALEGFLGTVAGLVTGWSLAFLAFERYIVICKPFGN-F
+RFSSKHALTVVLATWTIGIGV-SIPPFFG-W-----SRFIPEGLQCSCGPDWYTVGTKYR
+SESYTWFLFIFCFIVPLSLICFSYTQLLRAL----KAVAAQQQE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SATTQKAEREVSRMV
+VVMVGSFCVCYVPYAAFAMYMVN-NRN-H--GLDLRLVTIPSFFSKSACIYNPIIYCFMN
+KQFQACIM-KMV-C---GKA-------------------------------MTDES--DT
+CSSQKT-E--VSTVS-STQV----------------------------------------
+---------------------------------------------GP-N---
+>     8=opsin, greensensitive  human (fragment) S07060
+------------------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+--------------------------------------------------DLAETVIA-S
+TISIVNQ-VS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-V
+RFDAKLAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPG
+VQSYMIVLMVTCCITPLSIIVLCYLQVWLAI----RAVAKQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SESTQKAEKEVTRMV
+VVMVLAFC----------------------------------------------------
+------------------------------------------------------------
+------------------------------------------------------------
+----------------------------------------------------
+>     9== K03494   1 human GCP <>[Science232(4747),193-202'86]
+M-------------AQQWSLQRLA--GRHPQDSYE-------------------------
+------------------------------DSTQ--SSIFTY----TN------------
+--------------------------SNST---RGPFEGPNY-HIA-----PRWV-----
+----YHLTSVWMIFVVIASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-S
+TISVVNQ-VY-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWMVVCKPFGN-V
+RFDAKLAIVGIAFSWIWAAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPG
+VQSYMIVLMVTCCITPLSIIVLCYLQVWLAI----RAVAKQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SESTQKAEKEVTRMV
+VVMVLAFCFCWGPYAFFACFAAA-NPG-Y--PFHPLMAALPAFFAKSATIYNPVIYVFMN
+RQFRNCIL-QLF-----GKK-------------------------------VDDGS--EL
+SSASKT-E--VSSV---SSV----------------------------------------
+---------------------------------------------SP-A---
+>    10== Z68193   1 human Red Opsin <>[]
+M-------------AQQWSLQRLA--GRHPQDSYE-------------------------
+------------------------------DSTQ--SSIFTY----TN------------
+--------------------------SNST---RGPFEGPNY-HIA-----PRWV-----
+----YHLTSVWMIFVVTASVFTNGLVLAATMKFKKLRHPLNWILVNLAVADLAETVIA-S
+TISIVNQ-VS-GYFV--LGHPMCVLEGYTVSLCGITGLWSLAIISWERWLVVCKPFGN-V
+RFDAKLAIVGIAFSWIWSAVW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSYPG
+VQSYMIVLMVTCCIIPLAIIMLCYLQVWLAI----RAVAKQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SESTQKAEKEVTRMV
+VVMIFAYCVCWGPYTFFACFAAA-NPG-Y--AFHPLMAALPAYFAKSATIYNPVIYVFMN
+RQFRNCIL-QLF-----GKK-------------------------------VDDGS--EL
+SSASKT-E--VSSV---SSV----------------------------------------
+---------------------------------------------SP-A---
+>    11== M92036   1 Gecko gecko P521 <retina>[PNAS89,6841-6845'92]
+M-------------TEAWNVAVFA--ARRSRDD-D-------------------------
+------------------------------DTTR--GSVFTY----TN------------
+--------------------------TNNT---RGPFEGPNY-HIA-----PRWV-----
+----YNLVSFFMIIVVIASCFTNGLVLVATAKFKKLRHPLNWILVNLAFVDLVETLVA-S
+TISVFNQ-IF-GYFI--LGHPLCVIEGYVVSSCGITGLWSLAIISWERWFVVCKPFGN-I
+KFDSKLAIIGIVFSWVWAWGW-SAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSVELG
+CQSFMLTLMITCCFLPLFIIIVCYLQVWMAI----RAVAAQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SESTQKAEREVSRMV
+VVMIVAFCICWGPYASFVSFAAA-NPG-Y--AFHPLAAALPAYFAKSATIYNPVIYVFMN
+RQFRNCIM-QLF-----GKK-------------------------------VDDGS--EA
+STTSRT-E--VSSVS-NSSV----------------------------------------
+---------------------------------------------AP-A---
+>    12== M62903   1 chicken visual pigment <>[BBRC173,1212-1217'90]
+M-------------AA-WEAAFAA--RRRHEE--E-------------------------
+------------------------------DTTR--DSVFTY----TN------------
+--------------------------SNNT---RGPFEGPNY-HIA-----PRWV-----
+----YNLTSVWMIFVVAASVFTNGLVLVATWKFKKLRHPLNWILVNLAVADLGETVIA-S
+TISVINQ-IS-GYFI--LGHPMCVVEGYTVSACGITALWSLAIISWERWFVVCKPFGN-I
+KFDGKLAVAGILFSWLWSCAW-TAPPIFG-W-----SRYWPHGLKTSCGPDVFSGSSDPG
+VQSYMVVLMVTCCFFPLAIIILCYLQVWLAI----RAVAAQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------SESTQKAEKEVSRMV
+VVMIVAYCFCWGPYTFFACFAAA-NPG-Y--AFHPLAAALPAYFAKSATIYNPIIYVFMN
+RQFRNCIL-QLF-----GKK-------------------------------VDDGS--EV
+ST-SRT-E--VSSVS-NSSV----------------------------------------
+---------------------------------------------SP-A---
+>    13== S75720   1 chicken P-opsin <>[Science267(5203),1502-1506'95]
+M-------------S-------------------S-------------------------
+------------------------------NSSQ--AP----------------------
+--------------------------PNGT---PGPFDGPQWPYQA-----PQST-----
+----YVGVAVLMGTVVACASVVNGLVIVVSICYKKLRSPLNYILVNLAVADLLVTLCG-S
+SVSLSNN-IN-GFFV--FGRRMCELEGFMVSLTGIVGLWSLAILALERYVVVCKPLGD-F
+QFQRRHAVSGCAFTWGWALLW-SAPPLLG-W-----SSYVPEGLRTSCGPNWYTGGSNN-
+-NSYILSLFVTCFVLPLSLILFSYTNLLLTL----RAAAAQQKE----------------
+------------------------------------------------------------
+------------------------------------------------------------
+---------------------------------------------ADTTQRAEREVTRMV
+IVMVMAFLLCWLPYSTFALVVAT-HKG-I--IIQPVLASLPSYFSKTATVYNPIIYVFMN
+KQFQSCLL-EMLCCGYQPQR-------------------------------TGKAS--PG
+TPGPHA-D--VTAAGLRNKV----------------------------------------
+---------------------------------------------MP-AHPV
+>    14== M17718   1 D.melanogaster Rh3 <>[J.Neurosci.7,1550-1557'87]
+M---------------------------------ES-G----------------------
+------------------------------NVSS---------------SLFGNVSTALR
+PEARLSA---ETRLLGWNVPPEELR------------------HIP-----EHWLTYPEP
+PESMNYLLGTLYIFFTLMSMLGNGLVIWVFSAAKSLRTPSNILVINLAFCDFMMMVK--T
+PIFIYNS-FH-QGYA--LGHLGCQIFGIIGSYTGIAAGATNAFIAYDRFNVITRPMEG--
+KMTHGKAIAMIIFIYMYATPW-VVACYTETW-----GRFVPEGYLTSCTFDYLT--DNFD
+TRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVESL---------------------RS-NVDKNKETAEIRIAKAA
+ITICFLFFCSWTPYGVMSLIGAF-GDK-T--LLTPGATMIPACACKMVACIDPFVYAISH
+PRYRMELQ---------KRCP------------------WLALNEKAPE--SSAVA--ST
+STTQEP-Q-------------------------QT-------------------------
+---------------------------------------------TA-A---
+>    15== X65879   1 Drosophila pseudoobscura Dpse\Rh3 <>[Genetics132(1),193-204'92
+M---------------------------------EY-H----------------------
+------------------------------NVSS---------------VL-GNVSSVLR
+PDARLSA---ESRLLGWNVPPDELR------------------HIP-----EHWLIYPEP
+PESMNYLLGTLYIFFTVISMIGNGLVMWVFSAAKSLRTPSNILVINLAFCDFMMMIK--T
+PIFIYNS-FH-QGYA--LGHLGCQIFGVIGSYTGIAAGATNAFIAYDRYNVITRPMEG--
+KMTHGKAIAMIIFIYLYATPW-VVACYTESW-----GRFVPEGYLTSCTFDYLT--DNFD
+TRLFVACIFFFSFVCPTTMITYYYSQIVGHVFSHEKALRDQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVDSL---------------------RS-NVDKSKEAAEIRIAKAA
+ITICFLFFASWTPYGVMSLIGAF-GDK-T--LLTPGATMIPACTCKMVACIDPFVYAISH
+PRYRMELQ---------KRCP------------------WLAISEKAPE--SRAAI--ST
+STTQEQ-Q-------------------------QT-------------------------
+---------------------------------------------TA-A---
+>    16== M17730   1 D.melanogaster Rh4 opsin <>[J.Neurosci.7,1558-1566'87]
+M---------------------------------EPLC----------------------
+------------------------------NASE---------------PP-------LR
+PEAR-SSGNGDLQFLGWNVPPDQIQ------------------YIP-----EHWLTQLEP
+PASMHYMLGVFYIFLFCASTVGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--A
+PIF--NS-FH-RGFAIYLGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--
+NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFD
+TRLFVGTIFFFSFVCPTLMILYYYSQIVGHVFSHEKALREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVESL---------------------RS-NVDKSKETAEIRIAKAA
+ITICFLFFVSWTPYGVMSLIGAF-GDK-S--LLTQGATMIPACTCKLVACIDPFVYAISH
+PRYRLELQ---------KRCP------------------WLGVNEKSGE--ISSAQ--ST
+-TTQEQ-Q-------------------------QT-------------------------
+---------------------------------------------TA-A---
+>    17== X65880   1 Drosophila pseudoobscura Dpse\Rh4 <>[Genetics132(1),193-204'92
+M---------------------------------DALC----------------------
+------------------------------NASE---------------PP-------LR
+PEARMSSGSDELQFLGWNVPPDQIQ------------------YIP-----EHWLTQLEP
+PASMHYMLGVFYIFLFFASTLGNGMVIWIFSTSKSLRTPSNMFVLNLAVFDLIMCLK--A
+PIFIYNS-FH-RGFA--LGNTWCQIFASIGSYSGIGAGMTNAAIGYDRYNVITKPMNR--
+NMTFTKAVIMNIIIWLYCTPW-VVLPLTQFW-----DRFVPEGYLTSCSFDYLS--DNFD
+TRLFVGTIFLFSFVVPTLMILYYYSQIVGHVFNHEKALREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVESL---------------------RS-NVDKSKETAEIRIAKAA
+ITICFLFFVSWTPYGVMSLIGAF-GDK-S--LLTPGATMIPACTCKLVACIEPFVYAISH
+PRYRMELQ---------KRCP------------------WLGVNEKSGE--ASSAQ--ST
+-TTQEQTQ-------------------------QT-------------------------
+---------------------------------------------SA-A---
+>    18== D50584   1 Hemigrapsus sanguineus opsin BcRh2 <compound eye>[J.Exp.Biol.1
+M---------------------------------------------TNATGPQMAYYG--
+---AASMDFGYPE-----------------GVSI---------------VD---------
+-----------------FVRPEIKP------------------YVH-----QHWYNYPPV
+NPMWHYLLGVIYLFLGTVSIFGNGLVIYLFNKSAALRTPANILVVNLALSDLIMLTTN-V
+PFFTYNC-FSGGVWM--FSPQYCEIYACLGAITGVCSIWLLCMISFDRYNIICNGFNG-P
+KLTTGKAVVFALISWVIAIGC-ALPPFFG-W-----GNYILEGILDSCSYDYLT--QDFN
+TFSYNIFIFVFDYFLPAAIIVFSYVFIVKAIFAHEAAMRAQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVSTL---------------------RS-N-EADAQRAEIRIAKTA
+LVNVSLWFICWTPYALISLKGVM-GDT-S--GITPLVSTLPALLAKSCSCYNPFVYAISH
+PKYRLAIT---------QHLP------------------WFCVHETETKS-NDDSQ--SN
+STVAQ-------------------------------------------------------
+---------------------------------------------DK-A---
+>    19== D50583   1 Hemigrapsus sanguineus opsin BcRh1 <compound eye>[J.Exp.Biol.1
+M---------------------------------------------ANVTGPQMAFYG--
+---SGAATFGYPE-----------------GMTV---------------AD---------
+-----------------FVPDRVKH------------------MVL-----DHWYNYPPV
+NPMWHYLLGVVYLFLGVISIAGNGLVIYLYMKSQALKTPANMLIVNLALSDLIMLTTN-F
+PPFCYNC-FSGGRWM--FSGTYCEIYAALGAITGVCSIWTLCMISFDRYNIICNGFNG-P
+KLTQGKATFMCGLAWVISVGW-SLPPFFG-W-----GSYTLEGILDSCSYDYFT--RDMN
+TITYNICIFIFDFFLPASVIVFSYVFIVKAIFAHEAAMRAQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVTNL---------------------RS-N-EAETQRAEIRIAKTA
+LVNVSLWFICWTPYAAITIQGLL-GNA-E--GITPLLTTLPALLAKSCSCYNPFVYAISH
+PKFRLAIT---------QHLP------------------WFCVHEKDPND-VEENQ--SS
+NTQTQ-------------------------------------------------------
+---------------------------------------------EK-S---
+>    20== K02320   1 D.melanogaster opsin <>[Cell40,851-858'85]
+M---------------------------------E------SFAVAAAQLGPHFAPLS--
+------------------------------NGSV---------------VD---------
+-----------------KVTPDMAH------------------LIS-----PYWNQFPAM
+DPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-T
+PMMGINL-YF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-R
+PMTIPLALGKM---------------------------YVPEGNLTSCGIDYLE--RDWN
+PRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVKSL---------------------RS-S-EDAEKSAEGKLAKVA
+LVTITLWFMAWTPYLVINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISH
+PKYRLALK---------EKCP------------------CCVFGKVDDGK-SSDAQ--SQ
+ATASEA-E----------------------------------------------------
+---------------------------------------------SK-A---
+>    21== K02315   1 D.melanogaster ninaE <>[Cell40,839-850'85]
+M---------------------------------E------SFAVAAAQLGPHFAPLS--
+------------------------------NGSV---------------VD---------
+-----------------KVTPDMAH------------------LIS-----PYWNQFPAM
+DPIWAKILTAYMIMIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-T
+PMMGINL-YF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-R
+PMTIPLALGKIAYIWFMSSIW-CLAPAFG-W-----SRYVPEGNLTSCGIDYLE--RDWN
+PRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVKSL---------------------RS-S-EDAEKSAEGKLAKVA
+LVTITLWFMAWTPYLVINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISH
+PKYRLALK---------EKCP------------------CCVFGKVDDGK-SSDAQ--SQ
+ATASEA-E----------------------------------------------------
+---------------------------------------------SK-A---
+>    22== X65877   1 Drosophila pseudoobscura Dpse\ninaE <>[Genetics132(1),193-204'
+M---------------------------------D------SFAAVATQLGPQFAAPS--
+------------------------------NGSV---------------VD---------
+-----------------KVTPDMAH------------------LIS-----PYWDQFPAM
+DPIWAKILTAYMIIIGMISWCGNGVVIYIFATTKSLRTPANLLVINLAISDFGIMITN-T
+PMMGINL-YF-ETWV--LGPMMCDIYAGLGSAFGCSSIWSMCMISLDRYQVIVKGMAG-R
+PMTIPLALGKIAYIWFMSTIWCCLAPVFG-W-----SRYVPEGNLTSCGIDYLE--RDWN
+PRSYLIFYSIFVYYIPLFLICYSYWFIIAAVSAHEKAMREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVKSL---------------------RS-S-EDADKSAEGKLAKVA
+LVTISLWFMAWTPYLVINCMGLF--KF-E--GLTPLNTIWGACFAKSAACYNPIVYGISH
+PKYRLALK---------EKCP------------------CCVFGKVDDGK-SSEAQ--SQ
+ATTSEA-E----------------------------------------------------
+---------------------------------------------SK-A---
+>    23== M12896   1 D.melanogaster Rh2 <>[Cell44,705-710'86]
+M---------------------------------ER-SHLPETPFDLAHSGPRFQAQS--
+---SG-------------------------NGSV---------------LD---------
+-----------------NVLPDMAH------------------LVN-----PYWSRFAPM
+DPMMSKILGLFTLAIMIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-S
+PVMIINF-YY-ETWV--LGPLWCDIYAGCGSLFGCVSIWSMCMIAFDRYNVIVKGING-T
+PMTIKTSIMKILFIWMMAVFW-TVMPLIG-W-----SAYVPEGNLTACSIDYMT--RMWN
+PRSYLITYSLFVYYTPLFLICYSYWFIIAAVAAHEKAMREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVKSL---------------------RS-S-EDCDKSAEGKLAKVA
+LTTISLWFMAWTPYLVICYFGLF--KI-D--GLTPLTTIWGATFAKTSAVYNPIVYGISH
+PKYRIVLK---------EKCP------------------MCVFGNTDEPKPDAPAS--DT
+ETTSEA-D----------------------------------------------------
+---------------------------------------------SK-A---
+>    24== X65878   1 Drosophila pseudoobscura Dpse\Rh2 <>[Genetics132(1),193-204'92
+M---------------------------------ER-SLLPEPPLAMALLGPRFEAQT--
+---GG-------------------------NRSV---------------LD---------
+-----------------NVLPDMAP------------------LVN-----PHWSRFAPM
+DPTMSKILGLFTLVILIISCCGNGVVVYIFGGTKSLRTPANLLVLNLAFSDFCMMASQ-S
+PVMIINF-YY-ETWV--LGPLWCDIYAACGSLFGCVSIWSMCMIAFDRYNVIVKGING-T
+PMTIKTSIMKIAFIWMMAVFW-TIMPLIG-W-----SSYVPEGNLTACSIDYMT--RQWN
+PRSYLITYSLFVYYTPLFMICYSYWFIIATVAAHEKAMRDQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVKSL---------------------RS-S-EDCDKSAENKLAKVA
+LTTISLWFMAWTPYLIICYFGLF--KI-D--GLTPLTTIWGATFAKTSAVYNPIVYGISH
+PNDRLVLK---------EKCP------------------MCVCGTTDEPKPDAPPS--DT
+ETTSEA-E----------------------------------------------------
+---------------------------------------------SK-D---
+>    25== U26026   1 Apis mellifera long-wavelength rhodopsin <>[]
+M---------------------------------------------IAVSGPSYEAFS--
+---YG----GQAR---------------FNNQTV---------------VD---------
+-----------------KVPPDMLH------------------LID-----ANWYQYPPL
+NPMWHGILGFVIGMLGFVSAMGNGMVVYIFLSTKSLRTPSNLFVINLAISNFLMMFCM-S
+PPMVINC-YY-ETWV--LGPLFCQIYAMLGSLFGCGSIWTMTMIAFDRYNVIVKGLSG-K
+PLSINGALIRIIAIWLFSLGW-TIAPMFG-W-----NRYVPEGNMTACGTDYFN--RGLL
+SASYLVCYGIWVYFVPLFLIIYSYWFIIQAVAAHEKNMREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVASL---------------------RS-S-ENQNTSAECKLAKVA
+LMTISLWFMAWTPYLVINFSGIF--NL-V--KISPLFTIWGSLFAKANAVYNPIVYGISH
+PKYRAALF---------AKFP------------------SLAC-AAEPSS-DAVST--TS
+GTTTVT-D----------------------------------------------------
+-----------------------------------------NEK-SN-A---
+>    26== L03781   1 Limulus polyphemus opsin <>[PNAS90,6150-6154'93]
+M-----------------------------------------------ANQLSYSSLG--
+---WP----YQP------------------NASV---------------VD---------
+-----------------TMPKEMLY------------------MIH-----EHWYAFPPM
+NPLWYSILGVAMIILGIICVLGNGMVIYLMMTTKSLRTPTNLLVVNLAFSDFCMMAFM-M
+PTMTSNC-FA-ETWI--LGPFMCEVYGMAGSLFGCASIWSMVMITLDRYNVIVRGMAA-A
+PLTHKKATLLLLFVWIWSGGW-TILPFFG-W-----SRYVPEGNLTSCTVDYLT--KDWS
+SASYVVIYGLAVYFLPLITMIYCYFFIVHAVAEHEKQLREQAKK----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------MNVASL---------------------RANA-DQQKQSAECRLAKVA
+MMTVGLWFMAWTPYLIISWAGVF--SSGT--RLTPLATIWGSVFAKANSCYNPIVYGISH
+PRYKAALY---------QRFP------------------SLACGSGESGS-DVKSE--AS
+ATTTME-E----------------------------------------------------
+-----------------------------------------KPKIPE-A---
+>    27== X07797   1 Octopus dofleini rhodopsin <>[FEBS232(1),69-72'88]
+M-----------------------------------------------------------
+---------VESTTLVNQTW-------WY-NPTV---------------D----------
+--------------------------------------------IH-----PHWAKFDPI
+PDAVYYSVGIFIGVVGIIGILGNGVVIYLFSKTKSLQTPANMFIINLAMSDLSFSAINGF
+PLKTISA-FM-KKWI--FGKVACQLYGLLGGIFGFMSINTMAMISIDRYNVIGRPMAASK
+KMSHRRAFLMIIFVWMWSIVW-SVGPVFN-W-----GAYVPEGILTSCSFDYLS--TDPS
+TRSFILCMYFCGFMLPIIIIAFCYFNIVMSVSNHEKEMAAMAKR----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------LNAKEL---------------------RK---AQAGASAEMKLAKIS
+MVIITQFMLSWSPYAIIALLAQF-GPA-E--WVTPYAAELPVLFAKASAIHNPIVYSVSH
+PKFREAIQ---------TTFPWL--------------LTCCQFDEKECED-ANDAE--EE
+VVASER---GGESRD-AAQMKEMMAMMQKMQAQQAAYQPPPPPQGY--PPQGYPPQGAYP
+PPQGYPPQGYPPQGYPPQGYPPQGAPPQVEAPQGAPPQGVDNQA-YQ-A---
+>    28== X70498   1 Todarodes pacificus rhodopsin <retina>[FEBS317(1-2),5-11'93]
+M-----------------------------------------------------------
+---------GRDLR-DNETW-------WY-NPSI---------------V----------
+--------------------------------------------VH-----PHWREFDQV
+PDAVYYSLGIFIGICGIIGCGGNGIVIYLFTKTKSLQTPANMFIINLAFSDFTFSLVNGF
+PLMTISC-FL-KKWI--FGFAACKVYGFIGGIFGFMSIMTMAMISIDRYNVIGRPMAASK
+KMSHRRAFIMIIFVWLWSVLW-AIGPIFG-W-----GAYTLEGVLCNCSFDYIS--RDST
+TRSNILCMFILGFFGPILIIFFCYFNIVMSVSNHEKEMAAMAKR----------------
+------------------------------------------------------------
+------------------------------------------------------------
+-------------LNAKEL---------------------RK---AQAGANAEMRLAKIS
+IVIVSQFLLSWSPYAVVALLAQF-GPL-E--WVTPYAAQLPVMFAKASAIHNPMIYSVSH
+PKFREAIS---------QTFPWV--------------LTCCQFDDKETED-DKDAE--TE
+IPAGES-SDAAPSAD-AAQMKEMMAMMQKMQQQQAAY----PPQGYAPPPQGYPPQGY--
+PPQGYPPQGYPPQGYPP---PPQGAPPQ-GAPPAAPPQGVDNQA-YQ-A---
+>    29== L21195   1 human serotonin 5-HT7 receptor protein <placenta and fetal bra
+MMDVNSSGRPDL----YGHLRSFL--LPE-----------------VGRGLPDLSPDGGA
+DPVAG-------------SWAPHLLS----EVTA--SPAPTW------------------
+-----------------DAPPDNAS-GCGE-------------QIN-------------Y
+GRVEKVVIGSILTLITLLTIAGNCLVVISVCFVKKLRQPSNYLIVSLALADLSVAVAV-M
+PFVSVTDLIG-GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPV
+RQNGKCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF--------
+--GYTIYSTAVAFYIPMSVMLFMYYQIY-------KAARKSAAKHKF-------------
+----PGF---------------------------------PRVEPDS-------------
+--------VIALNGIVKLQKEV--------------------------------------
+--------EE--CANLSRLLKH------------------ER-K-NISIFKREQKAATTL
+GIIVGAFTVCWLPFFLLSTARPFICGT-SCSCIPLWVERTFLWLGYANSLINPFIYAFFN
+RDLRTTYR-SLL----------QC---QYRNINRKLSA-------------AGMHE--AL
+KLAERP-E--------RPEF-----VL------QN-------------------------
+------ADYCRKKGHD--------------------------------S---
+>    30== L15228   1 rat 5HT-7 serotonin receptor <>[JBC268,18200-18204'93]
+M-----------------------------------------------------------
+---------------------PHLLSGFL-EVTA--SPAPTW------------------
+-----------------DAPPDNVS-GCGE-------------QIN-------------Y
+GRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-M
+PFVSVTDLIG-GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPV
+RQNGKCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF--------
+--GYTIYSTAVAFYIPMSVMLFMYYQIY-------KAARKSAAKHKF-------------
+----PGF---------------------------------PRVQPES-------------
+--------VISLNGVVKLQKEV--------------------------------------
+--------EE--CANLSRLLKH------------------ER-K-NISIFKREQKAATTL
+GIIVGAFTVCWLPFFLLSTARPFICGT-SCSCIPLWVERTCLWLGYANSLINPFIYAFFN
+RDLRPTSR-SLL----------QC---QYRNINRKLSA-------------AGMHE--AL
+KLAERP-E--------RSEF-----VL------QN-------------------------
+------SDHCGKKGHD--------------------------------T---
+>    31=p A47425 serotonin receptor 5HT-7 - rat
+M-----------------------------------------------------------
+---------------------PHLLSGFL-EVTA--SPAPTW------------------
+-----------------DAPPDNVS-GCGE-------------QIN-------------Y
+GRVEKVVIGSILTLITLLTIAGNCLVVISVSFVKKLRQPSNYLIVSLALADLSVAVAV-M
+PFVSVTDLIG-GKWI--FGHFFCNVFIAMDVMCCTASIMTLCVISIDRYLGITRPLTYPV
+RQNGKCMAKMILSVWLLSASI-TLPPLFG-W-----AQNVNDDKVCLISQDF--------
+--GYTIYSTAVAFYIPMSVMLFMYYQIY-------KAARKSAAKHKF-------------
+----PGF---------------------------------PRVQPES-------------
+--------VISLNGVVKLQKEV--------------------------------------
+--------EE--CANLSRLLKH------------------ER-K-NISIFKREQKAATTL
+GIIVGAFTVCWLPFFLLSTARPFICGT-SCSCIPLWVERTCLWLGYANSLINPFIYAFFN
+RDLRTTYR-SLL----------QC---QYRNINRKLSA-------------AGMHE--AL
+KLAERP-E--------RSEF-----VL------QN-------------------------
+------SDHCGKKGHD--------------------------------T---
+>    32== M83181   1 human serotonin receptor <>[JBC267(11),7553-7562'92]
+M-DVLSPGQ-----------------GNN-----------------TTSPPAPFETGG--
+------------------------------NTTG--ISDVTV------------------
+------------------------------------------------------------
+--SYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-L
+PMAALYQ-VL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVN
+KRTPRRAAALISLTWLIGFLI-SIPPMLG-WRTP---EDRSDPDACTISKDH--------
+--GYTIYSTFGAFYIPLLLMLVLYGRIF-------RAARFRIRK----------------
+-----------------------TVKKVEKTGADTRHGASPAPQPKKSVNGESGSRNWRL
+GVESKAGGALCANGAVRQGDDG----AALEVIEVHRVGNSKEHLPLPSEAGPTPCAPASF
+ERKN----ERN--------------------A--------EA-K-RKMALARERKTVKTL
+GIIMGTFILCWLPFFIVALVLPF-CES-SC-HMPTLLGAIINWLGYSNSLLNPVIYAYFN
+KDFQNAFK-KII---------------KCKFCRQ--------------------------
+------------------------------------------------------------
+----------------------------------------------------
+>    33=p A35181 serotonin receptor class 1A - rat
+M-DVFSFGQ-----------------GNN-----------------TTASQEPFGTGG--
+------------------------------NVTS--ISDVTF------------------
+------------------------------------------------------------
+--SYQVITSLLLGTLIFCAVLGNACVVAAIALERSLQNVANYLIGSLAVTDLMVSVLV-L
+PMAALYQ-VL-NKWT--LGQVTCDLFIALDVLCCTSSILHLCAIALDRYWAITDPIDYVN
+KRTPRRAAALISLTWLIGFLI-SIPPMLG-WRTP---EDRSDPDACTISKDH--------
+--GYTIYSTFGAFYIPLLLMLVLYGRIF-------RAARFRIRK----------------
+-----------------------TVRKVEKKGAGTSLGTSSAPPPKKSLNGQPGSGDWRR
+CAENRAVGTPCTNGAVRQGDDE----ATLEVIEVHRVGNSKEHLPLPSESGSNSYAPACL
+ERKN----ERN--------------------A--------EA-K-RKMALARERKTVKTL
+GIIMGTFILCWLPFFIVALVLPF-CES-SC-HMPALLGAIINWLGYSNSLLNPVIYAYFN
+KDFQNAFK-KII---------------KCKFCRR--------------------------
+------------------------------------------------------------
+----------------------------------------------------
+>    34== L06803   1 Lymnaea stagnalis serotonin receptor <>[PNAS90,11-15'93]
+M-ANFTFGDLALDVARMGGLASTPSGLRS-----------------TGLTTPGLSPTG--
+------------------------------LVTS--DFNDSYGLTGQF-IN-GSHS----
+-----------------SRSRDNAS-ANDT-------------SATNMTDDRYWS-LTVY
+SHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-M
+PLSVVSE-IS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIR
+RRSARRILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK--------
+--GYTIFSTVGAFYLPMLVMMIIYIRIW-------LVARSRIRKDKFQMTKARLKTEETT
+LVASPKTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKK-------------
+---NRAKKLPENANGVNSNSSS------------------SERLKQIQIETAEAFANGCA
+EEASIAMLERQ-CNNGKKISSNDTPYS-------------RT-R-EKLELKRERKAARTL
+AIITGAFLICWLPFFIIALIGPF-VDP-E--GIPPFARSFVLWLGYFNSLLNPIIYTIFS
+PEFRSAFQ-KIL----------FG---KYRRGHR--------------------------
+------------------------------------------------------------
+----------------------------------------------------
+>    35=p A47174 serotonin receptor, 5HTlym receptor - great pond snail
+M-ANFTFGDLALDVARMGGLASTPSGLRS-----------------TGLTTPGLSPTG--
+------------------------------LVTS--DFNDSYGLTGQF-IN-GSHS----
+-----------------SRSRDNAS-ANDT-------------SATNMTDDRYWS-LTVY
+SHEHLVLTSVILGLFVLCCIIGNCFVIAAVMLERSLHNVANYLILSLAVADLMVAVLV-M
+PLSVVSE-IS-KVWF--LHSEVCDMWISVDVLCCTASILHLVAIAMDRYWAVTS-IDYIR
+RRSARRILLMIMVVWIVALFI-SIPPLFG-WRDP--NNDPDKTGTCIISQDK--------
+--GYTIFSTVGAFYLPMLVMMIIYIRIW-------LVARSRIRKDKFQMTKARLKTEETT
+LVASPKTEYSVVSDCNGCNSPDSTTEKKKRRAPFKSYGCSPRPERKK-------------
+---NRAKKLPENANGVNSNSSS------------------SERLKQIQIETAEAFANGCA
+EEASIAMLERQ-CNNGKKISSNDTPYS-------------RT-R-EKLELKRERKAARTL
+AIITGAFLICWLPFFIIALIGPF-VDP-E--GIPPFARSFVLWLGYFNSLLNPIIYTIFS
+PEFRSAFQ-KIL----------FG---KYRRGHR--------------------------
+------------------------------------------------------------
+----------------------------------------------------
+>    36== X95604   1 Bombyx mori serotonin receptor <antennae>[InsectBiochem.Mol.Bi
+M-EGAE-GQEELDWEAL--YLRLP--LQN-----------------CSWNSTGWEPNW--
+------------------------------NVTV--VPNTTW-----------WQA----
+-----------------SAPFDTPA-ALVR-------------AAAK-------------
+--------AVVLGLLILATVVGNVFVIAAILLERHLRSAANNLILSLAVADLLVACLV-M
+PLGAVYE-VV-QRWT--LGPELCDMWTSGDVLCCTASILHLVAIALDRYWAVTN-IDYIH
+ASTAKRVGMMIACVWTVSFFV-CIAQLLG-WKDPDWNQRVSEDLRCVVSQDV--------
+--GYQIFATASSFYVPVLIILILYWRIY-------QTARKRIR-----------------
+----------------------------RRRGATARGGVGPPP-----------------
+--------VPAGGALVAGGGSGGIAAAVVAVI--------GRPLPTISETTTTGFTNVSS
+NNTS---PEKQSCANGLEADPPTTGYGAVAAAYYPSLVRRKP-K-EAADSKRERKAAKTL
+AIITGAFVACWLPFFVLAILVPT-CDC-E---VSPVLTSLSLWLGYFNSTLNPVIYTVFS
+PEFRHAFQ-RLL----------CGRRVRRRRAPQ--------------------------
+------------------------------------------------------------
+----------------------------------------------------
diff --git a/binaries/src/mafft/test/samplerna b/binaries/src/mafft/test/samplerna
new file mode 100644 (file)
index 0000000..926ff03
--- /dev/null
@@ -0,0 +1,36 @@
+>AJ006331.1_1230 
+ccauggcguuaguau
+gagugucgugcagccuccaggccccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaaucgcuggggugaccggguccuuucuuggaacaacccgc
+ucaauacccagaaauuugggcgugcccccgcgagaucacuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagu
+
+>Z84287.1_1250 
+uucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucgaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgagagu
+
+>AF064490.1_2296 
+ugagu
+gucgaacagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccgggaugaccggguccuuucuuggauaaacccgc
+ucaaugcccggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaacaugagcacgaauccuaaaccucaaagaaaaaccaaaagaaacaccaaccg
+>Z84230.1_1250 
+uucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggauaagcccgc
+ucaaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgagagu
+
+>AB049100.1_1360 
+auagaucacuccccugugaggaacuacugucuucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucaaugccuggagauuugggcgugcccccgcgagaccgcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaccaugagcacgaauccuaaaccucaaagaaaaaccaaacguaacaccaaccg
+
diff --git a/binaries/src/mafft/test/samplerna.qinsi b/binaries/src/mafft/test/samplerna.qinsi
new file mode 100644 (file)
index 0000000..0d9d4c2
--- /dev/null
@@ -0,0 +1,35 @@
+>AJ006331.1_1230 
+---------------------------------------------------ccauggcgu
+uaguaugagugucgugcagccuccaggccccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaaucgcuggggugaccggguccuuucuuggaacaacccgc
+ucaauacccagaaauuugggcgugcccccgcgagaucacuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagu-------------------
+------------------------------------------------------------
+>Z84287.1_1250 
+-------------------------------uucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucgaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgagagu-------------------
+------------------------------------------------------------
+>AF064490.1_2296 
+------------------------------------------------------------
+-----ugagugucgaacagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccgggaugaccggguccuuucuuggauaaacccgc
+ucaaugcccggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaacaugagcacgaauccuaaaccucaaagaaaaaccaaaagaaacaccaaccg
+>Z84230.1_1250 
+-------------------------------uucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggauaagcccgc
+ucaaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgagagu-------------------
+------------------------------------------------------------
+>AB049100.1_1360 
+auagaucacuccccugugaggaacuacugucuucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucaaugccuggagauuugggcgugcccccgcgagaccgcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaccaugagcacgaauccuaaaccucaaagaaaaaccaaacguaacaccaaccg
diff --git a/binaries/src/mafft/test/samplerna.xinsi b/binaries/src/mafft/test/samplerna.xinsi
new file mode 100644 (file)
index 0000000..f90b173
--- /dev/null
@@ -0,0 +1,35 @@
+>AJ006331.1_1230 
+c---------------------------------------------------cauggcgu
+uaguaugagugucgugcagccuccaggccccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaaucgcuggggugaccggguccuuucuuggaacaacccgc
+ucaauacccagaaauuugggcgugcccccgcgagaucacuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcga---------------------
+----------------------------------------------------------gu
+>Z84287.1_1250 
+u-------------------------------ucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucgaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgaga---------------------
+----------------------------------------------------------gu
+>AF064490.1_2296 
+u-----------------------------------------------------------
+------gagugucgaacagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccgggaugaccggguccuuucuuggauaaacccgc
+ucaaugcccggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaacaugagcacgaauccuaaaccucaaagaaaaaccaaaagaaacaccaaccg
+>Z84230.1_1250 
+u-------------------------------ucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggauaagcccgc
+ucaaugccuggagauuugggcgugcccccgcgagacugcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcucgaga---------------------
+----------------------------------------------------------gu
+>AB049100.1_1360 
+auagaucacuccccugugaggaacuacugucuucacgcagaaagcgucuagccauggcgu
+uaguaugagugucgugcagccuccaggacccccccucccgggagagccauaguggucugc
+ggaaccggugaguacaccggaauugccaggacgaccggguccuuucuuggaucaacccgc
+ucaaugccuggagauuugggcgugcccccgcgagaccgcuagccgaguaguguugggucg
+cgaaaggccuugugguacugccugauagggugcuugcgagugccccgggaggucucguag
+accgugcaccaugagcacgaauccuaaaccucaaagaaaaaccaaacguaacaccaaccg